uaccess.h 933 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef UACCESS_H
  3. #define UACCESS_H
  4. #include <linux/compiler.h>
  5. extern void *__user_addr_min, *__user_addr_max;
  6. #define put_user(x, ptr) \
  7. ({ \
  8. typeof(ptr) __pu_ptr = (ptr); \
  9. __chk_user_ptr(__pu_ptr); \
  10. WRITE_ONCE(*(__pu_ptr), x); \
  11. 0; \
  12. })
  13. #define get_user(x, ptr) \
  14. ({ \
  15. typeof(ptr) __pu_ptr = (ptr); \
  16. __chk_user_ptr(__pu_ptr); \
  17. x = READ_ONCE(*(__pu_ptr)); \
  18. 0; \
  19. })
  20. static void volatile_memcpy(volatile char *to, const volatile char *from,
  21. unsigned long n)
  22. {
  23. while (n--)
  24. *(to++) = *(from++);
  25. }
  26. static inline int copy_from_user(void *to, const void __user volatile *from,
  27. unsigned long n)
  28. {
  29. volatile_memcpy(to, from, n);
  30. return 0;
  31. }
  32. static inline int copy_to_user(void __user volatile *to, const void *from,
  33. unsigned long n)
  34. {
  35. volatile_memcpy(to, from, n);
  36. return 0;
  37. }
  38. #endif /* UACCESS_H */