um_uaccess.h 3.0 KB

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