uaccess.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #ifndef __UM_UACCESS_H
  6. #define __UM_UACCESS_H
  7. #include "linux/sched.h"
  8. #define VERIFY_READ 0
  9. #define VERIFY_WRITE 1
  10. /*
  11. * The fs value determines whether argument validity checking should be
  12. * performed or not. If get_fs() == USER_DS, checking is performed, with
  13. * get_fs() == KERNEL_DS, checking is bypassed.
  14. *
  15. * For historical reasons, these macros are grossly misnamed.
  16. */
  17. #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
  18. #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
  19. #define USER_DS MAKE_MM_SEG(TASK_SIZE)
  20. #define get_ds() (KERNEL_DS)
  21. #define get_fs() (current_thread_info()->addr_limit)
  22. #define set_fs(x) (current_thread_info()->addr_limit = (x))
  23. #define segment_eq(a, b) ((a).seg == (b).seg)
  24. #include "um_uaccess.h"
  25. #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
  26. #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
  27. #define __copy_to_user_inatomic __copy_to_user
  28. #define __copy_from_user_inatomic __copy_from_user
  29. #define __get_user(x, ptr) \
  30. ({ \
  31. const __typeof__(*(ptr)) __user *__private_ptr = (ptr); \
  32. __typeof__(x) __private_val; \
  33. int __private_ret = -EFAULT; \
  34. (x) = (__typeof__(*(__private_ptr)))0; \
  35. if (__copy_from_user((__force void *)&__private_val, (__private_ptr),\
  36. sizeof(*(__private_ptr))) == 0) { \
  37. (x) = (__typeof__(*(__private_ptr))) __private_val; \
  38. __private_ret = 0; \
  39. } \
  40. __private_ret; \
  41. })
  42. #define get_user(x, ptr) \
  43. ({ \
  44. const __typeof__((*(ptr))) __user *private_ptr = (ptr); \
  45. (access_ok(VERIFY_READ, private_ptr, sizeof(*private_ptr)) ? \
  46. __get_user(x, private_ptr) : ((x) = (__typeof__(*ptr))0, -EFAULT)); \
  47. })
  48. #define __put_user(x, ptr) \
  49. ({ \
  50. __typeof__(*(ptr)) __user *__private_ptr = ptr; \
  51. __typeof__(*(__private_ptr)) __private_val; \
  52. int __private_ret = -EFAULT; \
  53. __private_val = (__typeof__(*(__private_ptr))) (x); \
  54. if (__copy_to_user((__private_ptr), &__private_val, \
  55. sizeof(*(__private_ptr))) == 0) { \
  56. __private_ret = 0; \
  57. } \
  58. __private_ret; \
  59. })
  60. #define put_user(x, ptr) \
  61. ({ \
  62. __typeof__(*(ptr)) __user *private_ptr = (ptr); \
  63. (access_ok(VERIFY_WRITE, private_ptr, sizeof(*private_ptr)) ? \
  64. __put_user(x, private_ptr) : -EFAULT); \
  65. })
  66. #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
  67. struct exception_table_entry
  68. {
  69. unsigned long insn;
  70. unsigned long fixup;
  71. };
  72. #endif