uaccess_no.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __M68KNOMMU_UACCESS_H
  3. #define __M68KNOMMU_UACCESS_H
  4. /*
  5. * User space memory access functions
  6. */
  7. #include <linux/mm.h>
  8. #include <linux/string.h>
  9. #include <asm/segment.h>
  10. #define access_ok(type,addr,size) _access_ok((unsigned long)(addr),(size))
  11. /*
  12. * It is not enough to just have access_ok check for a real RAM address.
  13. * This would disallow the case of code/ro-data running XIP in flash/rom.
  14. * Ideally we would check the possible flash ranges too, but that is
  15. * currently not so easy.
  16. */
  17. static inline int _access_ok(unsigned long addr, unsigned long size)
  18. {
  19. return 1;
  20. }
  21. /*
  22. * These are the main single-value transfer routines. They automatically
  23. * use the right size if we just have the right pointer type.
  24. */
  25. #define put_user(x, ptr) \
  26. ({ \
  27. int __pu_err = 0; \
  28. typeof(*(ptr)) __pu_val = (x); \
  29. switch (sizeof (*(ptr))) { \
  30. case 1: \
  31. __put_user_asm(__pu_err, __pu_val, ptr, b); \
  32. break; \
  33. case 2: \
  34. __put_user_asm(__pu_err, __pu_val, ptr, w); \
  35. break; \
  36. case 4: \
  37. __put_user_asm(__pu_err, __pu_val, ptr, l); \
  38. break; \
  39. case 8: \
  40. memcpy(ptr, &__pu_val, sizeof (*(ptr))); \
  41. break; \
  42. default: \
  43. __pu_err = __put_user_bad(); \
  44. break; \
  45. } \
  46. __pu_err; \
  47. })
  48. #define __put_user(x, ptr) put_user(x, ptr)
  49. extern int __put_user_bad(void);
  50. /*
  51. * Tell gcc we read from memory instead of writing: this is because
  52. * we do not write to any memory gcc knows about, so there are no
  53. * aliasing issues.
  54. */
  55. #define __ptr(x) ((unsigned long *)(x))
  56. #define __put_user_asm(err,x,ptr,bwl) \
  57. __asm__ ("move" #bwl " %0,%1" \
  58. : /* no outputs */ \
  59. :"d" (x),"m" (*__ptr(ptr)) : "memory")
  60. #define get_user(x, ptr) \
  61. ({ \
  62. int __gu_err = 0; \
  63. typeof(x) __gu_val = 0; \
  64. switch (sizeof(*(ptr))) { \
  65. case 1: \
  66. __get_user_asm(__gu_err, __gu_val, ptr, b, "=d"); \
  67. break; \
  68. case 2: \
  69. __get_user_asm(__gu_err, __gu_val, ptr, w, "=r"); \
  70. break; \
  71. case 4: \
  72. __get_user_asm(__gu_err, __gu_val, ptr, l, "=r"); \
  73. break; \
  74. case 8: \
  75. memcpy((void *) &__gu_val, ptr, sizeof (*(ptr))); \
  76. break; \
  77. default: \
  78. __gu_val = 0; \
  79. __gu_err = __get_user_bad(); \
  80. break; \
  81. } \
  82. (x) = (typeof(*(ptr))) __gu_val; \
  83. __gu_err; \
  84. })
  85. #define __get_user(x, ptr) get_user(x, ptr)
  86. extern int __get_user_bad(void);
  87. #define __get_user_asm(err,x,ptr,bwl,reg) \
  88. __asm__ ("move" #bwl " %1,%0" \
  89. : "=d" (x) \
  90. : "m" (*__ptr(ptr)))
  91. static inline unsigned long
  92. raw_copy_from_user(void *to, const void __user *from, unsigned long n)
  93. {
  94. memcpy(to, (__force const void *)from, n);
  95. return 0;
  96. }
  97. static inline unsigned long
  98. raw_copy_to_user(void __user *to, const void *from, unsigned long n)
  99. {
  100. memcpy((__force void *)to, from, n);
  101. return 0;
  102. }
  103. #define INLINE_COPY_FROM_USER
  104. #define INLINE_COPY_TO_USER
  105. /*
  106. * Copy a null terminated string from userspace.
  107. */
  108. static inline long
  109. strncpy_from_user(char *dst, const char *src, long count)
  110. {
  111. char *tmp;
  112. strncpy(dst, src, count);
  113. for (tmp = dst; *tmp && count > 0; tmp++, count--)
  114. ;
  115. return(tmp - dst); /* DAVIDM should we count a NUL ? check getname */
  116. }
  117. /*
  118. * Return the size of a string (including the ending 0)
  119. *
  120. * Return 0 on exception, a value greater than N if too long
  121. */
  122. static inline long strnlen_user(const char *src, long n)
  123. {
  124. return(strlen(src) + 1); /* DAVIDM make safer */
  125. }
  126. /*
  127. * Zero Userspace
  128. */
  129. static inline unsigned long
  130. __clear_user(void *to, unsigned long n)
  131. {
  132. memset(to, 0, n);
  133. return 0;
  134. }
  135. #define clear_user(to,n) __clear_user(to,n)
  136. #endif /* _M68KNOMMU_UACCESS_H */