uaccess.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_UACCESS_H
  3. #define __ASM_SH_UACCESS_H
  4. #include <asm/extable.h>
  5. #include <asm-generic/access_ok.h>
  6. /*
  7. * Uh, these should become the main single-value transfer routines ...
  8. * They automatically use the right size if we just have the right
  9. * pointer type ...
  10. *
  11. * As SuperH uses the same address space for kernel and user data, we
  12. * can just do these as direct assignments.
  13. *
  14. * Careful to not
  15. * (a) re-use the arguments for side effects (sizeof is ok)
  16. * (b) require any knowledge of processes at this stage
  17. */
  18. #define put_user(x,ptr) __put_user_check((x), (ptr), sizeof(*(ptr)))
  19. #define get_user(x,ptr) __get_user_check((x), (ptr), sizeof(*(ptr)))
  20. /*
  21. * The "__xxx" versions do not do address space checking, useful when
  22. * doing multiple accesses to the same area (the user has to do the
  23. * checks by hand with "access_ok()")
  24. */
  25. #define __put_user(x,ptr) __put_user_nocheck((x), (ptr), sizeof(*(ptr)))
  26. #define __get_user(x,ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
  27. struct __large_struct { unsigned long buf[100]; };
  28. #define __m(x) (*(struct __large_struct __user *)(x))
  29. #define __get_user_nocheck(x,ptr,size) \
  30. ({ \
  31. long __gu_err; \
  32. unsigned long __gu_val; \
  33. const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
  34. __chk_user_ptr(ptr); \
  35. __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
  36. (x) = (__force __typeof__(*(ptr)))__gu_val; \
  37. __gu_err; \
  38. })
  39. #define __get_user_check(x,ptr,size) \
  40. ({ \
  41. long __gu_err = -EFAULT; \
  42. unsigned long __gu_val = 0; \
  43. const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
  44. if (likely(access_ok(__gu_addr, (size)))) \
  45. __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
  46. (x) = (__force __typeof__(*(ptr)))__gu_val; \
  47. __gu_err; \
  48. })
  49. #define __put_user_nocheck(x,ptr,size) \
  50. ({ \
  51. long __pu_err; \
  52. __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
  53. __typeof__(*(ptr)) __pu_val = x; \
  54. __chk_user_ptr(ptr); \
  55. __put_user_size(__pu_val, __pu_addr, (size), __pu_err); \
  56. __pu_err; \
  57. })
  58. #define __put_user_check(x,ptr,size) \
  59. ({ \
  60. long __pu_err = -EFAULT; \
  61. __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
  62. __typeof__(*(ptr)) __pu_val = x; \
  63. if (likely(access_ok(__pu_addr, size))) \
  64. __put_user_size(__pu_val, __pu_addr, (size), \
  65. __pu_err); \
  66. __pu_err; \
  67. })
  68. # include <asm/uaccess_32.h>
  69. extern long strncpy_from_user(char *dest, const char __user *src, long count);
  70. extern __must_check long strnlen_user(const char __user *str, long n);
  71. /* Generic arbitrary sized copy. */
  72. /* Return the number of bytes NOT copied */
  73. __kernel_size_t __copy_user(void *to, const void *from, __kernel_size_t n);
  74. static __always_inline unsigned long
  75. raw_copy_from_user(void *to, const void __user *from, unsigned long n)
  76. {
  77. return __copy_user(to, (__force void *)from, n);
  78. }
  79. static __always_inline unsigned long __must_check
  80. raw_copy_to_user(void __user *to, const void *from, unsigned long n)
  81. {
  82. return __copy_user((__force void *)to, from, n);
  83. }
  84. #define INLINE_COPY_FROM_USER
  85. #define INLINE_COPY_TO_USER
  86. /*
  87. * Clear the area and return remaining number of bytes
  88. * (on failure. Usually it's 0.)
  89. */
  90. __kernel_size_t __clear_user(void __user *addr, __kernel_size_t size);
  91. #define clear_user(addr,n) \
  92. ({ \
  93. void __user * __cl_addr = (addr); \
  94. unsigned long __cl_size = (n); \
  95. \
  96. if (__cl_size && access_ok(__cl_addr, __cl_size)) \
  97. __cl_size = __clear_user(__cl_addr, __cl_size); \
  98. \
  99. __cl_size; \
  100. })
  101. extern void *set_exception_table_vec(unsigned int vec, void *handler);
  102. static inline void *set_exception_table_evt(unsigned int evt, void *handler)
  103. {
  104. return set_exception_table_vec(evt >> 5, handler);
  105. }
  106. struct mem_access {
  107. unsigned long (*from)(void *dst, const void __user *src, unsigned long cnt);
  108. unsigned long (*to)(void __user *dst, const void *src, unsigned long cnt);
  109. };
  110. int handle_unaligned_access(insn_size_t instruction, struct pt_regs *regs,
  111. struct mem_access *ma, int, unsigned long address);
  112. #endif /* __ASM_SH_UACCESS_H */