um_uaccess.h 3.2 KB

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