uaccess.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2006 Atmark Techno, Inc.
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. */
  8. #ifndef _ASM_MICROBLAZE_UACCESS_H
  9. #define _ASM_MICROBLAZE_UACCESS_H
  10. #ifdef __KERNEL__
  11. #ifndef __ASSEMBLY__
  12. #include <linux/kernel.h>
  13. #include <linux/errno.h>
  14. #include <linux/sched.h> /* RLIMIT_FSIZE */
  15. #include <linux/mm.h>
  16. #include <asm/mmu.h>
  17. #include <asm/page.h>
  18. #include <asm/pgtable.h>
  19. #include <asm/segment.h>
  20. #include <linux/string.h>
  21. #define VERIFY_READ 0
  22. #define VERIFY_WRITE 1
  23. extern int ___range_ok(unsigned long addr, unsigned long size);
  24. #define __range_ok(addr, size) \
  25. ___range_ok((unsigned long)(addr), (unsigned long)(size))
  26. #define access_ok(type, addr, size) (__range_ok((addr), (size)) == 0)
  27. #define __access_ok(add, size) (__range_ok((addr), (size)) == 0)
  28. extern inline int bad_user_access_length(void)
  29. {
  30. return 0;
  31. }
  32. /* FIXME this is function for optimalization -> memcpy */
  33. #define __get_user(var, ptr) \
  34. ({ \
  35. int __gu_err = 0; \
  36. switch (sizeof(*(ptr))) { \
  37. case 1: \
  38. case 2: \
  39. case 4: \
  40. (var) = *(ptr); \
  41. break; \
  42. case 8: \
  43. memcpy((void *) &(var), (ptr), 8); \
  44. break; \
  45. default: \
  46. (var) = 0; \
  47. __gu_err = __get_user_bad(); \
  48. break; \
  49. } \
  50. __gu_err; \
  51. })
  52. #define __get_user_bad() (bad_user_access_length(), (-EFAULT))
  53. #define __put_user(var, ptr) \
  54. ({ \
  55. int __pu_err = 0; \
  56. switch (sizeof(*(ptr))) { \
  57. case 1: \
  58. case 2: \
  59. case 4: \
  60. *(ptr) = (var); \
  61. break; \
  62. case 8: { \
  63. typeof(*(ptr)) __pu_val = var; \
  64. memcpy(ptr, &__pu_val, sizeof(__pu_val));\
  65. } \
  66. break; \
  67. default: \
  68. __pu_err = __put_user_bad(); \
  69. break; \
  70. } \
  71. __pu_err; \
  72. })
  73. #define __put_user_bad() (bad_user_access_length(), (-EFAULT))
  74. #define put_user(x, ptr) __put_user(x, ptr)
  75. #define get_user(x, ptr) __get_user(x, ptr)
  76. #define copy_to_user(to, from, n) (memcpy(to, from, n), 0)
  77. #define copy_from_user(to, from, n) (memcpy(to, from, n), 0)
  78. #define __copy_to_user(to, from, n) (copy_to_user(to, from, n))
  79. #define __copy_from_user(to, from, n) (copy_from_user(to, from, n))
  80. #define __copy_to_user_inatomic(to, from, n) (__copy_to_user(to, from, n))
  81. #define __copy_from_user_inatomic(to, from, n) (__copy_from_user(to, from, n))
  82. #define __clear_user(addr, n) (memset((void *)addr, 0, n), 0)
  83. static inline unsigned long clear_user(void *addr, unsigned long size)
  84. {
  85. if (access_ok(VERIFY_WRITE, addr, size))
  86. size = __clear_user(addr, size);
  87. return size;
  88. }
  89. /* Returns 0 if exception not found and fixup otherwise. */
  90. extern unsigned long search_exception_table(unsigned long);
  91. extern long strncpy_from_user(char *dst, const char __user *src, long count);
  92. extern long strnlen_user(const char __user *src, long count);
  93. extern long __strncpy_from_user(char *dst, const char __user *src, long count);
  94. /*
  95. * The exception table consists of pairs of addresses: the first is the
  96. * address of an instruction that is allowed to fault, and the second is
  97. * the address at which the program should continue. No registers are
  98. * modified, so it is entirely up to the continuation code to figure out
  99. * what to do.
  100. *
  101. * All the routines below use bits of fixup code that are out of line
  102. * with the main instruction path. This means when everything is well,
  103. * we don't even have to jump over them. Further, they do not intrude
  104. * on our cache or tlb entries.
  105. */
  106. struct exception_table_entry {
  107. unsigned long insn, fixup;
  108. };
  109. #endif /* __ASSEMBLY__ */
  110. #endif /* __KERNEL__ */
  111. #endif /* _ASM_MICROBLAZE_UACCESS_H */