uaccess_no.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #ifndef __M68KNOMMU_UACCESS_H
  2. #define __M68KNOMMU_UACCESS_H
  3. /*
  4. * User space memory access functions
  5. */
  6. #include <linux/sched.h>
  7. #include <linux/mm.h>
  8. #include <linux/string.h>
  9. #include <asm/segment.h>
  10. #define VERIFY_READ 0
  11. #define VERIFY_WRITE 1
  12. #define access_ok(type,addr,size) _access_ok((unsigned long)(addr),(size))
  13. /*
  14. * It is not enough to just have access_ok check for a real RAM address.
  15. * This would disallow the case of code/ro-data running XIP in flash/rom.
  16. * Ideally we would check the possible flash ranges too, but that is
  17. * currently not so easy.
  18. */
  19. static inline int _access_ok(unsigned long addr, unsigned long size)
  20. {
  21. return 1;
  22. }
  23. /*
  24. * The exception table consists of pairs of addresses: the first is the
  25. * address of an instruction that is allowed to fault, and the second is
  26. * the address at which the program should continue. No registers are
  27. * modified, so it is entirely up to the continuation code to figure out
  28. * what to do.
  29. *
  30. * All the routines below use bits of fixup code that are out of line
  31. * with the main instruction path. This means when everything is well,
  32. * we don't even have to jump over them. Further, they do not intrude
  33. * on our cache or tlb entries.
  34. */
  35. struct exception_table_entry
  36. {
  37. unsigned long insn, fixup;
  38. };
  39. /* Returns 0 if exception not found and fixup otherwise. */
  40. extern unsigned long search_exception_table(unsigned long);
  41. /*
  42. * These are the main single-value transfer routines. They automatically
  43. * use the right size if we just have the right pointer type.
  44. */
  45. #define put_user(x, ptr) \
  46. ({ \
  47. int __pu_err = 0; \
  48. typeof(*(ptr)) __pu_val = (x); \
  49. switch (sizeof (*(ptr))) { \
  50. case 1: \
  51. __put_user_asm(__pu_err, __pu_val, ptr, b); \
  52. break; \
  53. case 2: \
  54. __put_user_asm(__pu_err, __pu_val, ptr, w); \
  55. break; \
  56. case 4: \
  57. __put_user_asm(__pu_err, __pu_val, ptr, l); \
  58. break; \
  59. case 8: \
  60. memcpy(ptr, &__pu_val, sizeof (*(ptr))); \
  61. break; \
  62. default: \
  63. __pu_err = __put_user_bad(); \
  64. break; \
  65. } \
  66. __pu_err; \
  67. })
  68. #define __put_user(x, ptr) put_user(x, ptr)
  69. extern int __put_user_bad(void);
  70. /*
  71. * Tell gcc we read from memory instead of writing: this is because
  72. * we do not write to any memory gcc knows about, so there are no
  73. * aliasing issues.
  74. */
  75. #define __ptr(x) ((unsigned long *)(x))
  76. #define __put_user_asm(err,x,ptr,bwl) \
  77. __asm__ ("move" #bwl " %0,%1" \
  78. : /* no outputs */ \
  79. :"d" (x),"m" (*__ptr(ptr)) : "memory")
  80. #define get_user(x, ptr) \
  81. ({ \
  82. int __gu_err = 0; \
  83. typeof(x) __gu_val = 0; \
  84. switch (sizeof(*(ptr))) { \
  85. case 1: \
  86. __get_user_asm(__gu_err, __gu_val, ptr, b, "=d"); \
  87. break; \
  88. case 2: \
  89. __get_user_asm(__gu_err, __gu_val, ptr, w, "=r"); \
  90. break; \
  91. case 4: \
  92. __get_user_asm(__gu_err, __gu_val, ptr, l, "=r"); \
  93. break; \
  94. case 8: \
  95. memcpy((void *) &__gu_val, ptr, sizeof (*(ptr))); \
  96. break; \
  97. default: \
  98. __gu_val = 0; \
  99. __gu_err = __get_user_bad(); \
  100. break; \
  101. } \
  102. (x) = (typeof(*(ptr))) __gu_val; \
  103. __gu_err; \
  104. })
  105. #define __get_user(x, ptr) get_user(x, ptr)
  106. extern int __get_user_bad(void);
  107. #define __get_user_asm(err,x,ptr,bwl,reg) \
  108. __asm__ ("move" #bwl " %1,%0" \
  109. : "=d" (x) \
  110. : "m" (*__ptr(ptr)))
  111. #define copy_from_user(to, from, n) (memcpy(to, from, n), 0)
  112. #define copy_to_user(to, from, n) (memcpy(to, from, n), 0)
  113. #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
  114. #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
  115. #define __copy_to_user_inatomic __copy_to_user
  116. #define __copy_from_user_inatomic __copy_from_user
  117. #define copy_to_user_ret(to,from,n,retval) ({ if (copy_to_user(to,from,n)) return retval; })
  118. #define copy_from_user_ret(to,from,n,retval) ({ if (copy_from_user(to,from,n)) return retval; })
  119. /*
  120. * Copy a null terminated string from userspace.
  121. */
  122. static inline long
  123. strncpy_from_user(char *dst, const char *src, long count)
  124. {
  125. char *tmp;
  126. strncpy(dst, src, count);
  127. for (tmp = dst; *tmp && count > 0; tmp++, count--)
  128. ;
  129. return(tmp - dst); /* DAVIDM should we count a NUL ? check getname */
  130. }
  131. /*
  132. * Return the size of a string (including the ending 0)
  133. *
  134. * Return 0 on exception, a value greater than N if too long
  135. */
  136. static inline long strnlen_user(const char *src, long n)
  137. {
  138. return(strlen(src) + 1); /* DAVIDM make safer */
  139. }
  140. #define strlen_user(str) strnlen_user(str, 32767)
  141. /*
  142. * Zero Userspace
  143. */
  144. static inline unsigned long
  145. __clear_user(void *to, unsigned long n)
  146. {
  147. memset(to, 0, n);
  148. return 0;
  149. }
  150. #define clear_user(to,n) __clear_user(to,n)
  151. #endif /* _M68KNOMMU_UACCESS_H */