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 <asm/uaccess.h>
11 * Copy a null terminated string from userspace.
14 #define __do_strncpy_from_user(dst,src,count,res) \
16 long __d0, __d1, __d2; \
18 __asm__ __volatile__( \
23 " testb %%al,%%al\n" \
29 ".section .fixup,\"ax\"\n" \
33 ".section __ex_table,\"a\"\n" \
37 : "=r"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \
39 : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
44 __strncpy_from_user(char *dst
, const char __user
*src
, long count
)
47 __do_strncpy_from_user(dst
, src
, count
, res
);
52 strncpy_from_user(char *dst
, const char __user
*src
, long count
)
55 if (access_ok(VERIFY_READ
, src
, 1))
56 __do_strncpy_from_user(dst
, src
, count
, res
);
64 unsigned long __clear_user(void __user
*addr
, unsigned long size
)
68 /* no memory constraint because it doesn't change any memory gcc knows
71 " testq %[size8],%[size8]\n"
73 "0: movq %[zero],(%[dst])\n"
74 " addq %[eight],%[dst]\n"
75 " decl %%ecx ; jnz 0b\n"
76 "4: movq %[size1],%%rcx\n"
77 " testl %%ecx,%%ecx\n"
79 "1: movb %b[zero],(%[dst])\n"
81 " decl %%ecx ; jnz 1b\n"
83 ".section .fixup,\"ax\"\n"
84 "3: lea 0(%[size1],%[size8],8),%[size8]\n"
87 ".section __ex_table,\"a\"\n"
92 : [size8
] "=c"(size
), [dst
] "=&D" (__d0
)
93 : [size1
] "r"(size
& 7), "[size8]" (size
/ 8), "[dst]"(addr
),
94 [zero
] "r" (0UL), [eight
] "r" (8UL));
99 unsigned long clear_user(void __user
*to
, unsigned long n
)
101 if (access_ok(VERIFY_WRITE
, to
, n
))
102 return __clear_user(to
, n
);
107 * Return the size of a string (including the ending 0)
109 * Return 0 on exception, a value greater than N if too long
112 long strnlen_user(const char __user
*s
, long n
)
117 if (!access_ok(VERIFY_READ
, s
, n
))
123 if (__get_user(c
, s
))
132 long strlen_user(const char __user
*s
)
147 unsigned long copy_in_user(void __user
*to
, const void __user
*from
, unsigned len
)
149 if (access_ok(VERIFY_WRITE
, to
, len
) && access_ok(VERIFY_READ
, from
, len
)) {
150 return copy_user_generic((__force
void *)to
, (__force
void *)from
, len
);