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/lockdep.h>
10 #include <asm/alternative.h>
11 #include <asm/cpufeature.h>
15 * Copy To/From Userspace
18 /* Handles exceptions in both to and from, but doesn't do access_ok */
19 __must_check
unsigned long
20 copy_user_generic_string(void *to
, const void *from
, unsigned len
);
21 __must_check
unsigned long
22 copy_user_generic_unrolled(void *to
, const void *from
, unsigned len
);
24 static __always_inline __must_check
unsigned long
25 copy_user_generic(void *to
, const void *from
, unsigned len
)
29 alternative_call(copy_user_generic_unrolled
,
30 copy_user_generic_string
,
32 ASM_OUTPUT2("=a" (ret
), "=D" (to
), "=S" (from
),
34 "1" (to
), "2" (from
), "3" (len
)
35 : "memory", "rcx", "r8", "r9", "r10", "r11");
39 __must_check
unsigned long
40 _copy_to_user(void __user
*to
, const void *from
, unsigned len
);
41 __must_check
unsigned long
42 _copy_from_user(void *to
, const void __user
*from
, unsigned len
);
43 __must_check
unsigned long
44 copy_in_user(void __user
*to
, const void __user
*from
, unsigned len
);
46 static inline unsigned long __must_check
copy_from_user(void *to
,
47 const void __user
*from
,
50 int sz
= __compiletime_object_size(to
);
53 if (likely(sz
== -1 || sz
>= n
))
54 n
= _copy_from_user(to
, from
, n
);
55 #ifdef CONFIG_DEBUG_VM
57 WARN(1, "Buffer overflow detected!\n");
62 static __always_inline __must_check
63 int copy_to_user(void __user
*dst
, const void *src
, unsigned size
)
67 return _copy_to_user(dst
, src
, size
);
70 static __always_inline __must_check
71 int __copy_from_user(void *dst
, const void __user
*src
, unsigned size
)
76 if (!__builtin_constant_p(size
))
77 return copy_user_generic(dst
, (__force
void *)src
, size
);
79 case 1:__get_user_asm(*(u8
*)dst
, (u8 __user
*)src
,
80 ret
, "b", "b", "=q", 1);
82 case 2:__get_user_asm(*(u16
*)dst
, (u16 __user
*)src
,
83 ret
, "w", "w", "=r", 2);
85 case 4:__get_user_asm(*(u32
*)dst
, (u32 __user
*)src
,
86 ret
, "l", "k", "=r", 4);
88 case 8:__get_user_asm(*(u64
*)dst
, (u64 __user
*)src
,
89 ret
, "q", "", "=r", 8);
92 __get_user_asm(*(u64
*)dst
, (u64 __user
*)src
,
93 ret
, "q", "", "=r", 10);
96 __get_user_asm(*(u16
*)(8 + (char *)dst
),
97 (u16 __user
*)(8 + (char __user
*)src
),
98 ret
, "w", "w", "=r", 2);
101 __get_user_asm(*(u64
*)dst
, (u64 __user
*)src
,
102 ret
, "q", "", "=r", 16);
105 __get_user_asm(*(u64
*)(8 + (char *)dst
),
106 (u64 __user
*)(8 + (char __user
*)src
),
107 ret
, "q", "", "=r", 8);
110 return copy_user_generic(dst
, (__force
void *)src
, size
);
114 static __always_inline __must_check
115 int __copy_to_user(void __user
*dst
, const void *src
, unsigned size
)
120 if (!__builtin_constant_p(size
))
121 return copy_user_generic((__force
void *)dst
, src
, size
);
123 case 1:__put_user_asm(*(u8
*)src
, (u8 __user
*)dst
,
124 ret
, "b", "b", "iq", 1);
126 case 2:__put_user_asm(*(u16
*)src
, (u16 __user
*)dst
,
127 ret
, "w", "w", "ir", 2);
129 case 4:__put_user_asm(*(u32
*)src
, (u32 __user
*)dst
,
130 ret
, "l", "k", "ir", 4);
132 case 8:__put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
133 ret
, "q", "", "er", 8);
136 __put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
137 ret
, "q", "", "er", 10);
141 __put_user_asm(4[(u16
*)src
], 4 + (u16 __user
*)dst
,
142 ret
, "w", "w", "ir", 2);
145 __put_user_asm(*(u64
*)src
, (u64 __user
*)dst
,
146 ret
, "q", "", "er", 16);
150 __put_user_asm(1[(u64
*)src
], 1 + (u64 __user
*)dst
,
151 ret
, "q", "", "er", 8);
154 return copy_user_generic((__force
void *)dst
, src
, size
);
158 static __always_inline __must_check
159 int __copy_in_user(void __user
*dst
, const void __user
*src
, unsigned size
)
164 if (!__builtin_constant_p(size
))
165 return copy_user_generic((__force
void *)dst
,
166 (__force
void *)src
, size
);
170 __get_user_asm(tmp
, (u8 __user
*)src
,
171 ret
, "b", "b", "=q", 1);
173 __put_user_asm(tmp
, (u8 __user
*)dst
,
174 ret
, "b", "b", "iq", 1);
179 __get_user_asm(tmp
, (u16 __user
*)src
,
180 ret
, "w", "w", "=r", 2);
182 __put_user_asm(tmp
, (u16 __user
*)dst
,
183 ret
, "w", "w", "ir", 2);
189 __get_user_asm(tmp
, (u32 __user
*)src
,
190 ret
, "l", "k", "=r", 4);
192 __put_user_asm(tmp
, (u32 __user
*)dst
,
193 ret
, "l", "k", "ir", 4);
198 __get_user_asm(tmp
, (u64 __user
*)src
,
199 ret
, "q", "", "=r", 8);
201 __put_user_asm(tmp
, (u64 __user
*)dst
,
202 ret
, "q", "", "er", 8);
206 return copy_user_generic((__force
void *)dst
,
207 (__force
void *)src
, size
);
212 strncpy_from_user(char *dst
, const char __user
*src
, long count
);
214 __strncpy_from_user(char *dst
, const char __user
*src
, long count
);
215 __must_check
long strnlen_user(const char __user
*str
, long n
);
216 __must_check
long __strnlen_user(const char __user
*str
, long n
);
217 __must_check
long strlen_user(const char __user
*str
);
218 __must_check
unsigned long clear_user(void __user
*mem
, unsigned long len
);
219 __must_check
unsigned long __clear_user(void __user
*mem
, unsigned long len
);
221 static __must_check __always_inline
int
222 __copy_from_user_inatomic(void *dst
, const void __user
*src
, unsigned size
)
224 return copy_user_generic(dst
, (__force
const void *)src
, size
);
227 static __must_check __always_inline
int
228 __copy_to_user_inatomic(void __user
*dst
, const void *src
, unsigned size
)
230 return copy_user_generic((__force
void *)dst
, src
, size
);
233 extern long __copy_user_nocache(void *dst
, const void __user
*src
,
234 unsigned size
, int zerorest
);
237 __copy_from_user_nocache(void *dst
, const void __user
*src
, unsigned size
)
240 return __copy_user_nocache(dst
, src
, size
, 1);
244 __copy_from_user_inatomic_nocache(void *dst
, const void __user
*src
,
247 return __copy_user_nocache(dst
, src
, size
, 0);
251 copy_user_handle_tail(char *to
, char *from
, unsigned len
, unsigned zerorest
);
253 #endif /* _ASM_X86_UACCESS_64_H */