um_uaccess.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  3. * Licensed under the GPL
  4. */
  5. #ifndef __ARCH_UM_UACCESS_H
  6. #define __ARCH_UM_UACCESS_H
  7. #include "choose-mode.h"
  8. #ifdef CONFIG_MODE_TT
  9. #include "uaccess-tt.h"
  10. #endif
  11. #ifdef CONFIG_MODE_SKAS
  12. #include "uaccess-skas.h"
  13. #endif
  14. #include "asm/fixmap.h"
  15. #define __under_task_size(addr, size) \
  16. (((unsigned long) (addr) < TASK_SIZE) && \
  17. (((unsigned long) (addr) + (size)) < TASK_SIZE))
  18. #define __access_ok_vsyscall(type, addr, size) \
  19. ((type == VERIFY_READ) && \
  20. ((unsigned long) (addr) >= FIXADDR_USER_START) && \
  21. ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
  22. ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
  23. #define __addr_range_nowrap(addr, size) \
  24. ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
  25. #define access_ok(type, addr, size) \
  26. (__addr_range_nowrap(addr, size) && \
  27. (__under_task_size(addr, size) || \
  28. __access_ok_vsyscall(type, addr, size) || \
  29. segment_eq(get_fs(), KERNEL_DS) || \
  30. CHOOSE_MODE_PROC(access_ok_tt, access_ok_skas, type, addr, size)))
  31. static inline int copy_from_user(void *to, const void __user *from, int n)
  32. {
  33. return(CHOOSE_MODE_PROC(copy_from_user_tt, copy_from_user_skas, to,
  34. from, n));
  35. }
  36. static inline int copy_to_user(void __user *to, const void *from, int n)
  37. {
  38. return(CHOOSE_MODE_PROC(copy_to_user_tt, copy_to_user_skas, to,
  39. from, n));
  40. }
  41. /*
  42. * strncpy_from_user: - Copy a NUL terminated string from userspace.
  43. * @dst: Destination address, in kernel space. This buffer must be at
  44. * least @count bytes long.
  45. * @src: Source address, in user space.
  46. * @count: Maximum number of bytes to copy, including the trailing NUL.
  47. *
  48. * Copies a NUL-terminated string from userspace to kernel space.
  49. *
  50. * On success, returns the length of the string (not including the trailing
  51. * NUL).
  52. *
  53. * If access to userspace fails, returns -EFAULT (some data may have been
  54. * copied).
  55. *
  56. * If @count is smaller than the length of the string, copies @count bytes
  57. * and returns @count.
  58. */
  59. static inline int strncpy_from_user(char *dst, const char __user *src, int count)
  60. {
  61. return(CHOOSE_MODE_PROC(strncpy_from_user_tt, strncpy_from_user_skas,
  62. dst, src, count));
  63. }
  64. /*
  65. * __clear_user: - Zero a block of memory in user space, with less checking.
  66. * @to: Destination address, in user space.
  67. * @n: Number of bytes to zero.
  68. *
  69. * Zero a block of memory in user space. Caller must check
  70. * the specified block with access_ok() before calling this function.
  71. *
  72. * Returns number of bytes that could not be cleared.
  73. * On success, this will be zero.
  74. */
  75. static inline int __clear_user(void *mem, int len)
  76. {
  77. return(CHOOSE_MODE_PROC(__clear_user_tt, __clear_user_skas, mem, len));
  78. }
  79. /*
  80. * clear_user: - Zero a block of memory in user space.
  81. * @to: Destination address, in user space.
  82. * @n: Number of bytes to zero.
  83. *
  84. * Zero a block of memory in user space.
  85. *
  86. * Returns number of bytes that could not be cleared.
  87. * On success, this will be zero.
  88. */
  89. static inline int clear_user(void __user *mem, int len)
  90. {
  91. return(CHOOSE_MODE_PROC(clear_user_tt, clear_user_skas, mem, len));
  92. }
  93. /*
  94. * strlen_user: - Get the size of a string in user space.
  95. * @str: The string to measure.
  96. * @n: The maximum valid length
  97. *
  98. * Get the size of a NUL-terminated string in user space.
  99. *
  100. * Returns the size of the string INCLUDING the terminating NUL.
  101. * On exception, returns 0.
  102. * If the string is too long, returns a value greater than @n.
  103. */
  104. static inline int strnlen_user(const void __user *str, long len)
  105. {
  106. return(CHOOSE_MODE_PROC(strnlen_user_tt, strnlen_user_skas, str, len));
  107. }
  108. #endif
  109. /*
  110. * Overrides for Emacs so that we follow Linus's tabbing style.
  111. * Emacs will notice this stuff at the end of the file and automatically
  112. * adjust the settings for this buffer only. This must remain at the end
  113. * of the file.
  114. * ---------------------------------------------------------------------------
  115. * Local variables:
  116. * c-file-style: "linux"
  117. * End:
  118. */