um_uaccess.h 4.0 KB

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