um_uaccess.h 3.5 KB

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