um_uaccess.h 3.3 KB

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