uaccess.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2002 Jeff Dike ([email protected])
  4. * Copyright (C) 2015 Richard Weinberger ([email protected])
  5. */
  6. #ifndef __UM_UACCESS_H
  7. #define __UM_UACCESS_H
  8. #include <asm/elf.h>
  9. #include <asm/unaligned.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(addr, size) \
  14. (((unsigned long) (addr) >= FIXADDR_USER_START) && \
  15. ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
  16. ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
  17. #define __addr_range_nowrap(addr, size) \
  18. ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
  19. extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n);
  20. extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n);
  21. extern unsigned long __clear_user(void __user *mem, unsigned long len);
  22. static inline int __access_ok(const void __user *ptr, unsigned long size);
  23. /* Teach asm-generic/uaccess.h that we have C functions for these. */
  24. #define __access_ok __access_ok
  25. #define __clear_user __clear_user
  26. #define INLINE_COPY_FROM_USER
  27. #define INLINE_COPY_TO_USER
  28. #include <asm-generic/uaccess.h>
  29. static inline int __access_ok(const void __user *ptr, unsigned long size)
  30. {
  31. unsigned long addr = (unsigned long)ptr;
  32. return __addr_range_nowrap(addr, size) &&
  33. (__under_task_size(addr, size) ||
  34. __access_ok_vsyscall(addr, size));
  35. }
  36. /* no pagefaults for kernel addresses in um */
  37. #define __get_kernel_nofault(dst, src, type, err_label) \
  38. do { \
  39. *((type *)dst) = get_unaligned((type *)(src)); \
  40. if (0) /* make sure the label looks used to the compiler */ \
  41. goto err_label; \
  42. } while (0)
  43. #define __put_kernel_nofault(dst, src, type, err_label) \
  44. do { \
  45. put_unaligned(*((type *)src), (type *)(dst)); \
  46. if (0) /* make sure the label looks used to the compiler */ \
  47. goto err_label; \
  48. } while (0)
  49. #endif