um_uaccess.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /*
  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. extern int strncpy_from_user(char *dst, const char __user *src, int count);
  46. /*
  47. * __clear_user: - Zero a block of memory in user space, with less checking.
  48. * @to: Destination address, in user space.
  49. * @n: Number of bytes to zero.
  50. *
  51. * Zero a block of memory in user space. Caller must check
  52. * the specified block with access_ok() before calling this function.
  53. *
  54. * Returns number of bytes that could not be cleared.
  55. * On success, this will be zero.
  56. */
  57. extern int __clear_user(void __user *mem, int len);
  58. /*
  59. * clear_user: - Zero a block of memory in user space.
  60. * @to: Destination address, in user space.
  61. * @n: Number of bytes to zero.
  62. *
  63. * Zero a block of memory in user space.
  64. *
  65. * Returns number of bytes that could not be cleared.
  66. * On success, this will be zero.
  67. */
  68. extern int clear_user(void __user *mem, int len);
  69. /*
  70. * strlen_user: - Get the size of a string in user space.
  71. * @str: The string to measure.
  72. * @n: The maximum valid length
  73. *
  74. * Get the size of a NUL-terminated string in user space.
  75. *
  76. * Returns the size of the string INCLUDING the terminating NUL.
  77. * On exception, returns 0.
  78. * If the string is too long, returns a value greater than @n.
  79. */
  80. extern int strnlen_user(const void __user *str, int len);
  81. #endif