uaccess.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
  4. * Copyright (C) 2015 Richard Weinberger (richard@nod.at)
  5. */
  6. #ifndef __UM_UACCESS_H
  7. #define __UM_UACCESS_H
  8. #include <asm/elf.h>
  9. #include <linux/unaligned.h>
  10. #include <sysdep/faultinfo.h>
  11. #define __under_task_size(addr, size) \
  12. (((unsigned long) (addr) < TASK_SIZE) && \
  13. (((unsigned long) (addr) + (size)) < TASK_SIZE))
  14. #define __addr_range_nowrap(addr, size) \
  15. ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
  16. extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n);
  17. extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n);
  18. extern unsigned long __clear_user(void __user *mem, unsigned long len);
  19. static inline int __access_ok(const void __user *ptr, unsigned long size);
  20. /* Teach asm-generic/uaccess.h that we have C functions for these. */
  21. #define __access_ok __access_ok
  22. #define __clear_user __clear_user
  23. #define INLINE_COPY_FROM_USER
  24. #define INLINE_COPY_TO_USER
  25. #include <asm-generic/uaccess.h>
  26. static inline int __access_ok(const void __user *ptr, unsigned long size)
  27. {
  28. unsigned long addr = (unsigned long)ptr;
  29. return __addr_range_nowrap(addr, size) && __under_task_size(addr, size);
  30. }
  31. #define __get_kernel_nofault(dst, src, type, err_label) \
  32. do { \
  33. int __faulted; \
  34. \
  35. ___backtrack_faulted(__faulted); \
  36. if (__faulted) { \
  37. *((type *)dst) = (type) 0; \
  38. goto err_label; \
  39. } \
  40. *((type *)dst) = get_unaligned((type *)(src)); \
  41. barrier(); \
  42. current->thread.segv_continue = NULL; \
  43. } while (0)
  44. #define __put_kernel_nofault(dst, src, type, err_label) \
  45. do { \
  46. int __faulted; \
  47. \
  48. ___backtrack_faulted(__faulted); \
  49. if (__faulted) \
  50. goto err_label; \
  51. put_unaligned(*((type *)src), (type *)(dst)); \
  52. barrier(); \
  53. current->thread.segv_continue = NULL; \
  54. } while (0)
  55. #endif