um_uaccess.h 3.1 KB

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