1 #ifndef _ASM_X86_UACCESS_32_H
2 #define _ASM_X86_UACCESS_32_H
5 * User space memory access functions
7 #include <linux/errno.h>
8 #include <linux/thread_info.h>
9 #include <linux/string.h>
13 unsigned long __must_check __copy_to_user_ll
14 (void __user *to, const void *from, unsigned long n);
15 unsigned long __must_check __copy_from_user_ll
16 (void *to, const void __user *from, unsigned long n);
17 unsigned long __must_check __copy_from_user_ll_nozero
18 (void *to, const void __user *from, unsigned long n);
19 unsigned long __must_check __copy_from_user_ll_nocache
20 (void *to, const void __user *from, unsigned long n);
21 unsigned long __must_check __copy_from_user_ll_nocache_nozero
22 (void *to, const void __user *from, unsigned long n);
25 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
26 * @to: Destination address, in user space.
27 * @from: Source address, in kernel space.
28 * @n: Number of bytes to copy.
30 * Context: User context only.
32 * Copy data from kernel space to user space. Caller must check
33 * the specified block with access_ok() before calling this function.
34 * The caller should also make sure he pins the user space address
35 * so that we don't result in page fault and sleep.
37 * Here we special-case 1, 2 and 4-byte copy_*_user invocations. On a fault
38 * we return the initial request size (1, 2 or 4), as copy_*_user should do.
39 * If a store crosses a page boundary and gets a fault, the x86 will not write
40 * anything, so this is accurate.
43 static __always_inline unsigned long __must_check
44 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
46 if (__builtin_constant_p(n)) {
51 __put_user_size(*(u8 *)from, (u8 __user *)to,
55 __put_user_size(*(u16 *)from, (u16 __user *)to,
59 __put_user_size(*(u32 *)from, (u32 __user *)to,
64 return __copy_to_user_ll(to, from, n);
68 * __copy_to_user: - Copy a block of data into user space, with less checking.
69 * @to: Destination address, in user space.
70 * @from: Source address, in kernel space.
71 * @n: Number of bytes to copy.
73 * Context: User context only. This function may sleep.
75 * Copy data from kernel space to user space. Caller must check
76 * the specified block with access_ok() before calling this function.
78 * Returns number of bytes that could not be copied.
79 * On success, this will be zero.
81 static __always_inline unsigned long __must_check
82 __copy_to_user(void __user *to, const void *from, unsigned long n)
85 return __copy_to_user_inatomic(to, from, n);
88 static __always_inline unsigned long
89 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
91 /* Avoid zeroing the tail if the copy fails..
92 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
93 * but as the zeroing behaviour is only significant when n is not
94 * constant, that shouldn't be a problem.
96 if (__builtin_constant_p(n)) {
101 __get_user_size(*(u8 *)to, from, 1, ret, 1);
104 __get_user_size(*(u16 *)to, from, 2, ret, 2);
107 __get_user_size(*(u32 *)to, from, 4, ret, 4);
111 return __copy_from_user_ll_nozero(to, from, n);
115 * __copy_from_user: - Copy a block of data from user space, with less checking.
116 * @to: Destination address, in kernel space.
117 * @from: Source address, in user space.
118 * @n: Number of bytes to copy.
120 * Context: User context only. This function may sleep.
122 * Copy data from user space to kernel space. Caller must check
123 * the specified block with access_ok() before calling this function.
125 * Returns number of bytes that could not be copied.
126 * On success, this will be zero.
128 * If some data could not be copied, this function will pad the copied
129 * data to the requested size using zero bytes.
131 * An alternate version - __copy_from_user_inatomic() - may be called from
132 * atomic context and will fail rather than sleep. In this case the
133 * uncopied bytes will *NOT* be padded with zeros. See fs/filemap.h
134 * for explanation of why this is needed.
136 static __always_inline unsigned long
137 __copy_from_user(void *to, const void __user *from, unsigned long n)
140 if (__builtin_constant_p(n)) {
145 __get_user_size(*(u8 *)to, from, 1, ret, 1);
148 __get_user_size(*(u16 *)to, from, 2, ret, 2);
151 __get_user_size(*(u32 *)to, from, 4, ret, 4);
155 return __copy_from_user_ll(to, from, n);
158 static __always_inline unsigned long __copy_from_user_nocache(void *to,
159 const void __user *from, unsigned long n)
162 if (__builtin_constant_p(n)) {
167 __get_user_size(*(u8 *)to, from, 1, ret, 1);
170 __get_user_size(*(u16 *)to, from, 2, ret, 2);
173 __get_user_size(*(u32 *)to, from, 4, ret, 4);
177 return __copy_from_user_ll_nocache(to, from, n);
180 static __always_inline unsigned long
181 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
184 return __copy_from_user_ll_nocache_nozero(to, from, n);
187 unsigned long __must_check copy_to_user(void __user *to,
188 const void *from, unsigned long n);
189 unsigned long __must_check _copy_from_user(void *to,
190 const void __user *from,
194 extern void copy_from_user_overflow(void)
195 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
196 __compiletime_error("copy_from_user() buffer size is not provably correct")
198 __compiletime_warning("copy_from_user() buffer size is not provably correct")
202 static inline unsigned long __must_check copy_from_user(void *to,
203 const void __user *from,
206 int sz = __compiletime_object_size(to);
208 if (likely(sz == -1 || sz >= n))
209 n = _copy_from_user(to, from, n);
211 copy_from_user_overflow();
216 unsigned long __must_check clear_user(void __user *mem, unsigned long len);
217 unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
219 #endif /* _ASM_X86_UACCESS_32_H */