x86: move __get_user and __put_user into uaccess.h.
[linux-2.6/mini2440.git] / include / asm-x86 / uaccess_32.h
blobd3b5bf88ea8638094083e33d678c16a0fb6f1696
1 #ifndef __i386_UACCESS_H
2 #define __i386_UACCESS_H
4 /*
5 * User space memory access functions
6 */
7 #include <linux/errno.h>
8 #include <linux/thread_info.h>
9 #include <linux/prefetch.h>
10 #include <linux/string.h>
11 #include <asm/asm.h>
12 #include <asm/page.h>
15 * movsl can be slow when source and dest are not both 8-byte aligned
17 #ifdef CONFIG_X86_INTEL_USERCOPY
18 extern struct movsl_mask {
19 int mask;
20 } ____cacheline_aligned_in_smp movsl_mask;
21 #endif
23 unsigned long __must_check __copy_to_user_ll
24 (void __user *to, const void *from, unsigned long n);
25 unsigned long __must_check __copy_from_user_ll
26 (void *to, const void __user *from, unsigned long n);
27 unsigned long __must_check __copy_from_user_ll_nozero
28 (void *to, const void __user *from, unsigned long n);
29 unsigned long __must_check __copy_from_user_ll_nocache
30 (void *to, const void __user *from, unsigned long n);
31 unsigned long __must_check __copy_from_user_ll_nocache_nozero
32 (void *to, const void __user *from, unsigned long n);
34 /**
35 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
36 * @to: Destination address, in user space.
37 * @from: Source address, in kernel space.
38 * @n: Number of bytes to copy.
40 * Context: User context only.
42 * Copy data from kernel space to user space. Caller must check
43 * the specified block with access_ok() before calling this function.
44 * The caller should also make sure he pins the user space address
45 * so that the we don't result in page fault and sleep.
47 * Here we special-case 1, 2 and 4-byte copy_*_user invocations. On a fault
48 * we return the initial request size (1, 2 or 4), as copy_*_user should do.
49 * If a store crosses a page boundary and gets a fault, the x86 will not write
50 * anything, so this is accurate.
53 static __always_inline unsigned long __must_check
54 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
56 if (__builtin_constant_p(n)) {
57 unsigned long ret;
59 switch (n) {
60 case 1:
61 __put_user_size(*(u8 *)from, (u8 __user *)to,
62 1, ret, 1);
63 return ret;
64 case 2:
65 __put_user_size(*(u16 *)from, (u16 __user *)to,
66 2, ret, 2);
67 return ret;
68 case 4:
69 __put_user_size(*(u32 *)from, (u32 __user *)to,
70 4, ret, 4);
71 return ret;
74 return __copy_to_user_ll(to, from, n);
77 /**
78 * __copy_to_user: - Copy a block of data into user space, with less checking.
79 * @to: Destination address, in user space.
80 * @from: Source address, in kernel space.
81 * @n: Number of bytes to copy.
83 * Context: User context only. This function may sleep.
85 * Copy data from kernel space to user space. Caller must check
86 * the specified block with access_ok() before calling this function.
88 * Returns number of bytes that could not be copied.
89 * On success, this will be zero.
91 static __always_inline unsigned long __must_check
92 __copy_to_user(void __user *to, const void *from, unsigned long n)
94 might_sleep();
95 return __copy_to_user_inatomic(to, from, n);
98 static __always_inline unsigned long
99 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
101 /* Avoid zeroing the tail if the copy fails..
102 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
103 * but as the zeroing behaviour is only significant when n is not
104 * constant, that shouldn't be a problem.
106 if (__builtin_constant_p(n)) {
107 unsigned long ret;
109 switch (n) {
110 case 1:
111 __get_user_size(*(u8 *)to, from, 1, ret, 1);
112 return ret;
113 case 2:
114 __get_user_size(*(u16 *)to, from, 2, ret, 2);
115 return ret;
116 case 4:
117 __get_user_size(*(u32 *)to, from, 4, ret, 4);
118 return ret;
121 return __copy_from_user_ll_nozero(to, from, n);
125 * __copy_from_user: - Copy a block of data from user space, with less checking.
126 * @to: Destination address, in kernel space.
127 * @from: Source address, in user space.
128 * @n: Number of bytes to copy.
130 * Context: User context only. This function may sleep.
132 * Copy data from user space to kernel space. Caller must check
133 * the specified block with access_ok() before calling this function.
135 * Returns number of bytes that could not be copied.
136 * On success, this will be zero.
138 * If some data could not be copied, this function will pad the copied
139 * data to the requested size using zero bytes.
141 * An alternate version - __copy_from_user_inatomic() - may be called from
142 * atomic context and will fail rather than sleep. In this case the
143 * uncopied bytes will *NOT* be padded with zeros. See fs/filemap.h
144 * for explanation of why this is needed.
146 static __always_inline unsigned long
147 __copy_from_user(void *to, const void __user *from, unsigned long n)
149 might_sleep();
150 if (__builtin_constant_p(n)) {
151 unsigned long ret;
153 switch (n) {
154 case 1:
155 __get_user_size(*(u8 *)to, from, 1, ret, 1);
156 return ret;
157 case 2:
158 __get_user_size(*(u16 *)to, from, 2, ret, 2);
159 return ret;
160 case 4:
161 __get_user_size(*(u32 *)to, from, 4, ret, 4);
162 return ret;
165 return __copy_from_user_ll(to, from, n);
168 #define ARCH_HAS_NOCACHE_UACCESS
170 static __always_inline unsigned long __copy_from_user_nocache(void *to,
171 const void __user *from, unsigned long n)
173 might_sleep();
174 if (__builtin_constant_p(n)) {
175 unsigned long ret;
177 switch (n) {
178 case 1:
179 __get_user_size(*(u8 *)to, from, 1, ret, 1);
180 return ret;
181 case 2:
182 __get_user_size(*(u16 *)to, from, 2, ret, 2);
183 return ret;
184 case 4:
185 __get_user_size(*(u32 *)to, from, 4, ret, 4);
186 return ret;
189 return __copy_from_user_ll_nocache(to, from, n);
192 static __always_inline unsigned long
193 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
194 unsigned long n)
196 return __copy_from_user_ll_nocache_nozero(to, from, n);
199 unsigned long __must_check copy_to_user(void __user *to,
200 const void *from, unsigned long n);
201 unsigned long __must_check copy_from_user(void *to,
202 const void __user *from,
203 unsigned long n);
204 long __must_check strncpy_from_user(char *dst, const char __user *src,
205 long count);
206 long __must_check __strncpy_from_user(char *dst,
207 const char __user *src, long count);
210 * strlen_user: - Get the size of a string in user space.
211 * @str: The string to measure.
213 * Context: User context only. This function may sleep.
215 * Get the size of a NUL-terminated string in user space.
217 * Returns the size of the string INCLUDING the terminating NUL.
218 * On exception, returns 0.
220 * If there is a limit on the length of a valid string, you may wish to
221 * consider using strnlen_user() instead.
223 #define strlen_user(str) strnlen_user(str, LONG_MAX)
225 long strnlen_user(const char __user *str, long n);
226 unsigned long __must_check clear_user(void __user *mem, unsigned long len);
227 unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
229 #endif /* __i386_UACCESS_H */