blob: 851fe0dc13bc18c33c79b8d54deb06e899ae63ad [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_UACCESS_H
2#define _ASM_X86_UACCESS_H
Glauber Costaca233862008-06-13 14:39:25 -03003/*
4 * User space memory access functions
5 */
6#include <linux/errno.h>
7#include <linux/compiler.h>
8#include <linux/thread_info.h>
Glauber Costaca233862008-06-13 14:39:25 -03009#include <linux/string.h>
10#include <asm/asm.h>
11#include <asm/page.h>
12
13#define VERIFY_READ 0
14#define VERIFY_WRITE 1
15
16/*
17 * The fs value determines whether argument validity checking should be
18 * performed or not. If get_fs() == USER_DS, checking is performed, with
19 * get_fs() == KERNEL_DS, checking is bypassed.
20 *
21 * For historical reasons, these macros are grossly misnamed.
22 */
23
24#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
25
26#define KERNEL_DS MAKE_MM_SEG(-1UL)
Linus Torvalds9063c612009-06-20 15:40:00 -070027#define USER_DS MAKE_MM_SEG(TASK_SIZE_MAX)
Glauber Costaca233862008-06-13 14:39:25 -030028
29#define get_ds() (KERNEL_DS)
30#define get_fs() (current_thread_info()->addr_limit)
31#define set_fs(x) (current_thread_info()->addr_limit = (x))
32
33#define segment_eq(a, b) ((a).seg == (b).seg)
34
Glauber Costa002ca162008-06-25 11:08:51 -030035#define __addr_ok(addr) \
36 ((unsigned long __force)(addr) < \
37 (current_thread_info()->addr_limit.seg))
38
Glauber Costaca233862008-06-13 14:39:25 -030039/*
40 * Test whether a block of memory is a valid user space address.
41 * Returns 0 if the range is valid, nonzero otherwise.
42 *
43 * This is equivalent to the following test:
Jiri Olsa26afb7c2011-05-12 16:30:30 +020044 * (u33)addr + (u33)size > (u33)current->addr_limit.seg (u65 for x86_64)
Glauber Costaca233862008-06-13 14:39:25 -030045 *
46 * This needs 33-bit (65-bit for x86_64) arithmetic. We have a carry...
47 */
48
49#define __range_not_ok(addr, size) \
50({ \
51 unsigned long flag, roksum; \
52 __chk_user_ptr(addr); \
53 asm("add %3,%1 ; sbb %0,%0 ; cmp %1,%4 ; sbb $0,%0" \
54 : "=&r" (flag), "=r" (roksum) \
55 : "1" (addr), "g" ((long)(size)), \
56 "rm" (current_thread_info()->addr_limit.seg)); \
57 flag; \
58})
59
60/**
61 * access_ok: - Checks if a user space pointer is valid
62 * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that
63 * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
64 * to write to a block, it is always safe to read from it.
65 * @addr: User space pointer to start of block to check
66 * @size: Size of block to check
67 *
68 * Context: User context only. This function may sleep.
69 *
70 * Checks if a pointer to a block of memory in user space is valid.
71 *
72 * Returns true (nonzero) if the memory block may be valid, false (zero)
73 * if it is definitely invalid.
74 *
75 * Note that, depending on architecture, this function probably just
76 * checks that the pointer is in the user space range - after calling
77 * this function, memory access functions may still return -EFAULT.
78 */
79#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
80
81/*
H. Peter Anvin70627652012-04-20 17:12:48 -070082 * The exception table consists of pairs of addresses relative to the
83 * exception table enty itself: the first is the address of an
84 * instruction that is allowed to fault, and the second is the address
85 * at which the program should continue. No registers are modified,
86 * so it is entirely up to the continuation code to figure out what to
87 * do.
Glauber Costaca233862008-06-13 14:39:25 -030088 *
89 * All the routines below use bits of fixup code that are out of line
90 * with the main instruction path. This means when everything is well,
91 * we don't even have to jump over them. Further, they do not intrude
92 * on our cache or tlb entries.
93 */
94
95struct exception_table_entry {
H. Peter Anvin70627652012-04-20 17:12:48 -070096 int insn, fixup;
Glauber Costaca233862008-06-13 14:39:25 -030097};
H. Peter Anvin70627652012-04-20 17:12:48 -070098/* This is not the generic standard exception_table_entry format */
99#define ARCH_HAS_SORT_EXTABLE
100#define ARCH_HAS_SEARCH_EXTABLE
Glauber Costaca233862008-06-13 14:39:25 -0300101
102extern int fixup_exception(struct pt_regs *regs);
H. Peter Anvin70627652012-04-20 17:12:48 -0700103extern int early_fixup_exception(unsigned long *ip);
Glauber Costaca233862008-06-13 14:39:25 -0300104
105/*
106 * These are the main single-value transfer routines. They automatically
107 * use the right size if we just have the right pointer type.
108 *
109 * This gets kind of ugly. We want to return _two_ values in "get_user()"
110 * and yet we don't want to do any pointers, because that is too much
111 * of a performance impact. Thus we have a few rather ugly macros here,
112 * and hide all the ugliness from the user.
113 *
114 * The "__xxx" versions of the user access functions are versions that
115 * do not verify the address space, that must have been done previously
116 * with a separate "access_ok()" call (this is used when we do multiple
117 * accesses to the same area of user memory).
118 */
119
120extern int __get_user_1(void);
121extern int __get_user_2(void);
122extern int __get_user_4(void);
123extern int __get_user_8(void);
124extern int __get_user_bad(void);
125
126#define __get_user_x(size, ret, x, ptr) \
127 asm volatile("call __get_user_" #size \
Hiroshi Shimamoto4d5d7832009-01-19 16:34:26 -0800128 : "=a" (ret), "=d" (x) \
Glauber Costaca233862008-06-13 14:39:25 -0300129 : "0" (ptr)) \
130
Glauber Costa865e5b72008-06-25 11:05:11 -0300131/* Careful: we have to cast the result to the type of the pointer
132 * for sign reasons */
133
134/**
135 * get_user: - Get a simple variable from user space.
136 * @x: Variable to store result.
137 * @ptr: Source address, in user space.
138 *
139 * Context: User context only. This function may sleep.
140 *
141 * This macro copies a single simple variable from user space to kernel
142 * space. It supports simple types like char and int, but not larger
143 * data types like structures or arrays.
144 *
145 * @ptr must have pointer-to-simple-variable type, and the result of
146 * dereferencing @ptr must be assignable to @x without a cast.
147 *
148 * Returns zero on success, or -EFAULT on error.
149 * On error, the variable @x is set to zero.
150 */
151#ifdef CONFIG_X86_32
152#define __get_user_8(__ret_gu, __val_gu, ptr) \
153 __get_user_x(X, __ret_gu, __val_gu, ptr)
154#else
155#define __get_user_8(__ret_gu, __val_gu, ptr) \
156 __get_user_x(8, __ret_gu, __val_gu, ptr)
157#endif
158
159#define get_user(x, ptr) \
160({ \
161 int __ret_gu; \
162 unsigned long __val_gu; \
163 __chk_user_ptr(ptr); \
Ingo Molnard1a76182008-10-28 16:54:49 +0100164 might_fault(); \
Glauber Costa865e5b72008-06-25 11:05:11 -0300165 switch (sizeof(*(ptr))) { \
166 case 1: \
167 __get_user_x(1, __ret_gu, __val_gu, ptr); \
168 break; \
169 case 2: \
170 __get_user_x(2, __ret_gu, __val_gu, ptr); \
171 break; \
172 case 4: \
173 __get_user_x(4, __ret_gu, __val_gu, ptr); \
174 break; \
175 case 8: \
176 __get_user_8(__ret_gu, __val_gu, ptr); \
177 break; \
178 default: \
179 __get_user_x(X, __ret_gu, __val_gu, ptr); \
180 break; \
181 } \
182 (x) = (__typeof__(*(ptr)))__val_gu; \
183 __ret_gu; \
184})
185
Glauber Costae30a44f2008-06-25 13:17:43 -0300186#define __put_user_x(size, x, ptr, __ret_pu) \
187 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
Hiroshi Shimamoto4d5d7832009-01-19 16:34:26 -0800188 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
Glauber Costae30a44f2008-06-25 13:17:43 -0300189
190
191
Glauber Costadc70ddf2008-06-25 11:48:29 -0300192#ifdef CONFIG_X86_32
Hiroshi Shimamoto18114f62009-01-30 18:16:46 -0800193#define __put_user_asm_u64(x, addr, err, errret) \
Glauber Costadc70ddf2008-06-25 11:48:29 -0300194 asm volatile("1: movl %%eax,0(%2)\n" \
195 "2: movl %%edx,4(%2)\n" \
196 "3:\n" \
197 ".section .fixup,\"ax\"\n" \
198 "4: movl %3,%0\n" \
199 " jmp 3b\n" \
200 ".previous\n" \
201 _ASM_EXTABLE(1b, 4b) \
202 _ASM_EXTABLE(2b, 4b) \
203 : "=r" (err) \
Hiroshi Shimamoto18114f62009-01-30 18:16:46 -0800204 : "A" (x), "r" (addr), "i" (errret), "0" (err))
Glauber Costae30a44f2008-06-25 13:17:43 -0300205
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800206#define __put_user_asm_ex_u64(x, addr) \
207 asm volatile("1: movl %%eax,0(%1)\n" \
208 "2: movl %%edx,4(%1)\n" \
209 "3:\n" \
H. Peter Anvin535c0c32012-04-20 16:57:35 -0700210 _ASM_EXTABLE_EX(1b, 2b) \
211 _ASM_EXTABLE_EX(2b, 3b) \
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800212 : : "A" (x), "r" (addr))
213
Glauber Costae30a44f2008-06-25 13:17:43 -0300214#define __put_user_x8(x, ptr, __ret_pu) \
215 asm volatile("call __put_user_8" : "=a" (__ret_pu) \
216 : "A" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
Glauber Costadc70ddf2008-06-25 11:48:29 -0300217#else
Hiroshi Shimamoto18114f62009-01-30 18:16:46 -0800218#define __put_user_asm_u64(x, ptr, retval, errret) \
H. Peter Anvinebe119c2009-07-20 23:27:39 -0700219 __put_user_asm(x, ptr, retval, "q", "", "er", errret)
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800220#define __put_user_asm_ex_u64(x, addr) \
H. Peter Anvinebe119c2009-07-20 23:27:39 -0700221 __put_user_asm_ex(x, addr, "q", "", "er")
Glauber Costae30a44f2008-06-25 13:17:43 -0300222#define __put_user_x8(x, ptr, __ret_pu) __put_user_x(8, x, ptr, __ret_pu)
Glauber Costadc70ddf2008-06-25 11:48:29 -0300223#endif
224
Glauber Costae30a44f2008-06-25 13:17:43 -0300225extern void __put_user_bad(void);
226
227/*
228 * Strange magic calling convention: pointer in %ecx,
229 * value in %eax(:%edx), return value in %eax. clobbers %rbx
230 */
231extern void __put_user_1(void);
232extern void __put_user_2(void);
233extern void __put_user_4(void);
234extern void __put_user_8(void);
235
Glauber Costadc70ddf2008-06-25 11:48:29 -0300236#ifdef CONFIG_X86_WP_WORKS_OK
237
Glauber Costae30a44f2008-06-25 13:17:43 -0300238/**
239 * put_user: - Write a simple value into user space.
240 * @x: Value to copy to user space.
241 * @ptr: Destination address, in user space.
242 *
243 * Context: User context only. This function may sleep.
244 *
245 * This macro copies a single simple value from kernel space to user
246 * space. It supports simple types like char and int, but not larger
247 * data types like structures or arrays.
248 *
249 * @ptr must have pointer-to-simple-variable type, and @x must be assignable
250 * to the result of dereferencing @ptr.
251 *
252 * Returns zero on success, or -EFAULT on error.
253 */
254#define put_user(x, ptr) \
255({ \
256 int __ret_pu; \
257 __typeof__(*(ptr)) __pu_val; \
258 __chk_user_ptr(ptr); \
Ingo Molnard1a76182008-10-28 16:54:49 +0100259 might_fault(); \
Glauber Costae30a44f2008-06-25 13:17:43 -0300260 __pu_val = x; \
261 switch (sizeof(*(ptr))) { \
262 case 1: \
263 __put_user_x(1, __pu_val, ptr, __ret_pu); \
264 break; \
265 case 2: \
266 __put_user_x(2, __pu_val, ptr, __ret_pu); \
267 break; \
268 case 4: \
269 __put_user_x(4, __pu_val, ptr, __ret_pu); \
270 break; \
271 case 8: \
272 __put_user_x8(__pu_val, ptr, __ret_pu); \
273 break; \
274 default: \
275 __put_user_x(X, __pu_val, ptr, __ret_pu); \
276 break; \
277 } \
278 __ret_pu; \
279})
280
Glauber Costadc70ddf2008-06-25 11:48:29 -0300281#define __put_user_size(x, ptr, size, retval, errret) \
282do { \
283 retval = 0; \
284 __chk_user_ptr(ptr); \
285 switch (size) { \
286 case 1: \
287 __put_user_asm(x, ptr, retval, "b", "b", "iq", errret); \
288 break; \
289 case 2: \
290 __put_user_asm(x, ptr, retval, "w", "w", "ir", errret); \
291 break; \
292 case 4: \
Hiroshi Shimamoto4d5d7832009-01-19 16:34:26 -0800293 __put_user_asm(x, ptr, retval, "l", "k", "ir", errret); \
Glauber Costadc70ddf2008-06-25 11:48:29 -0300294 break; \
295 case 8: \
Hiroshi Shimamoto18114f62009-01-30 18:16:46 -0800296 __put_user_asm_u64((__typeof__(*ptr))(x), ptr, retval, \
297 errret); \
Glauber Costadc70ddf2008-06-25 11:48:29 -0300298 break; \
299 default: \
300 __put_user_bad(); \
301 } \
302} while (0)
303
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800304#define __put_user_size_ex(x, ptr, size) \
305do { \
306 __chk_user_ptr(ptr); \
307 switch (size) { \
308 case 1: \
309 __put_user_asm_ex(x, ptr, "b", "b", "iq"); \
310 break; \
311 case 2: \
312 __put_user_asm_ex(x, ptr, "w", "w", "ir"); \
313 break; \
314 case 4: \
315 __put_user_asm_ex(x, ptr, "l", "k", "ir"); \
316 break; \
317 case 8: \
318 __put_user_asm_ex_u64((__typeof__(*ptr))(x), ptr); \
319 break; \
320 default: \
321 __put_user_bad(); \
322 } \
323} while (0)
324
Glauber Costadc70ddf2008-06-25 11:48:29 -0300325#else
326
327#define __put_user_size(x, ptr, size, retval, errret) \
328do { \
329 __typeof__(*(ptr))__pus_tmp = x; \
330 retval = 0; \
331 \
332 if (unlikely(__copy_to_user_ll(ptr, &__pus_tmp, size) != 0)) \
333 retval = errret; \
334} while (0)
335
Glauber Costae30a44f2008-06-25 13:17:43 -0300336#define put_user(x, ptr) \
337({ \
338 int __ret_pu; \
339 __typeof__(*(ptr))__pus_tmp = x; \
340 __ret_pu = 0; \
341 if (unlikely(__copy_to_user_ll(ptr, &__pus_tmp, \
342 sizeof(*(ptr))) != 0)) \
343 __ret_pu = -EFAULT; \
344 __ret_pu; \
345})
Glauber Costadc70ddf2008-06-25 11:48:29 -0300346#endif
347
Glauber Costa3f168222008-06-25 12:48:47 -0300348#ifdef CONFIG_X86_32
349#define __get_user_asm_u64(x, ptr, retval, errret) (x) = __get_user_bad()
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800350#define __get_user_asm_ex_u64(x, ptr) (x) = __get_user_bad()
Glauber Costa3f168222008-06-25 12:48:47 -0300351#else
352#define __get_user_asm_u64(x, ptr, retval, errret) \
353 __get_user_asm(x, ptr, retval, "q", "", "=r", errret)
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800354#define __get_user_asm_ex_u64(x, ptr) \
355 __get_user_asm_ex(x, ptr, "q", "", "=r")
Glauber Costa3f168222008-06-25 12:48:47 -0300356#endif
357
358#define __get_user_size(x, ptr, size, retval, errret) \
359do { \
360 retval = 0; \
361 __chk_user_ptr(ptr); \
362 switch (size) { \
363 case 1: \
364 __get_user_asm(x, ptr, retval, "b", "b", "=q", errret); \
365 break; \
366 case 2: \
367 __get_user_asm(x, ptr, retval, "w", "w", "=r", errret); \
368 break; \
369 case 4: \
370 __get_user_asm(x, ptr, retval, "l", "k", "=r", errret); \
371 break; \
372 case 8: \
373 __get_user_asm_u64(x, ptr, retval, errret); \
374 break; \
375 default: \
376 (x) = __get_user_bad(); \
377 } \
378} while (0)
379
380#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
381 asm volatile("1: mov"itype" %2,%"rtype"1\n" \
382 "2:\n" \
383 ".section .fixup,\"ax\"\n" \
384 "3: mov %3,%0\n" \
385 " xor"itype" %"rtype"1,%"rtype"1\n" \
386 " jmp 2b\n" \
387 ".previous\n" \
388 _ASM_EXTABLE(1b, 3b) \
389 : "=r" (err), ltype(x) \
390 : "m" (__m(addr)), "i" (errret), "0" (err))
391
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800392#define __get_user_size_ex(x, ptr, size) \
393do { \
394 __chk_user_ptr(ptr); \
395 switch (size) { \
396 case 1: \
397 __get_user_asm_ex(x, ptr, "b", "b", "=q"); \
398 break; \
399 case 2: \
400 __get_user_asm_ex(x, ptr, "w", "w", "=r"); \
401 break; \
402 case 4: \
403 __get_user_asm_ex(x, ptr, "l", "k", "=r"); \
404 break; \
405 case 8: \
406 __get_user_asm_ex_u64(x, ptr); \
407 break; \
408 default: \
409 (x) = __get_user_bad(); \
410 } \
411} while (0)
412
413#define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
414 asm volatile("1: mov"itype" %1,%"rtype"0\n" \
415 "2:\n" \
H. Peter Anvin535c0c32012-04-20 16:57:35 -0700416 _ASM_EXTABLE_EX(1b, 2b) \
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800417 : ltype(x) : "m" (__m(addr)))
418
Glauber Costadc70ddf2008-06-25 11:48:29 -0300419#define __put_user_nocheck(x, ptr, size) \
420({ \
Hiroshi Shimamoto16855f82008-12-08 19:18:38 -0800421 int __pu_err; \
Glauber Costadc70ddf2008-06-25 11:48:29 -0300422 __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \
423 __pu_err; \
424})
425
Glauber Costa3f168222008-06-25 12:48:47 -0300426#define __get_user_nocheck(x, ptr, size) \
427({ \
Hiroshi Shimamoto16855f82008-12-08 19:18:38 -0800428 int __gu_err; \
Glauber Costa3f168222008-06-25 12:48:47 -0300429 unsigned long __gu_val; \
430 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
431 (x) = (__force __typeof__(*(ptr)))__gu_val; \
432 __gu_err; \
433})
Glauber Costadc70ddf2008-06-25 11:48:29 -0300434
435/* FIXME: this hack is definitely wrong -AK */
436struct __large_struct { unsigned long buf[100]; };
437#define __m(x) (*(struct __large_struct __user *)(x))
438
439/*
440 * Tell gcc we read from memory instead of writing: this is because
441 * we do not write to any memory gcc knows about, so there are no
442 * aliasing issues.
443 */
444#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
445 asm volatile("1: mov"itype" %"rtype"1,%2\n" \
446 "2:\n" \
447 ".section .fixup,\"ax\"\n" \
448 "3: mov %3,%0\n" \
449 " jmp 2b\n" \
450 ".previous\n" \
451 _ASM_EXTABLE(1b, 3b) \
452 : "=r"(err) \
453 : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800454
455#define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
456 asm volatile("1: mov"itype" %"rtype"0,%1\n" \
457 "2:\n" \
H. Peter Anvin535c0c32012-04-20 16:57:35 -0700458 _ASM_EXTABLE_EX(1b, 2b) \
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800459 : : ltype(x), "m" (__m(addr)))
460
461/*
462 * uaccess_try and catch
463 */
464#define uaccess_try do { \
465 int prev_err = current_thread_info()->uaccess_err; \
466 current_thread_info()->uaccess_err = 0; \
467 barrier();
468
469#define uaccess_catch(err) \
Andy Lutomirski4fc34902011-11-07 16:33:40 -0800470 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800471 current_thread_info()->uaccess_err = prev_err; \
472} while (0)
473
Glauber Costa8cb834e2008-06-25 14:43:30 -0300474/**
475 * __get_user: - Get a simple variable from user space, with less checking.
476 * @x: Variable to store result.
477 * @ptr: Source address, in user space.
478 *
479 * Context: User context only. This function may sleep.
480 *
481 * This macro copies a single simple variable from user space to kernel
482 * space. It supports simple types like char and int, but not larger
483 * data types like structures or arrays.
484 *
485 * @ptr must have pointer-to-simple-variable type, and the result of
486 * dereferencing @ptr must be assignable to @x without a cast.
487 *
488 * Caller must check the pointer with access_ok() before calling this
489 * function.
490 *
491 * Returns zero on success, or -EFAULT on error.
492 * On error, the variable @x is set to zero.
493 */
Glauber Costadc70ddf2008-06-25 11:48:29 -0300494
Glauber Costa8cb834e2008-06-25 14:43:30 -0300495#define __get_user(x, ptr) \
496 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800497
Glauber Costa8cb834e2008-06-25 14:43:30 -0300498/**
499 * __put_user: - Write a simple value into user space, with less checking.
500 * @x: Value to copy to user space.
501 * @ptr: Destination address, in user space.
502 *
503 * Context: User context only. This function may sleep.
504 *
505 * This macro copies a single simple value from kernel space to user
506 * space. It supports simple types like char and int, but not larger
507 * data types like structures or arrays.
508 *
509 * @ptr must have pointer-to-simple-variable type, and @x must be assignable
510 * to the result of dereferencing @ptr.
511 *
512 * Caller must check the pointer with access_ok() before calling this
513 * function.
514 *
515 * Returns zero on success, or -EFAULT on error.
516 */
517
518#define __put_user(x, ptr) \
519 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
520
521#define __get_user_unaligned __get_user
522#define __put_user_unaligned __put_user
Glauber Costa865e5b72008-06-25 11:05:11 -0300523
Glauber Costa8bc7de0c2008-06-25 14:53:41 -0300524/*
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800525 * {get|put}_user_try and catch
526 *
527 * get_user_try {
528 * get_user_ex(...);
529 * } get_user_catch(err)
530 */
531#define get_user_try uaccess_try
532#define get_user_catch(err) uaccess_catch(err)
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800533
534#define get_user_ex(x, ptr) do { \
535 unsigned long __gue_val; \
536 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
537 (x) = (__force __typeof__(*(ptr)))__gue_val; \
538} while (0)
539
Hiroshi Shimamoto019a1362009-01-29 11:49:18 -0800540#ifdef CONFIG_X86_WP_WORKS_OK
541
542#define put_user_try uaccess_try
543#define put_user_catch(err) uaccess_catch(err)
544
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800545#define put_user_ex(x, ptr) \
546 __put_user_size_ex((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
547
Hiroshi Shimamoto019a1362009-01-29 11:49:18 -0800548#else /* !CONFIG_X86_WP_WORKS_OK */
549
550#define put_user_try do { \
551 int __uaccess_err = 0;
552
553#define put_user_catch(err) \
554 (err) |= __uaccess_err; \
555} while (0)
556
557#define put_user_ex(x, ptr) do { \
558 __uaccess_err |= __put_user(x, ptr); \
559} while (0)
560
561#endif /* CONFIG_X86_WP_WORKS_OK */
562
Robert Richter1ac2e6c2011-06-07 11:49:55 +0200563extern unsigned long
564copy_from_user_nmi(void *to, const void __user *from, unsigned long n);
Linus Torvalds92ae03f2012-04-06 14:32:32 -0700565extern __must_check long
566strncpy_from_user(char *dst, const char __user *src, long count);
Robert Richter1ac2e6c2011-06-07 11:49:55 +0200567
Hiroshi Shimamotofe40c0a2009-01-23 15:49:41 -0800568/*
Glauber Costa8bc7de0c2008-06-25 14:53:41 -0300569 * movsl can be slow when source and dest are not both 8-byte aligned
570 */
571#ifdef CONFIG_X86_INTEL_USERCOPY
572extern struct movsl_mask {
573 int mask;
574} ____cacheline_aligned_in_smp movsl_mask;
575#endif
576
Glauber Costa22cac162008-06-25 14:56:53 -0300577#define ARCH_HAS_NOCACHE_UACCESS 1
578
Thomas Gleixner96a388d2007-10-11 11:20:03 +0200579#ifdef CONFIG_X86_32
580# include "uaccess_32.h"
581#else
582# include "uaccess_64.h"
583#endif
Glauber Costaca233862008-06-13 14:39:25 -0300584
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700585#endif /* _ASM_X86_UACCESS_H */
Nick Piggin8174c432008-07-25 19:45:24 -0700586