1 #ifndef _ASM_X86_UACCESS_64_H
2 #define _ASM_X86_UACCESS_64_H
5 * User space memory access functions
7 #include <linux/compiler.h>
8 #include <linux/errno.h>
9 #include <linux/prefetch.h>
10 #include <linux/lockdep.h>
11 #include <asm/alternative.h>
12 #include <asm/cpufeature.h>
16 * Copy To/From Userspace
19 /* Handles exceptions in both to and from, but doesn't do access_ok */
20 __must_check
unsigned long
21 copy_user_generic_string(void *to
, const void *from
, unsigned len
);
22 __must_check
unsigned long
23 copy_user_generic_unrolled(void *to
, const void *from
, unsigned len
);
25 static __always_inline __must_check
unsigned long
26 copy_user_generic(void *to
, const void *from
, unsigned len
)
30 alternative_call(copy_user_generic_unrolled
,
31 copy_user_generic_string
,
33 ASM_OUTPUT2("=a" (ret
), "=D" (to
), "=S" (from
),
35 "1" (to
), "2" (from
), "3" (len
)
36 : "memory", "rcx", "r8", "r9", "r10", "r11");
40 __must_check
unsigned long
41 _copy_to_user(void __user
*to
, const void *from
, unsigned len
);
42 __must_check
unsigned long
43 _copy_from_user(void *to
, const void __user
*from
, unsigned len
);
44 __must_check
unsigned long
45 copy_in_user(void __user
*to
, const void __user
*from
, unsigned len
);
47 static inline unsigned long __must_check
copy_from_user(void *to
,
48 const void __user
*from
,
51 int sz
= __compiletime_object_size(to
);
54 if (likely(sz
== -1 || sz
>= n
))
55 n
= _copy_from_user(to
, from
, n
);
56 #ifdef CONFIG_DEBUG_VM
58 WARN(1, "Buffer overflow detected!\n");
63 static __always_inline __must_check
64 int copy_to_user(void __user
*dst
, const void *src
, unsigned size
)
68 return _copy_to_user(dst
, src
, size
);
71 static __always_inline __must_check
72 int __copy_from_user(void *dst
, const void __user
*src
, unsigned size
)
77 if (!__builtin_constant_p(size
))
78 return copy_user_generic(dst
, (__force
void *)src
, size
);
80 case 1:__get_user_asm(*(u8
*)dst
, (u8 __user
*)src
,
81 ret
, "b", "b", "=q", 1);
83 case 2:__get_user_asm(*(u16
*)dst
, (u16 __user
*)src
,
84 ret
, "w", "w", "=r", 2);
86 case 4:__get_user_asm(*(u32
*)dst
, (u32 __user
*)src
,
87 ret
, "l", "k", "=r", 4);
89 case 8:__get_user_asm(*(u64
*)dst
, (u64 __user
*)src
,
90 ret
, "q", "", "=r", 8);
93 __get_user_asm(*(u64
*)dst
, (u64 __user
*)src
,
94 ret
, "q", "", "=r", 10);
97 __get_user_asm(*(u16
*)(8 + (char *)dst
),
98 (u16 __user
*)(8 + (char __user
*)src
),
99 ret
, "w", "w", "=r", 2);
102 __get_user_asm(*(u64
*)dst
, (u64 __user
*)src
,
103 ret
, "q", "", "=r", 16);
106 __get_user_asm(*(u64
*)(8 + (char *)dst
),
107 (u64 __user
*)(8 + (char __user
*)src
),
108 ret
, "q", "", "=r", 8);
111 return copy_user_generic(dst
, (__force
void *)src
, size
);
115 static __always_inline __must_check
116 int __copy_to_user(void __user
*dst
, const void *src
, unsigned size
)
121 if (!__builtin_constant_p(size
))
122 return copy_user_generic((__force
void *)dst
, src
, size
);
124 case 1:__put_user_asm(*(u8
*)src
, (u8 __user
*)dst
,
125 ret
, "b", "b", "iq", 1);
127 case 2:__put_user_asm(*(u16
*)src
, (u16 __user
*)dst
,
128 ret
, "w", "w", "ir", 2);
130 case 4:__put_user_asm(*(u32
*)src
, (u32 __user
*)dst
,
131 ret
, "l", "k", "ir", 4);
133 case 8:__put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
134 ret
, "q", "", "er", 8);
137 __put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
138 ret
, "q", "", "er", 10);
142 __put_user_asm(4[(u16
*)src
], 4 + (u16 __user
*)dst
,
143 ret
, "w", "w", "ir", 2);
146 __put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
147 ret
, "q", "", "er", 16);
151 __put_user_asm(1[(u64
*)src
], 1 + (u64 __user
*)dst
,
152 ret
, "q", "", "er", 8);
155 return copy_user_generic((__force
void *)dst
, src
, size
);
159 static __always_inline __must_check
160 int __copy_in_user(void __user
*dst
, const void __user
*src
, unsigned size
)
165 if (!__builtin_constant_p(size
))
166 return copy_user_generic((__force
void *)dst
,
167 (__force
void *)src
, size
);
171 __get_user_asm(tmp
, (u8 __user
*)src
,
172 ret
, "b", "b", "=q", 1);
174 __put_user_asm(tmp
, (u8 __user
*)dst
,
175 ret
, "b", "b", "iq", 1);
180 __get_user_asm(tmp
, (u16 __user
*)src
,
181 ret
, "w", "w", "=r", 2);
183 __put_user_asm(tmp
, (u16 __user
*)dst
,
184 ret
, "w", "w", "ir", 2);
190 __get_user_asm(tmp
, (u32 __user
*)src
,
191 ret
, "l", "k", "=r", 4);
193 __put_user_asm(tmp
, (u32 __user
*)dst
,
194 ret
, "l", "k", "ir", 4);
199 __get_user_asm(tmp
, (u64 __user
*)src
,
200 ret
, "q", "", "=r", 8);
202 __put_user_asm(tmp
, (u64 __user
*)dst
,
203 ret
, "q", "", "er", 8);
207 return copy_user_generic((__force
void *)dst
,
208 (__force
void *)src
, size
);
213 strncpy_from_user(char *dst
, const char __user
*src
, long count
);
215 __strncpy_from_user(char *dst
, const char __user
*src
, long count
);
216 __must_check
long strnlen_user(const char __user
*str
, long n
);
217 __must_check
long __strnlen_user(const char __user
*str
, long n
);
218 __must_check
long strlen_user(const char __user
*str
);
219 __must_check
unsigned long clear_user(void __user
*mem
, unsigned long len
);
220 __must_check
unsigned long __clear_user(void __user
*mem
, unsigned long len
);
222 static __must_check __always_inline
int
223 __copy_from_user_inatomic(void *dst
, const void __user
*src
, unsigned size
)
225 return copy_user_generic(dst
, (__force
const void *)src
, size
);
228 static __must_check __always_inline
int
229 __copy_to_user_inatomic(void __user
*dst
, const void *src
, unsigned size
)
231 return copy_user_generic((__force
void *)dst
, src
, size
);
234 extern long __copy_user_nocache(void *dst
, const void __user
*src
,
235 unsigned size
, int zerorest
);
238 __copy_from_user_nocache(void *dst
, const void __user
*src
, unsigned size
)
241 return __copy_user_nocache(dst
, src
, size
, 1);
245 __copy_from_user_inatomic_nocache(void *dst
, const void __user
*src
,
248 return __copy_user_nocache(dst
, src
, size
, 0);
252 copy_user_handle_tail(char *to
, char *from
, unsigned len
, unsigned zerorest
);
254 #endif /* _ASM_X86_UACCESS_64_H */