x86: Slightly tweak the access_ok() C variant for better code
[platform/adaptation/renesas_rcar/renesas_kernel.git] / arch / x86 / include / asm / uaccess.h
1 #ifndef _ASM_X86_UACCESS_H
2 #define _ASM_X86_UACCESS_H
3 /*
4  * User space memory access functions
5  */
6 #include <linux/errno.h>
7 #include <linux/compiler.h>
8 #include <linux/thread_info.h>
9 #include <linux/string.h>
10 #include <asm/asm.h>
11 #include <asm/page.h>
12 #include <asm/smap.h>
13
14 #define VERIFY_READ 0
15 #define VERIFY_WRITE 1
16
17 /*
18  * The fs value determines whether argument validity checking should be
19  * performed or not.  If get_fs() == USER_DS, checking is performed, with
20  * get_fs() == KERNEL_DS, checking is bypassed.
21  *
22  * For historical reasons, these macros are grossly misnamed.
23  */
24
25 #define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
26
27 #define KERNEL_DS       MAKE_MM_SEG(-1UL)
28 #define USER_DS         MAKE_MM_SEG(TASK_SIZE_MAX)
29
30 #define get_ds()        (KERNEL_DS)
31 #define get_fs()        (current_thread_info()->addr_limit)
32 #define set_fs(x)       (current_thread_info()->addr_limit = (x))
33
34 #define segment_eq(a, b)        ((a).seg == (b).seg)
35
36 #define user_addr_max() (current_thread_info()->addr_limit.seg)
37 #define __addr_ok(addr)         \
38         ((unsigned long __force)(addr) < user_addr_max())
39
40 /*
41  * Test whether a block of memory is a valid user space address.
42  * Returns 0 if the range is valid, nonzero otherwise.
43  */
44 static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, unsigned long limit)
45 {
46         /*
47          * If we have used "sizeof()" for the size,
48          * we know it won't overflow the limit (but
49          * it might overflow the 'addr', so it's
50          * important to subtract the size from the
51          * limit, not add it to the address).
52          */
53         if (__builtin_constant_p(size))
54                 return addr > limit - size;
55
56         /* Arbitrary sizes? Be careful about overflow */
57         addr += size;
58         if (addr < size)
59                 return true;
60         return addr > limit;
61 }
62
63 #define __range_not_ok(addr, size, limit)                               \
64 ({                                                                      \
65         __chk_user_ptr(addr);                                           \
66         __chk_range_not_ok((unsigned long __force)(addr), size, limit); \
67 })
68
69 /**
70  * access_ok: - Checks if a user space pointer is valid
71  * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE.  Note that
72  *        %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
73  *        to write to a block, it is always safe to read from it.
74  * @addr: User space pointer to start of block to check
75  * @size: Size of block to check
76  *
77  * Context: User context only.  This function may sleep.
78  *
79  * Checks if a pointer to a block of memory in user space is valid.
80  *
81  * Returns true (nonzero) if the memory block may be valid, false (zero)
82  * if it is definitely invalid.
83  *
84  * Note that, depending on architecture, this function probably just
85  * checks that the pointer is in the user space range - after calling
86  * this function, memory access functions may still return -EFAULT.
87  */
88 #define access_ok(type, addr, size) \
89         likely(!__range_not_ok(addr, size, user_addr_max()))
90
91 /*
92  * The exception table consists of pairs of addresses relative to the
93  * exception table enty itself: the first is the address of an
94  * instruction that is allowed to fault, and the second is the address
95  * at which the program should continue.  No registers are modified,
96  * so it is entirely up to the continuation code to figure out what to
97  * do.
98  *
99  * All the routines below use bits of fixup code that are out of line
100  * with the main instruction path.  This means when everything is well,
101  * we don't even have to jump over them.  Further, they do not intrude
102  * on our cache or tlb entries.
103  */
104
105 struct exception_table_entry {
106         int insn, fixup;
107 };
108 /* This is not the generic standard exception_table_entry format */
109 #define ARCH_HAS_SORT_EXTABLE
110 #define ARCH_HAS_SEARCH_EXTABLE
111
112 extern int fixup_exception(struct pt_regs *regs);
113 extern int early_fixup_exception(unsigned long *ip);
114
115 /*
116  * These are the main single-value transfer routines.  They automatically
117  * use the right size if we just have the right pointer type.
118  *
119  * This gets kind of ugly. We want to return _two_ values in "get_user()"
120  * and yet we don't want to do any pointers, because that is too much
121  * of a performance impact. Thus we have a few rather ugly macros here,
122  * and hide all the ugliness from the user.
123  *
124  * The "__xxx" versions of the user access functions are versions that
125  * do not verify the address space, that must have been done previously
126  * with a separate "access_ok()" call (this is used when we do multiple
127  * accesses to the same area of user memory).
128  */
129
130 extern int __get_user_1(void);
131 extern int __get_user_2(void);
132 extern int __get_user_4(void);
133 extern int __get_user_8(void);
134 extern int __get_user_bad(void);
135
136 /*
137  * This is a type: either unsigned long, if the argument fits into
138  * that type, or otherwise unsigned long long.
139  */
140 #define __inttype(x) \
141 __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
142
143 /**
144  * get_user: - Get a simple variable from user space.
145  * @x:   Variable to store result.
146  * @ptr: Source address, in user space.
147  *
148  * Context: User context only.  This function may sleep.
149  *
150  * This macro copies a single simple variable from user space to kernel
151  * space.  It supports simple types like char and int, but not larger
152  * data types like structures or arrays.
153  *
154  * @ptr must have pointer-to-simple-variable type, and the result of
155  * dereferencing @ptr must be assignable to @x without a cast.
156  *
157  * Returns zero on success, or -EFAULT on error.
158  * On error, the variable @x is set to zero.
159  */
160 /*
161  * Careful: we have to cast the result to the type of the pointer
162  * for sign reasons.
163  *
164  * The use of _ASM_DX as the register specifier is a bit of a
165  * simplification, as gcc only cares about it as the starting point
166  * and not size: for a 64-bit value it will use %ecx:%edx on 32 bits
167  * (%ecx being the next register in gcc's x86 register sequence), and
168  * %rdx on 64 bits.
169  *
170  * Clang/LLVM cares about the size of the register, but still wants
171  * the base register for something that ends up being a pair.
172  */
173 #define get_user(x, ptr)                                                \
174 ({                                                                      \
175         int __ret_gu;                                                   \
176         register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX);            \
177         __chk_user_ptr(ptr);                                            \
178         might_fault();                                                  \
179         asm volatile("call __get_user_%P3"                              \
180                      : "=a" (__ret_gu), "=r" (__val_gu)                 \
181                      : "0" (ptr), "i" (sizeof(*(ptr))));                \
182         (x) = (__typeof__(*(ptr))) __val_gu;                            \
183         __ret_gu;                                                       \
184 })
185
186 #define __put_user_x(size, x, ptr, __ret_pu)                    \
187         asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
188                      : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
189
190
191
192 #ifdef CONFIG_X86_32
193 #define __put_user_asm_u64(x, addr, err, errret)                        \
194         asm volatile(ASM_STAC "\n"                                      \
195                      "1:        movl %%eax,0(%2)\n"                     \
196                      "2:        movl %%edx,4(%2)\n"                     \
197                      "3: " ASM_CLAC "\n"                                \
198                      ".section .fixup,\"ax\"\n"                         \
199                      "4:        movl %3,%0\n"                           \
200                      "  jmp 3b\n"                                       \
201                      ".previous\n"                                      \
202                      _ASM_EXTABLE(1b, 4b)                               \
203                      _ASM_EXTABLE(2b, 4b)                               \
204                      : "=r" (err)                                       \
205                      : "A" (x), "r" (addr), "i" (errret), "0" (err))
206
207 #define __put_user_asm_ex_u64(x, addr)                                  \
208         asm volatile(ASM_STAC "\n"                                      \
209                      "1:        movl %%eax,0(%1)\n"                     \
210                      "2:        movl %%edx,4(%1)\n"                     \
211                      "3: " ASM_CLAC "\n"                                \
212                      _ASM_EXTABLE_EX(1b, 2b)                            \
213                      _ASM_EXTABLE_EX(2b, 3b)                            \
214                      : : "A" (x), "r" (addr))
215
216 #define __put_user_x8(x, ptr, __ret_pu)                         \
217         asm volatile("call __put_user_8" : "=a" (__ret_pu)      \
218                      : "A" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
219 #else
220 #define __put_user_asm_u64(x, ptr, retval, errret) \
221         __put_user_asm(x, ptr, retval, "q", "", "er", errret)
222 #define __put_user_asm_ex_u64(x, addr)  \
223         __put_user_asm_ex(x, addr, "q", "", "er")
224 #define __put_user_x8(x, ptr, __ret_pu) __put_user_x(8, x, ptr, __ret_pu)
225 #endif
226
227 extern void __put_user_bad(void);
228
229 /*
230  * Strange magic calling convention: pointer in %ecx,
231  * value in %eax(:%edx), return value in %eax. clobbers %rbx
232  */
233 extern void __put_user_1(void);
234 extern void __put_user_2(void);
235 extern void __put_user_4(void);
236 extern void __put_user_8(void);
237
238 /**
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);                                    \
259         might_fault();                                          \
260         __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
281 #define __put_user_size(x, ptr, size, retval, errret)                   \
282 do {                                                                    \
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:                                                         \
293                 __put_user_asm(x, ptr, retval, "l", "k", "ir", errret); \
294                 break;                                                  \
295         case 8:                                                         \
296                 __put_user_asm_u64((__typeof__(*ptr))(x), ptr, retval,  \
297                                    errret);                             \
298                 break;                                                  \
299         default:                                                        \
300                 __put_user_bad();                                       \
301         }                                                               \
302 } while (0)
303
304 #define __put_user_size_ex(x, ptr, size)                                \
305 do {                                                                    \
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
325 #ifdef CONFIG_X86_32
326 #define __get_user_asm_u64(x, ptr, retval, errret)      (x) = __get_user_bad()
327 #define __get_user_asm_ex_u64(x, ptr)                   (x) = __get_user_bad()
328 #else
329 #define __get_user_asm_u64(x, ptr, retval, errret) \
330          __get_user_asm(x, ptr, retval, "q", "", "=r", errret)
331 #define __get_user_asm_ex_u64(x, ptr) \
332          __get_user_asm_ex(x, ptr, "q", "", "=r")
333 #endif
334
335 #define __get_user_size(x, ptr, size, retval, errret)                   \
336 do {                                                                    \
337         retval = 0;                                                     \
338         __chk_user_ptr(ptr);                                            \
339         switch (size) {                                                 \
340         case 1:                                                         \
341                 __get_user_asm(x, ptr, retval, "b", "b", "=q", errret); \
342                 break;                                                  \
343         case 2:                                                         \
344                 __get_user_asm(x, ptr, retval, "w", "w", "=r", errret); \
345                 break;                                                  \
346         case 4:                                                         \
347                 __get_user_asm(x, ptr, retval, "l", "k", "=r", errret); \
348                 break;                                                  \
349         case 8:                                                         \
350                 __get_user_asm_u64(x, ptr, retval, errret);             \
351                 break;                                                  \
352         default:                                                        \
353                 (x) = __get_user_bad();                                 \
354         }                                                               \
355 } while (0)
356
357 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret)       \
358         asm volatile(ASM_STAC "\n"                                      \
359                      "1:        mov"itype" %2,%"rtype"1\n"              \
360                      "2: " ASM_CLAC "\n"                                \
361                      ".section .fixup,\"ax\"\n"                         \
362                      "3:        mov %3,%0\n"                            \
363                      "  xor"itype" %"rtype"1,%"rtype"1\n"               \
364                      "  jmp 2b\n"                                       \
365                      ".previous\n"                                      \
366                      _ASM_EXTABLE(1b, 3b)                               \
367                      : "=r" (err), ltype(x)                             \
368                      : "m" (__m(addr)), "i" (errret), "0" (err))
369
370 #define __get_user_size_ex(x, ptr, size)                                \
371 do {                                                                    \
372         __chk_user_ptr(ptr);                                            \
373         switch (size) {                                                 \
374         case 1:                                                         \
375                 __get_user_asm_ex(x, ptr, "b", "b", "=q");              \
376                 break;                                                  \
377         case 2:                                                         \
378                 __get_user_asm_ex(x, ptr, "w", "w", "=r");              \
379                 break;                                                  \
380         case 4:                                                         \
381                 __get_user_asm_ex(x, ptr, "l", "k", "=r");              \
382                 break;                                                  \
383         case 8:                                                         \
384                 __get_user_asm_ex_u64(x, ptr);                          \
385                 break;                                                  \
386         default:                                                        \
387                 (x) = __get_user_bad();                                 \
388         }                                                               \
389 } while (0)
390
391 #define __get_user_asm_ex(x, addr, itype, rtype, ltype)                 \
392         asm volatile("1:        mov"itype" %1,%"rtype"0\n"              \
393                      "2:\n"                                             \
394                      _ASM_EXTABLE_EX(1b, 2b)                            \
395                      : ltype(x) : "m" (__m(addr)))
396
397 #define __put_user_nocheck(x, ptr, size)                        \
398 ({                                                              \
399         int __pu_err;                                           \
400         __put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \
401         __pu_err;                                               \
402 })
403
404 #define __get_user_nocheck(x, ptr, size)                                \
405 ({                                                                      \
406         int __gu_err;                                                   \
407         unsigned long __gu_val;                                         \
408         __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT);    \
409         (x) = (__force __typeof__(*(ptr)))__gu_val;                     \
410         __gu_err;                                                       \
411 })
412
413 /* FIXME: this hack is definitely wrong -AK */
414 struct __large_struct { unsigned long buf[100]; };
415 #define __m(x) (*(struct __large_struct __user *)(x))
416
417 /*
418  * Tell gcc we read from memory instead of writing: this is because
419  * we do not write to any memory gcc knows about, so there are no
420  * aliasing issues.
421  */
422 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret)       \
423         asm volatile(ASM_STAC "\n"                                      \
424                      "1:        mov"itype" %"rtype"1,%2\n"              \
425                      "2: " ASM_CLAC "\n"                                \
426                      ".section .fixup,\"ax\"\n"                         \
427                      "3:        mov %3,%0\n"                            \
428                      "  jmp 2b\n"                                       \
429                      ".previous\n"                                      \
430                      _ASM_EXTABLE(1b, 3b)                               \
431                      : "=r"(err)                                        \
432                      : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
433
434 #define __put_user_asm_ex(x, addr, itype, rtype, ltype)                 \
435         asm volatile("1:        mov"itype" %"rtype"0,%1\n"              \
436                      "2:\n"                                             \
437                      _ASM_EXTABLE_EX(1b, 2b)                            \
438                      : : ltype(x), "m" (__m(addr)))
439
440 /*
441  * uaccess_try and catch
442  */
443 #define uaccess_try     do {                                            \
444         current_thread_info()->uaccess_err = 0;                         \
445         stac();                                                         \
446         barrier();
447
448 #define uaccess_catch(err)                                              \
449         clac();                                                         \
450         (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0);    \
451 } while (0)
452
453 /**
454  * __get_user: - Get a simple variable from user space, with less checking.
455  * @x:   Variable to store result.
456  * @ptr: Source address, in user space.
457  *
458  * Context: User context only.  This function may sleep.
459  *
460  * This macro copies a single simple variable from user space to kernel
461  * space.  It supports simple types like char and int, but not larger
462  * data types like structures or arrays.
463  *
464  * @ptr must have pointer-to-simple-variable type, and the result of
465  * dereferencing @ptr must be assignable to @x without a cast.
466  *
467  * Caller must check the pointer with access_ok() before calling this
468  * function.
469  *
470  * Returns zero on success, or -EFAULT on error.
471  * On error, the variable @x is set to zero.
472  */
473
474 #define __get_user(x, ptr)                                              \
475         __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
476
477 /**
478  * __put_user: - Write a simple value into user space, with less checking.
479  * @x:   Value to copy to user space.
480  * @ptr: Destination address, in user space.
481  *
482  * Context: User context only.  This function may sleep.
483  *
484  * This macro copies a single simple value from kernel space to user
485  * space.  It supports simple types like char and int, but not larger
486  * data types like structures or arrays.
487  *
488  * @ptr must have pointer-to-simple-variable type, and @x must be assignable
489  * to the result of dereferencing @ptr.
490  *
491  * Caller must check the pointer with access_ok() before calling this
492  * function.
493  *
494  * Returns zero on success, or -EFAULT on error.
495  */
496
497 #define __put_user(x, ptr)                                              \
498         __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
499
500 #define __get_user_unaligned __get_user
501 #define __put_user_unaligned __put_user
502
503 /*
504  * {get|put}_user_try and catch
505  *
506  * get_user_try {
507  *      get_user_ex(...);
508  * } get_user_catch(err)
509  */
510 #define get_user_try            uaccess_try
511 #define get_user_catch(err)     uaccess_catch(err)
512
513 #define get_user_ex(x, ptr)     do {                                    \
514         unsigned long __gue_val;                                        \
515         __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr))));       \
516         (x) = (__force __typeof__(*(ptr)))__gue_val;                    \
517 } while (0)
518
519 #define put_user_try            uaccess_try
520 #define put_user_catch(err)     uaccess_catch(err)
521
522 #define put_user_ex(x, ptr)                                             \
523         __put_user_size_ex((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
524
525 extern unsigned long
526 copy_from_user_nmi(void *to, const void __user *from, unsigned long n);
527 extern __must_check long
528 strncpy_from_user(char *dst, const char __user *src, long count);
529
530 extern __must_check long strlen_user(const char __user *str);
531 extern __must_check long strnlen_user(const char __user *str, long n);
532
533 unsigned long __must_check clear_user(void __user *mem, unsigned long len);
534 unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
535
536 /*
537  * movsl can be slow when source and dest are not both 8-byte aligned
538  */
539 #ifdef CONFIG_X86_INTEL_USERCOPY
540 extern struct movsl_mask {
541         int mask;
542 } ____cacheline_aligned_in_smp movsl_mask;
543 #endif
544
545 #define ARCH_HAS_NOCACHE_UACCESS 1
546
547 #ifdef CONFIG_X86_32
548 # include <asm/uaccess_32.h>
549 #else
550 # include <asm/uaccess_64.h>
551 #endif
552
553 unsigned long __must_check _copy_from_user(void *to, const void __user *from,
554                                            unsigned n);
555 unsigned long __must_check _copy_to_user(void __user *to, const void *from,
556                                          unsigned n);
557
558 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
559 # define copy_user_diag __compiletime_error
560 #else
561 # define copy_user_diag __compiletime_warning
562 #endif
563
564 extern void copy_user_diag("copy_from_user() buffer size is too small")
565 copy_from_user_overflow(void);
566 extern void copy_user_diag("copy_to_user() buffer size is too small")
567 copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
568
569 #undef copy_user_diag
570
571 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
572
573 extern void
574 __compiletime_warning("copy_from_user() buffer size is not provably correct")
575 __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
576 #define __copy_from_user_overflow(size, count) __copy_from_user_overflow()
577
578 extern void
579 __compiletime_warning("copy_to_user() buffer size is not provably correct")
580 __copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
581 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
582
583 #else
584
585 static inline void
586 __copy_from_user_overflow(int size, unsigned long count)
587 {
588         WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
589 }
590
591 #define __copy_to_user_overflow __copy_from_user_overflow
592
593 #endif
594
595 static inline unsigned long __must_check
596 copy_from_user(void *to, const void __user *from, unsigned long n)
597 {
598         int sz = __compiletime_object_size(to);
599
600         might_fault();
601
602         /*
603          * While we would like to have the compiler do the checking for us
604          * even in the non-constant size case, any false positives there are
605          * a problem (especially when DEBUG_STRICT_USER_COPY_CHECKS, but even
606          * without - the [hopefully] dangerous looking nature of the warning
607          * would make people go look at the respecitive call sites over and
608          * over again just to find that there's no problem).
609          *
610          * And there are cases where it's just not realistic for the compiler
611          * to prove the count to be in range. For example when multiple call
612          * sites of a helper function - perhaps in different source files -
613          * all doing proper range checking, yet the helper function not doing
614          * so again.
615          *
616          * Therefore limit the compile time checking to the constant size
617          * case, and do only runtime checking for non-constant sizes.
618          */
619
620         if (likely(sz < 0 || sz >= n))
621                 n = _copy_from_user(to, from, n);
622         else if(__builtin_constant_p(n))
623                 copy_from_user_overflow();
624         else
625                 __copy_from_user_overflow(sz, n);
626
627         return n;
628 }
629
630 static inline unsigned long __must_check
631 copy_to_user(void __user *to, const void *from, unsigned long n)
632 {
633         int sz = __compiletime_object_size(from);
634
635         might_fault();
636
637         /* See the comment in copy_from_user() above. */
638         if (likely(sz < 0 || sz >= n))
639                 n = _copy_to_user(to, from, n);
640         else if(__builtin_constant_p(n))
641                 copy_to_user_overflow();
642         else
643                 __copy_to_user_overflow(sz, n);
644
645         return n;
646 }
647
648 #undef __copy_from_user_overflow
649 #undef __copy_to_user_overflow
650
651 #endif /* _ASM_X86_UACCESS_H */
652