ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / i386 / lib / usercopy.c
1 /* 
2  * User address space access functions.
3  * The non inlined parts of asm-i386/uaccess.h are here.
4  *
5  * Copyright 1997 Andi Kleen <ak@muc.de>
6  * Copyright 1997 Linus Torvalds
7  */
8 #include <linux/config.h>
9 #include <linux/mm.h>
10 #include <linux/highmem.h>
11 #include <linux/blkdev.h>
12 #include <linux/module.h>
13 #include <asm/uaccess.h>
14 #include <asm/mmx.h>
15
16 static inline int __movsl_is_ok(unsigned long a1, unsigned long a2, unsigned long n)
17 {
18 #ifdef CONFIG_X86_INTEL_USERCOPY
19         if (n >= 64 && ((a1 ^ a2) & movsl_mask.mask))
20                 return 0;
21 #endif
22         return 1;
23 }
24 #define movsl_is_ok(a1,a2,n) \
25         __movsl_is_ok((unsigned long)(a1),(unsigned long)(a2),(n))
26
27 /*
28  * Copy a null terminated string from userspace.
29  */
30
31 #define __do_strncpy_from_user(dst,src,count,res)                          \
32 do {                                                                       \
33         int __d0, __d1, __d2;                                              \
34         __asm__ __volatile__(                                              \
35                 "       testl %1,%1\n"                                     \
36                 "       jz 2f\n"                                           \
37                 "0:     lodsb\n"                                           \
38                 "       stosb\n"                                           \
39                 "       testb %%al,%%al\n"                                 \
40                 "       jz 1f\n"                                           \
41                 "       decl %1\n"                                         \
42                 "       jnz 0b\n"                                          \
43                 "1:     subl %1,%0\n"                                      \
44                 "2:\n"                                                     \
45                 ".section .fixup,\"ax\"\n"                                 \
46                 "3:     movl %5,%0\n"                                      \
47                 "       jmp 2b\n"                                          \
48                 ".previous\n"                                              \
49                 ".section __ex_table,\"a\"\n"                              \
50                 "       .align 4\n"                                        \
51                 "       .long 0b,3b\n"                                     \
52                 ".previous"                                                \
53                 : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),      \
54                   "=&D" (__d2)                                             \
55                 : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
56                 : "memory");                                               \
57 } while (0)
58
59 /**
60  * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
61  * @dst:   Destination address, in kernel space.  This buffer must be at
62  *         least @count bytes long.
63  * @src:   Source address, in user space.
64  * @count: Maximum number of bytes to copy, including the trailing NUL.
65  * 
66  * Copies a NUL-terminated string from userspace to kernel space.
67  * Caller must check the specified block with access_ok() before calling
68  * this function.
69  *
70  * On success, returns the length of the string (not including the trailing
71  * NUL).
72  *
73  * If access to userspace fails, returns -EFAULT (some data may have been
74  * copied).
75  *
76  * If @count is smaller than the length of the string, copies @count bytes
77  * and returns @count.
78  */
79 long
80 __strncpy_from_user(char *dst, const char __user *src, long count)
81 {
82         long res;
83         __do_strncpy_from_user(dst, src, count, res);
84         return res;
85 }
86
87 /**
88  * strncpy_from_user: - Copy a NUL terminated string from userspace.
89  * @dst:   Destination address, in kernel space.  This buffer must be at
90  *         least @count bytes long.
91  * @src:   Source address, in user space.
92  * @count: Maximum number of bytes to copy, including the trailing NUL.
93  * 
94  * Copies a NUL-terminated string from userspace to kernel space.
95  *
96  * On success, returns the length of the string (not including the trailing
97  * NUL).
98  *
99  * If access to userspace fails, returns -EFAULT (some data may have been
100  * copied).
101  *
102  * If @count is smaller than the length of the string, copies @count bytes
103  * and returns @count.
104  */
105 long
106 strncpy_from_user(char *dst, const char __user *src, long count)
107 {
108         long res = -EFAULT;
109         if (access_ok(VERIFY_READ, src, 1))
110                 __do_strncpy_from_user(dst, src, count, res);
111         return res;
112 }
113
114
115 /*
116  * Zero Userspace
117  */
118
119 #define __do_clear_user(addr,size)                                      \
120 do {                                                                    \
121         int __d0;                                                       \
122         __asm__ __volatile__(                                           \
123                 "0:     rep; stosl\n"                                   \
124                 "       movl %2,%0\n"                                   \
125                 "1:     rep; stosb\n"                                   \
126                 "2:\n"                                                  \
127                 ".section .fixup,\"ax\"\n"                              \
128                 "3:     lea 0(%2,%0,4),%0\n"                            \
129                 "       jmp 2b\n"                                       \
130                 ".previous\n"                                           \
131                 ".section __ex_table,\"a\"\n"                           \
132                 "       .align 4\n"                                     \
133                 "       .long 0b,3b\n"                                  \
134                 "       .long 1b,2b\n"                                  \
135                 ".previous"                                             \
136                 : "=&c"(size), "=&D" (__d0)                             \
137                 : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0));     \
138 } while (0)
139
140 /**
141  * clear_user: - Zero a block of memory in user space.
142  * @to:   Destination address, in user space.
143  * @n:    Number of bytes to zero.
144  *
145  * Zero a block of memory in user space.
146  *
147  * Returns number of bytes that could not be cleared.
148  * On success, this will be zero.
149  */
150 unsigned long
151 clear_user(void __user *to, unsigned long n)
152 {
153         might_sleep();
154         if (access_ok(VERIFY_WRITE, to, n))
155                 __do_clear_user(to, n);
156         return n;
157 }
158
159 /**
160  * __clear_user: - Zero a block of memory in user space, with less checking.
161  * @to:   Destination address, in user space.
162  * @n:    Number of bytes to zero.
163  *
164  * Zero a block of memory in user space.  Caller must check
165  * the specified block with access_ok() before calling this function.
166  *
167  * Returns number of bytes that could not be cleared.
168  * On success, this will be zero.
169  */
170 unsigned long
171 __clear_user(void __user *to, unsigned long n)
172 {
173         __do_clear_user(to, n);
174         return n;
175 }
176
177 /**
178  * strlen_user: - Get the size of a string in user space.
179  * @s: The string to measure.
180  * @n: The maximum valid length
181  *
182  * Get the size of a NUL-terminated string in user space.
183  *
184  * Returns the size of the string INCLUDING the terminating NUL.
185  * On exception, returns 0.
186  * If the string is too long, returns a value greater than @n.
187  */
188 long strnlen_user(const char __user *s, long n)
189 {
190         unsigned long mask = -__addr_ok(s);
191         unsigned long res, tmp;
192
193         might_sleep();
194
195         __asm__ __volatile__(
196                 "       testl %0, %0\n"
197                 "       jz 3f\n"
198                 "       andl %0,%%ecx\n"
199                 "0:     repne; scasb\n"
200                 "       setne %%al\n"
201                 "       subl %%ecx,%0\n"
202                 "       addl %0,%%eax\n"
203                 "1:\n"
204                 ".section .fixup,\"ax\"\n"
205                 "2:     xorl %%eax,%%eax\n"
206                 "       jmp 1b\n"
207                 "3:     movb $1,%%al\n"
208                 "       jmp 1b\n"
209                 ".previous\n"
210                 ".section __ex_table,\"a\"\n"
211                 "       .align 4\n"
212                 "       .long 0b,2b\n"
213                 ".previous"
214                 :"=r" (n), "=D" (s), "=a" (res), "=c" (tmp)
215                 :"0" (n), "1" (s), "2" (0), "3" (mask)
216                 :"cc");
217         return res & mask;
218 }
219
220 #ifdef CONFIG_X86_INTEL_USERCOPY
221 static unsigned long
222 __copy_user_intel(void *to, const void *from,unsigned long size)
223 {
224         int d0, d1;
225         __asm__ __volatile__(
226                        "       .align 2,0x90\n"
227                        "1:     movl 32(%4), %%eax\n"
228                        "       cmpl $67, %0\n"
229                        "       jbe 3f\n"
230                        "2:     movl 64(%4), %%eax\n"
231                        "       .align 2,0x90\n"
232                        "3:     movl 0(%4), %%eax\n"
233                        "4:     movl 4(%4), %%edx\n"
234                        "5:     movl %%eax, 0(%3)\n"
235                        "6:     movl %%edx, 4(%3)\n"
236                        "7:     movl 8(%4), %%eax\n"
237                        "8:     movl 12(%4),%%edx\n"
238                        "9:     movl %%eax, 8(%3)\n"
239                        "10:    movl %%edx, 12(%3)\n"
240                        "11:    movl 16(%4), %%eax\n"
241                        "12:    movl 20(%4), %%edx\n"
242                        "13:    movl %%eax, 16(%3)\n"
243                        "14:    movl %%edx, 20(%3)\n"
244                        "15:    movl 24(%4), %%eax\n"
245                        "16:    movl 28(%4), %%edx\n"
246                        "17:    movl %%eax, 24(%3)\n"
247                        "18:    movl %%edx, 28(%3)\n"
248                        "19:    movl 32(%4), %%eax\n"
249                        "20:    movl 36(%4), %%edx\n"
250                        "21:    movl %%eax, 32(%3)\n"
251                        "22:    movl %%edx, 36(%3)\n"
252                        "23:    movl 40(%4), %%eax\n"
253                        "24:    movl 44(%4), %%edx\n"
254                        "25:    movl %%eax, 40(%3)\n"
255                        "26:    movl %%edx, 44(%3)\n"
256                        "27:    movl 48(%4), %%eax\n"
257                        "28:    movl 52(%4), %%edx\n"
258                        "29:    movl %%eax, 48(%3)\n"
259                        "30:    movl %%edx, 52(%3)\n"
260                        "31:    movl 56(%4), %%eax\n"
261                        "32:    movl 60(%4), %%edx\n"
262                        "33:    movl %%eax, 56(%3)\n"
263                        "34:    movl %%edx, 60(%3)\n"
264                        "       addl $-64, %0\n"
265                        "       addl $64, %4\n"
266                        "       addl $64, %3\n"
267                        "       cmpl $63, %0\n"
268                        "       ja  1b\n"
269                        "35:    movl  %0, %%eax\n"
270                        "       shrl  $2, %0\n"
271                        "       andl  $3, %%eax\n"
272                        "       cld\n"
273                        "99:    rep; movsl\n"
274                        "36:    movl %%eax, %0\n"
275                        "37:    rep; movsb\n"
276                        "100:\n"
277                        ".section .fixup,\"ax\"\n"
278                        "101:   lea 0(%%eax,%0,4),%0\n"
279                        "       jmp 100b\n"
280                        ".previous\n"
281                        ".section __ex_table,\"a\"\n"
282                        "       .align 4\n"
283                        "       .long 1b,100b\n"
284                        "       .long 2b,100b\n"
285                        "       .long 3b,100b\n"
286                        "       .long 4b,100b\n"
287                        "       .long 5b,100b\n"
288                        "       .long 6b,100b\n"
289                        "       .long 7b,100b\n"
290                        "       .long 8b,100b\n"
291                        "       .long 9b,100b\n"
292                        "       .long 10b,100b\n"
293                        "       .long 11b,100b\n"
294                        "       .long 12b,100b\n"
295                        "       .long 13b,100b\n"
296                        "       .long 14b,100b\n"
297                        "       .long 15b,100b\n"
298                        "       .long 16b,100b\n"
299                        "       .long 17b,100b\n"
300                        "       .long 18b,100b\n"
301                        "       .long 19b,100b\n"
302                        "       .long 20b,100b\n"
303                        "       .long 21b,100b\n"
304                        "       .long 22b,100b\n"
305                        "       .long 23b,100b\n"
306                        "       .long 24b,100b\n"
307                        "       .long 25b,100b\n"
308                        "       .long 26b,100b\n"
309                        "       .long 27b,100b\n"
310                        "       .long 28b,100b\n"
311                        "       .long 29b,100b\n"
312                        "       .long 30b,100b\n"
313                        "       .long 31b,100b\n"
314                        "       .long 32b,100b\n"
315                        "       .long 33b,100b\n"
316                        "       .long 34b,100b\n"
317                        "       .long 35b,100b\n"
318                        "       .long 36b,100b\n"
319                        "       .long 37b,100b\n"
320                        "       .long 99b,101b\n"
321                        ".previous"
322                        : "=&c"(size), "=&D" (d0), "=&S" (d1)
323                        :  "1"(to), "2"(from), "0"(size)
324                        : "eax", "edx", "memory");
325         return size;
326 }
327
328 static unsigned long
329 __copy_user_zeroing_intel(void *to, const void *from, unsigned long size)
330 {
331         int d0, d1;
332         __asm__ __volatile__(
333                        "        .align 2,0x90\n"
334                        "0:      movl 32(%4), %%eax\n"
335                        "        cmpl $67, %0\n"      
336                        "        jbe 2f\n"            
337                        "1:      movl 64(%4), %%eax\n"
338                        "        .align 2,0x90\n"     
339                        "2:      movl 0(%4), %%eax\n" 
340                        "21:     movl 4(%4), %%edx\n" 
341                        "        movl %%eax, 0(%3)\n" 
342                        "        movl %%edx, 4(%3)\n" 
343                        "3:      movl 8(%4), %%eax\n" 
344                        "31:     movl 12(%4),%%edx\n" 
345                        "        movl %%eax, 8(%3)\n" 
346                        "        movl %%edx, 12(%3)\n"
347                        "4:      movl 16(%4), %%eax\n"
348                        "41:     movl 20(%4), %%edx\n"
349                        "        movl %%eax, 16(%3)\n"
350                        "        movl %%edx, 20(%3)\n"
351                        "10:     movl 24(%4), %%eax\n"
352                        "51:     movl 28(%4), %%edx\n"
353                        "        movl %%eax, 24(%3)\n"
354                        "        movl %%edx, 28(%3)\n"
355                        "11:     movl 32(%4), %%eax\n"
356                        "61:     movl 36(%4), %%edx\n"
357                        "        movl %%eax, 32(%3)\n"
358                        "        movl %%edx, 36(%3)\n"
359                        "12:     movl 40(%4), %%eax\n"
360                        "71:     movl 44(%4), %%edx\n"
361                        "        movl %%eax, 40(%3)\n"
362                        "        movl %%edx, 44(%3)\n"
363                        "13:     movl 48(%4), %%eax\n"
364                        "81:     movl 52(%4), %%edx\n"
365                        "        movl %%eax, 48(%3)\n"
366                        "        movl %%edx, 52(%3)\n"
367                        "14:     movl 56(%4), %%eax\n"
368                        "91:     movl 60(%4), %%edx\n"
369                        "        movl %%eax, 56(%3)\n"
370                        "        movl %%edx, 60(%3)\n"
371                        "        addl $-64, %0\n"     
372                        "        addl $64, %4\n"      
373                        "        addl $64, %3\n"      
374                        "        cmpl $63, %0\n"      
375                        "        ja  0b\n"            
376                        "5:      movl  %0, %%eax\n"   
377                        "        shrl  $2, %0\n"      
378                        "        andl $3, %%eax\n"    
379                        "        cld\n"               
380                        "6:      rep; movsl\n"   
381                        "        movl %%eax,%0\n"
382                        "7:      rep; movsb\n"   
383                        "8:\n"                   
384                        ".section .fixup,\"ax\"\n"
385                        "9:      lea 0(%%eax,%0,4),%0\n" 
386                        "16:     pushl %0\n"     
387                        "        pushl %%eax\n"  
388                        "        xorl %%eax,%%eax\n"
389                        "        rep; stosb\n"   
390                        "        popl %%eax\n"   
391                        "        popl %0\n"      
392                        "        jmp 8b\n"       
393                        ".previous\n"            
394                        ".section __ex_table,\"a\"\n"
395                        "        .align 4\n"        
396                        "        .long 0b,16b\n"  
397                        "        .long 1b,16b\n"
398                        "        .long 2b,16b\n"
399                        "        .long 21b,16b\n"
400                        "        .long 3b,16b\n" 
401                        "        .long 31b,16b\n"
402                        "        .long 4b,16b\n" 
403                        "        .long 41b,16b\n"
404                        "        .long 10b,16b\n"
405                        "        .long 51b,16b\n"
406                        "        .long 11b,16b\n"
407                        "        .long 61b,16b\n"
408                        "        .long 12b,16b\n"
409                        "        .long 71b,16b\n"
410                        "        .long 13b,16b\n"
411                        "        .long 81b,16b\n"
412                        "        .long 14b,16b\n"
413                        "        .long 91b,16b\n"
414                        "        .long 6b,9b\n"  
415                        "        .long 7b,16b\n" 
416                        ".previous"              
417                        : "=&c"(size), "=&D" (d0), "=&S" (d1)
418                        :  "1"(to), "2"(from), "0"(size)
419                        : "eax", "edx", "memory");
420         return size;
421 }
422 #else
423 /*
424  * Leave these declared but undefined.  They should not be any references to
425  * them
426  */
427 unsigned long
428 __copy_user_zeroing_intel(void *to, const void *from, unsigned long size);
429 unsigned long
430 __copy_user_intel(void *to, const void *from,unsigned long size);
431 #endif /* CONFIG_X86_INTEL_USERCOPY */
432
433 /* Generic arbitrary sized copy.  */
434 #define __copy_user(to,from,size)                                       \
435 do {                                                                    \
436         int __d0, __d1, __d2;                                           \
437         __asm__ __volatile__(                                           \
438                 "       cmp  $7,%0\n"                                   \
439                 "       jbe  1f\n"                                      \
440                 "       movl %1,%0\n"                                   \
441                 "       negl %0\n"                                      \
442                 "       andl $7,%0\n"                                   \
443                 "       subl %0,%3\n"                                   \
444                 "4:     rep; movsb\n"                                   \
445                 "       movl %3,%0\n"                                   \
446                 "       shrl $2,%0\n"                                   \
447                 "       andl $3,%3\n"                                   \
448                 "       .align 2,0x90\n"                                \
449                 "0:     rep; movsl\n"                                   \
450                 "       movl %3,%0\n"                                   \
451                 "1:     rep; movsb\n"                                   \
452                 "2:\n"                                                  \
453                 ".section .fixup,\"ax\"\n"                              \
454                 "5:     addl %3,%0\n"                                   \
455                 "       jmp 2b\n"                                       \
456                 "3:     lea 0(%3,%0,4),%0\n"                            \
457                 "       jmp 2b\n"                                       \
458                 ".previous\n"                                           \
459                 ".section __ex_table,\"a\"\n"                           \
460                 "       .align 4\n"                                     \
461                 "       .long 4b,5b\n"                                  \
462                 "       .long 0b,3b\n"                                  \
463                 "       .long 1b,2b\n"                                  \
464                 ".previous"                                             \
465                 : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)   \
466                 : "3"(size), "0"(size), "1"(to), "2"(from)              \
467                 : "memory");                                            \
468 } while (0)
469
470 #define __copy_user_zeroing(to,from,size)                               \
471 do {                                                                    \
472         int __d0, __d1, __d2;                                           \
473         __asm__ __volatile__(                                           \
474                 "       cmp  $7,%0\n"                                   \
475                 "       jbe  1f\n"                                      \
476                 "       movl %1,%0\n"                                   \
477                 "       negl %0\n"                                      \
478                 "       andl $7,%0\n"                                   \
479                 "       subl %0,%3\n"                                   \
480                 "4:     rep; movsb\n"                                   \
481                 "       movl %3,%0\n"                                   \
482                 "       shrl $2,%0\n"                                   \
483                 "       andl $3,%3\n"                                   \
484                 "       .align 2,0x90\n"                                \
485                 "0:     rep; movsl\n"                                   \
486                 "       movl %3,%0\n"                                   \
487                 "1:     rep; movsb\n"                                   \
488                 "2:\n"                                                  \
489                 ".section .fixup,\"ax\"\n"                              \
490                 "5:     addl %3,%0\n"                                   \
491                 "       jmp 6f\n"                                       \
492                 "3:     lea 0(%3,%0,4),%0\n"                            \
493                 "6:     pushl %0\n"                                     \
494                 "       pushl %%eax\n"                                  \
495                 "       xorl %%eax,%%eax\n"                             \
496                 "       rep; stosb\n"                                   \
497                 "       popl %%eax\n"                                   \
498                 "       popl %0\n"                                      \
499                 "       jmp 2b\n"                                       \
500                 ".previous\n"                                           \
501                 ".section __ex_table,\"a\"\n"                           \
502                 "       .align 4\n"                                     \
503                 "       .long 4b,5b\n"                                  \
504                 "       .long 0b,3b\n"                                  \
505                 "       .long 1b,6b\n"                                  \
506                 ".previous"                                             \
507                 : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)   \
508                 : "3"(size), "0"(size), "1"(to), "2"(from)              \
509                 : "memory");                                            \
510 } while (0)
511
512
513 unsigned long __copy_to_user_ll(void __user *to, const void *from, unsigned long n)
514 {
515 #ifndef CONFIG_X86_WP_WORKS_OK
516         if (unlikely(boot_cpu_data.wp_works_ok == 0) &&
517                         ((unsigned long )to) < TASK_SIZE) {
518                 /* 
519                  * CPU does not honor the WP bit when writing
520                  * from supervisory mode, and due to preemption or SMP,
521                  * the page tables can change at any time.
522                  * Do it manually.      Manfred <manfred@colorfullife.com>
523                  */
524                 while (n) {
525                         unsigned long offset = ((unsigned long)to)%PAGE_SIZE;
526                         unsigned long len = PAGE_SIZE - offset;
527                         int retval;
528                         struct page *pg;
529                         void *maddr;
530                         
531                         if (len > n)
532                                 len = n;
533
534 survive:
535                         down_read(&current->mm->mmap_sem);
536                         retval = get_user_pages(current, current->mm,
537                                         (unsigned long )to, 1, 1, 0, &pg, NULL);
538
539                         if (retval == -ENOMEM && current->pid == 1) {
540                                 up_read(&current->mm->mmap_sem);
541                                 blk_congestion_wait(WRITE, HZ/50);
542                                 goto survive;
543                         }
544
545                         if (retval != 1) {
546                                 up_read(&current->mm->mmap_sem);
547                                 break;
548                         }
549
550                         maddr = kmap_atomic(pg, KM_USER0);
551                         memcpy(maddr + offset, from, len);
552                         kunmap_atomic(maddr, KM_USER0);
553                         set_page_dirty_lock(pg);
554                         put_page(pg);
555                         up_read(&current->mm->mmap_sem);
556
557                         from += len;
558                         to += len;
559                         n -= len;
560                 }
561                 return n;
562         }
563 #endif
564         if (movsl_is_ok(to, from, n))
565                 __copy_user((void *)to, from, n);
566         else
567                 n = __copy_user_intel((void *)to, from, n);
568         return n;
569 }
570
571 unsigned long
572 __copy_from_user_ll(void *to, const void __user *from, unsigned long n)
573 {
574         if (movsl_is_ok(to, from, n))
575                 __copy_user_zeroing(to, (const void *) from, n);
576         else
577                 n = __copy_user_zeroing_intel(to, (const void *) from, n);
578         return n;
579 }
580
581 /**
582  * copy_to_user: - Copy a block of data into user space.
583  * @to:   Destination address, in user space.
584  * @from: Source address, in kernel space.
585  * @n:    Number of bytes to copy.
586  *
587  * Context: User context only.  This function may sleep.
588  *
589  * Copy data from kernel space to user space.
590  *
591  * Returns number of bytes that could not be copied.
592  * On success, this will be zero.
593  */
594 unsigned long
595 copy_to_user(void __user *to, const void *from, unsigned long n)
596 {
597         might_sleep();
598         if (access_ok(VERIFY_WRITE, to, n))
599                 n = __copy_to_user(to, from, n);
600         return n;
601 }
602 EXPORT_SYMBOL(copy_to_user);
603
604 /**
605  * copy_from_user: - Copy a block of data from user space.
606  * @to:   Destination address, in kernel space.
607  * @from: Source address, in user space.
608  * @n:    Number of bytes to copy.
609  *
610  * Context: User context only.  This function may sleep.
611  *
612  * Copy data from user space to kernel space.
613  *
614  * Returns number of bytes that could not be copied.
615  * On success, this will be zero.
616  *
617  * If some data could not be copied, this function will pad the copied
618  * data to the requested size using zero bytes.
619  */
620 unsigned long
621 copy_from_user(void *to, const void __user *from, unsigned long n)
622 {
623         might_sleep();
624         if (access_ok(VERIFY_READ, from, n))
625                 n = __copy_from_user(to, from, n);
626         else
627                 memset(to, 0, n);
628         return n;
629 }
630 EXPORT_SYMBOL(copy_from_user);