uaccess.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef __LINUX_UACCESS_H__
  2. #define __LINUX_UACCESS_H__
  3. #include <asm/uaccess.h>
  4. #ifndef ARCH_HAS_NOCACHE_UACCESS
  5. static inline unsigned long __copy_from_user_inatomic_nocache(void *to,
  6. const void __user *from, unsigned long n)
  7. {
  8. return __copy_from_user_inatomic(to, from, n);
  9. }
  10. static inline unsigned long __copy_from_user_nocache(void *to,
  11. const void __user *from, unsigned long n)
  12. {
  13. return __copy_from_user(to, from, n);
  14. }
  15. #endif /* ARCH_HAS_NOCACHE_UACCESS */
  16. /**
  17. * probe_kernel_address(): safely attempt to read from a location
  18. * @addr: address to read from - its type is type typeof(retval)*
  19. * @retval: read into this variable
  20. *
  21. * Safely read from address @addr into variable @revtal. If a kernel fault
  22. * happens, handle that and return -EFAULT.
  23. * We ensure that the __get_user() is executed in atomic context so that
  24. * do_page_fault() doesn't attempt to take mmap_sem. This makes
  25. * probe_kernel_address() suitable for use within regions where the caller
  26. * already holds mmap_sem, or other locks which nest inside mmap_sem.
  27. */
  28. #define probe_kernel_address(addr, retval) \
  29. ({ \
  30. long ret; \
  31. \
  32. inc_preempt_count(); \
  33. ret = __get_user(retval, addr); \
  34. dec_preempt_count(); \
  35. ret; \
  36. })
  37. #endif /* __LINUX_UACCESS_H__ */