2 * User address space access functions.
4 * Copyright 1997 Andi Kleen <ak@muc.de>
5 * Copyright 1997 Linus Torvalds
6 * Copyright 2002 Andi Kleen <ak@suse.de>
8 #include <linux/module.h>
9 #include <asm/uaccess.h>
15 unsigned long __clear_user(void __user *addr, unsigned long size)
19 /* no memory constraint because it doesn't change any memory gcc knows
22 " testq %[size8],%[size8]\n"
24 "0: movq %[zero],(%[dst])\n"
25 " addq %[eight],%[dst]\n"
26 " decl %%ecx ; jnz 0b\n"
27 "4: movq %[size1],%%rcx\n"
28 " testl %%ecx,%%ecx\n"
30 "1: movb %b[zero],(%[dst])\n"
32 " decl %%ecx ; jnz 1b\n"
34 ".section .fixup,\"ax\"\n"
35 "3: lea 0(%[size1],%[size8],8),%[size8]\n"
40 : [size8] "=&c"(size), [dst] "=&D" (__d0)
41 : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
42 [zero] "r" (0UL), [eight] "r" (8UL));
45 EXPORT_SYMBOL(__clear_user);
47 unsigned long clear_user(void __user *to, unsigned long n)
49 if (access_ok(VERIFY_WRITE, to, n))
50 return __clear_user(to, n);
53 EXPORT_SYMBOL(clear_user);
56 * Return the size of a string (including the ending 0)
58 * Return 0 on exception, a value greater than N if too long
61 long __strnlen_user(const char __user *s, long n)
77 EXPORT_SYMBOL(__strnlen_user);
79 long strnlen_user(const char __user *s, long n)
81 if (!access_ok(VERIFY_READ, s, 1))
83 return __strnlen_user(s, n);
85 EXPORT_SYMBOL(strnlen_user);
87 long strlen_user(const char __user *s)
101 EXPORT_SYMBOL(strlen_user);
103 unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
105 if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
106 return copy_user_generic((__force void *)to, (__force void *)from, len);
110 EXPORT_SYMBOL(copy_in_user);
113 * Try to copy last bytes and clear the rest if needed.
114 * Since protection fault in copy_from/to_user is not a normal situation,
115 * it is not necessary to optimize tail handling.
118 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
124 if (__get_user_nocheck(c, from++, sizeof(char)))
126 if (__put_user_nocheck(c, to++, sizeof(char)))
130 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
131 if (__put_user_nocheck(c, to++, sizeof(char)))