1 #ifndef __X86_64_UACCESS_H
2 #define __X86_64_UACCESS_H
5 * User space memory access functions
7 #include <linux/compiler.h>
8 #include <linux/errno.h>
9 #include <linux/prefetch.h>
13 * Copy To/From Userspace
16 /* Handles exceptions in both to and from, but doesn't do access_ok */
17 __must_check unsigned long
18 copy_user_generic(void *to, const void *from, unsigned len);
20 __must_check unsigned long
21 copy_to_user(void __user *to, const void *from, unsigned len);
22 __must_check unsigned long
23 copy_from_user(void *to, const void __user *from, unsigned len);
24 __must_check unsigned long
25 copy_in_user(void __user *to, const void __user *from, unsigned len);
27 static __always_inline __must_check
28 int __copy_from_user(void *dst, const void __user *src, unsigned size)
31 if (!__builtin_constant_p(size))
32 return copy_user_generic(dst, (__force void *)src, size);
34 case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
35 ret, "b", "b", "=q", 1);
37 case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
38 ret, "w", "w", "=r", 2);
40 case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
41 ret, "l", "k", "=r", 4);
43 case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
44 ret, "q", "", "=r", 8);
47 __get_user_asm(*(u64 *)dst, (u64 __user *)src,
48 ret, "q", "", "=r", 16);
51 __get_user_asm(*(u16 *)(8 + (char *)dst),
52 (u16 __user *)(8 + (char __user *)src),
53 ret, "w", "w", "=r", 2);
56 __get_user_asm(*(u64 *)dst, (u64 __user *)src,
57 ret, "q", "", "=r", 16);
60 __get_user_asm(*(u64 *)(8 + (char *)dst),
61 (u64 __user *)(8 + (char __user *)src),
62 ret, "q", "", "=r", 8);
65 return copy_user_generic(dst, (__force void *)src, size);
69 static __always_inline __must_check
70 int __copy_to_user(void __user *dst, const void *src, unsigned size)
73 if (!__builtin_constant_p(size))
74 return copy_user_generic((__force void *)dst, src, size);
76 case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
77 ret, "b", "b", "iq", 1);
79 case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
80 ret, "w", "w", "ir", 2);
82 case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
83 ret, "l", "k", "ir", 4);
85 case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
86 ret, "q", "", "ir", 8);
89 __put_user_asm(*(u64 *)src, (u64 __user *)dst,
90 ret, "q", "", "ir", 10);
94 __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
95 ret, "w", "w", "ir", 2);
98 __put_user_asm(*(u64 *)src, (u64 __user *)dst,
99 ret, "q", "", "ir", 16);
103 __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
104 ret, "q", "", "ir", 8);
107 return copy_user_generic((__force void *)dst, src, size);
111 static __always_inline __must_check
112 int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
115 if (!__builtin_constant_p(size))
116 return copy_user_generic((__force void *)dst,
117 (__force void *)src, size);
121 __get_user_asm(tmp, (u8 __user *)src,
122 ret, "b", "b", "=q", 1);
124 __put_user_asm(tmp, (u8 __user *)dst,
125 ret, "b", "b", "iq", 1);
130 __get_user_asm(tmp, (u16 __user *)src,
131 ret, "w", "w", "=r", 2);
133 __put_user_asm(tmp, (u16 __user *)dst,
134 ret, "w", "w", "ir", 2);
140 __get_user_asm(tmp, (u32 __user *)src,
141 ret, "l", "k", "=r", 4);
143 __put_user_asm(tmp, (u32 __user *)dst,
144 ret, "l", "k", "ir", 4);
149 __get_user_asm(tmp, (u64 __user *)src,
150 ret, "q", "", "=r", 8);
152 __put_user_asm(tmp, (u64 __user *)dst,
153 ret, "q", "", "ir", 8);
157 return copy_user_generic((__force void *)dst,
158 (__force void *)src, size);
163 strncpy_from_user(char *dst, const char __user *src, long count);
165 __strncpy_from_user(char *dst, const char __user *src, long count);
166 __must_check long strnlen_user(const char __user *str, long n);
167 __must_check long __strnlen_user(const char __user *str, long n);
168 __must_check long strlen_user(const char __user *str);
169 __must_check unsigned long clear_user(void __user *mem, unsigned long len);
170 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
172 __must_check long __copy_from_user_inatomic(void *dst, const void __user *src,
175 static __must_check __always_inline int
176 __copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
178 return copy_user_generic((__force void *)dst, src, size);
181 extern long __copy_user_nocache(void *dst, const void __user *src,
182 unsigned size, int zerorest);
184 static inline int __copy_from_user_nocache(void *dst, const void __user *src,
188 return __copy_user_nocache(dst, src, size, 1);
191 static inline int __copy_from_user_inatomic_nocache(void *dst,
192 const void __user *src,
195 return __copy_user_nocache(dst, src, size, 0);
199 copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
201 #endif /* __X86_64_UACCESS_H */