1 #ifndef __LINUX_UACCESS_H__
2 #define __LINUX_UACCESS_H__
4 #include <linux/sched.h>
6 #define uaccess_kernel() segment_eq(get_fs(), KERNEL_DS)
8 #include <asm/uaccess.h>
10 static __always_inline void pagefault_disabled_inc(void)
12 current->pagefault_disabled++;
15 static __always_inline void pagefault_disabled_dec(void)
17 current->pagefault_disabled--;
18 WARN_ON(current->pagefault_disabled < 0);
22 * These routines enable/disable the pagefault handler. If disabled, it will
23 * not take any locks and go straight to the fixup table.
25 * User access methods will not sleep when called from a pagefault_disabled()
28 static inline void pagefault_disable(void)
30 pagefault_disabled_inc();
32 * make sure to have issued the store before a pagefault
38 static inline void pagefault_enable(void)
41 * make sure to issue those last loads/stores before enabling
42 * the pagefault handler again.
45 pagefault_disabled_dec();
49 * Is the pagefault handler disabled? If so, user access methods will not sleep.
51 #define pagefault_disabled() (current->pagefault_disabled != 0)
54 * The pagefault handler is in general disabled by pagefault_disable() or
55 * when in irq context (via in_atomic()).
57 * This function should only be used by the fault handlers. Other users should
58 * stick to pagefault_disabled().
59 * Please NEVER use preempt_disable() to disable the fault handler. With
60 * !CONFIG_PREEMPT_COUNT, this is like a NOP. So the handler won't be disabled.
61 * in_atomic() will report different values based on !CONFIG_PREEMPT_COUNT.
63 #define faulthandler_disabled() (pagefault_disabled() || in_atomic())
65 #ifndef ARCH_HAS_NOCACHE_UACCESS
67 static inline unsigned long __copy_from_user_inatomic_nocache(void *to,
68 const void __user *from, unsigned long n)
70 return __copy_from_user_inatomic(to, from, n);
73 static inline unsigned long __copy_from_user_nocache(void *to,
74 const void __user *from, unsigned long n)
76 return __copy_from_user(to, from, n);
79 #endif /* ARCH_HAS_NOCACHE_UACCESS */
82 * probe_kernel_read(): safely attempt to read from a location
83 * @dst: pointer to the buffer that shall take the data
84 * @src: address to read from
85 * @size: size of the data chunk
87 * Safely read from address @src to the buffer at @dst. If a kernel fault
88 * happens, handle that and return -EFAULT.
90 extern long probe_kernel_read(void *dst, const void *src, size_t size);
91 extern long __probe_kernel_read(void *dst, const void *src, size_t size);
94 * probe_user_read(): safely attempt to read from a location in user space
95 * @dst: pointer to the buffer that shall take the data
96 * @src: address to read from
97 * @size: size of the data chunk
99 * Safely read from address @src to the buffer at @dst. If a kernel fault
100 * happens, handle that and return -EFAULT.
102 extern long probe_user_read(void *dst, const void __user *src, size_t size);
105 * probe_kernel_write(): safely attempt to write to a location
106 * @dst: address to write to
107 * @src: pointer to the data that shall be written
108 * @size: size of the data chunk
110 * Safely write to address @dst from the buffer at @src. If a kernel fault
111 * happens, handle that and return -EFAULT.
113 extern long notrace probe_kernel_write(void *dst, const void *src, size_t size);
114 extern long notrace __probe_kernel_write(void *dst, const void *src, size_t size);
117 * probe_user_write(): safely attempt to write to a location in user space
118 * @dst: address to write to
119 * @src: pointer to the data that shall be written
120 * @size: size of the data chunk
122 * Safely write to address @dst from the buffer at @src. If a kernel fault
123 * happens, handle that and return -EFAULT.
125 extern long notrace probe_user_write(void __user *dst, const void *src, size_t size);
126 extern long notrace __probe_user_write(void __user *dst, const void *src, size_t size);
128 extern long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count);
129 extern long strncpy_from_unsafe_user(char *dst, const void __user *unsafe_addr,
131 extern long strnlen_unsafe_user(const void __user *unsafe_addr, long count);
134 * probe_kernel_address(): safely attempt to read from a location
135 * @addr: address to read from
136 * @retval: read into this variable
138 * Returns 0 on success, or -EFAULT.
140 #define probe_kernel_address(addr, retval) \
141 probe_kernel_read(&retval, addr, sizeof(retval))
143 #endif /* __LINUX_UACCESS_H__ */