uaccess.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 <asm/errno.h>
  8. #include <asm/processor.h>
  9. /* thread_info has a mm_segment_t in it, so put the definition up here */
  10. typedef struct {
  11. unsigned long seg;
  12. } mm_segment_t;
  13. #include "linux/thread_info.h"
  14. #define VERIFY_READ 0
  15. #define VERIFY_WRITE 1
  16. /*
  17. * The fs value determines whether argument validity checking should be
  18. * performed or not. If get_fs() == USER_DS, checking is performed, with
  19. * get_fs() == KERNEL_DS, checking is bypassed.
  20. *
  21. * For historical reasons, these macros are grossly misnamed.
  22. */
  23. #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
  24. #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
  25. #define USER_DS MAKE_MM_SEG(TASK_SIZE)
  26. #define get_ds() (KERNEL_DS)
  27. #define get_fs() (current_thread_info()->addr_limit)
  28. #define set_fs(x) (current_thread_info()->addr_limit = (x))
  29. #define segment_eq(a, b) ((a).seg == (b).seg)
  30. #include "um_uaccess.h"
  31. #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
  32. #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
  33. #define __copy_to_user_inatomic __copy_to_user
  34. #define __copy_from_user_inatomic __copy_from_user
  35. #define __get_user(x, ptr) \
  36. ({ \
  37. const __typeof__(*(ptr)) __user *__private_ptr = (ptr); \
  38. __typeof__(x) __private_val; \
  39. int __private_ret = -EFAULT; \
  40. (x) = (__typeof__(*(__private_ptr)))0; \
  41. if (__copy_from_user((__force void *)&__private_val, (__private_ptr),\
  42. sizeof(*(__private_ptr))) == 0) { \
  43. (x) = (__typeof__(*(__private_ptr))) __private_val; \
  44. __private_ret = 0; \
  45. } \
  46. __private_ret; \
  47. })
  48. #define get_user(x, ptr) \
  49. ({ \
  50. const __typeof__((*(ptr))) __user *private_ptr = (ptr); \
  51. (access_ok(VERIFY_READ, private_ptr, sizeof(*private_ptr)) ? \
  52. __get_user(x, private_ptr) : ((x) = (__typeof__(*ptr))0, -EFAULT)); \
  53. })
  54. #define __put_user(x, ptr) \
  55. ({ \
  56. __typeof__(*(ptr)) __user *__private_ptr = ptr; \
  57. __typeof__(*(__private_ptr)) __private_val; \
  58. int __private_ret = -EFAULT; \
  59. __private_val = (__typeof__(*(__private_ptr))) (x); \
  60. if (__copy_to_user((__private_ptr), &__private_val, \
  61. sizeof(*(__private_ptr))) == 0) { \
  62. __private_ret = 0; \
  63. } \
  64. __private_ret; \
  65. })
  66. #define put_user(x, ptr) \
  67. ({ \
  68. __typeof__(*(ptr)) __user *private_ptr = (ptr); \
  69. (access_ok(VERIFY_WRITE, private_ptr, sizeof(*private_ptr)) ? \
  70. __put_user(x, private_ptr) : -EFAULT); \
  71. })
  72. #define strlen_user(str) strnlen_user(str, ~0U >> 1)
  73. struct exception_table_entry
  74. {
  75. unsigned long insn;
  76. unsigned long fixup;
  77. };
  78. #endif