um_uaccess.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.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. extern int __do_copy_to_user(void *to, const void *from, int n,
  26. void **fault_addr, jmp_buf **fault_catcher);
  27. extern void __do_copy(void *to, const void *from, int n);
  28. /*
  29. * strncpy_from_user: - Copy a NUL terminated string from userspace.
  30. * @dst: Destination address, in kernel space. This buffer must be at
  31. * least @count bytes long.
  32. * @src: Source address, in user space.
  33. * @count: Maximum number of bytes to copy, including the trailing NUL.
  34. *
  35. * Copies a NUL-terminated string from userspace to kernel space.
  36. *
  37. * On success, returns the length of the string (not including the trailing
  38. * NUL).
  39. *
  40. * If access to userspace fails, returns -EFAULT (some data may have been
  41. * copied).
  42. *
  43. * If @count is smaller than the length of the string, copies @count bytes
  44. * and returns @count.
  45. */
  46. extern int strncpy_from_user(char *dst, const char __user *src, int count);
  47. /*
  48. * __clear_user: - Zero a block of memory in user space, with less checking.
  49. * @to: Destination address, in user space.
  50. * @n: Number of bytes to zero.
  51. *
  52. * Zero a block of memory in user space. Caller must check
  53. * the specified block with access_ok() before calling this function.
  54. *
  55. * Returns number of bytes that could not be cleared.
  56. * On success, this will be zero.
  57. */
  58. extern int __clear_user(void __user *mem, int len);
  59. /*
  60. * clear_user: - Zero a block of memory in user space.
  61. * @to: Destination address, in user space.
  62. * @n: Number of bytes to zero.
  63. *
  64. * Zero a block of memory in user space.
  65. *
  66. * Returns number of bytes that could not be cleared.
  67. * On success, this will be zero.
  68. */
  69. extern int clear_user(void __user *mem, int len);
  70. /*
  71. * strlen_user: - Get the size of a string in user space.
  72. * @str: The string to measure.
  73. * @n: The maximum valid length
  74. *
  75. * Get the size of a NUL-terminated string in user space.
  76. *
  77. * Returns the size of the string INCLUDING the terminating NUL.
  78. * On exception, returns 0.
  79. * If the string is too long, returns a value greater than @n.
  80. */
  81. extern int strnlen_user(const void __user *str, int len);
  82. #endif