1 #ifndef _ARCH_POWERPC_UACCESS_H
2 #define _ARCH_POWERPC_UACCESS_H
7 #include <linux/sched.h>
8 #include <linux/errno.h>
9 #include <asm/asm-compat.h>
10 #include <asm/processor.h>
14 #define VERIFY_WRITE 1
27 #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
29 #define KERNEL_DS MAKE_MM_SEG(~0UL)
32 #define USER_DS MAKE_MM_SEG(TASK_SIZE_USER64 - 1)
34 #define USER_DS MAKE_MM_SEG(TASK_SIZE - 1)
37 #define get_ds() (KERNEL_DS)
38 #define get_fs() (current->thread.fs)
39 #define set_fs(val) (current->thread.fs = (val))
41 #define segment_eq(a, b) ((a).seg == (b).seg)
43 #define user_addr_max() (get_fs().seg)
50 #define __access_ok(addr, size, segment) \
51 (((addr) <= (segment).seg) && ((size) <= (segment).seg))
55 #define __access_ok(addr, size, segment) \
56 (((addr) <= (segment).seg) && \
57 (((size) == 0) || (((size) - 1) <= ((segment).seg - (addr)))))
61 #define access_ok(type, addr, size) \
62 (__chk_user_ptr(addr), \
63 __access_ok((__force unsigned long)(addr), (size), get_fs()))
102 #define get_user(x, ptr) \
103 __get_user_check((x), (ptr), sizeof(*(ptr)))
104 #define put_user(x, ptr) \
105 __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
107 #define __get_user(x, ptr) \
108 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
109 #define __put_user(x, ptr) \
110 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
112 #define __get_user_inatomic(x, ptr) \
113 __get_user_nosleep((x), (ptr), sizeof(*(ptr)))
114 #define __put_user_inatomic(x, ptr) \
115 __put_user_nosleep((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
117 #define __get_user_unaligned __get_user
118 #define __put_user_unaligned __put_user
127 #define __put_user_asm(x, addr, err, op) \
128 __asm__ __volatile__( \
129 "1: " op " %1,0(%2) # put_user\n" \
131 ".section .fixup,\"ax\"\n" \
135 ".section __ex_table,\"a\"\n" \
136 PPC_LONG_ALIGN "\n" \
140 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
143 #define __put_user_asm2(x, ptr, retval) \
144 __put_user_asm(x, ptr, retval, "std")
146 #define __put_user_asm2(x, addr, err) \
147 __asm__ __volatile__( \
148 "1: stw %1,0(%2)\n" \
149 "2: stw %1+1,4(%2)\n" \
151 ".section .fixup,\"ax\"\n" \
155 ".section __ex_table,\"a\"\n" \
156 PPC_LONG_ALIGN "\n" \
161 : "r" (x), "b" (addr), "i" (-EFAULT), "0" (err))
164 #define __put_user_size(x, ptr, size, retval) \
168 case 1: __put_user_asm(x, ptr, retval, "stb"); break; \
169 case 2: __put_user_asm(x, ptr, retval, "sth"); break; \
170 case 4: __put_user_asm(x, ptr, retval, "stw"); break; \
171 case 8: __put_user_asm2(x, ptr, retval); break; \
172 default: __put_user_bad(); \
176 #define __put_user_nocheck(x, ptr, size) \
179 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
180 if (!is_kernel_addr((unsigned long)__pu_addr)) \
182 __chk_user_ptr(ptr); \
183 __put_user_size((x), __pu_addr, (size), __pu_err); \
187 #define __put_user_check(x, ptr, size) \
189 long __pu_err = -EFAULT; \
190 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
192 if (access_ok(VERIFY_WRITE, __pu_addr, size)) \
193 __put_user_size((x), __pu_addr, (size), __pu_err); \
197 #define __put_user_nosleep(x, ptr, size) \
200 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
201 __chk_user_ptr(ptr); \
202 __put_user_size((x), __pu_addr, (size), __pu_err); \
209 #define __get_user_asm(x, addr, err, op) \
210 __asm__ __volatile__( \
211 "1: "op" %1,0(%2) # get_user\n" \
213 ".section .fixup,\"ax\"\n" \
218 ".section __ex_table,\"a\"\n" \
219 PPC_LONG_ALIGN "\n" \
222 : "=r" (err), "=r" (x) \
223 : "b" (addr), "i" (-EFAULT), "0" (err))
226 #define __get_user_asm2(x, addr, err) \
227 __get_user_asm(x, addr, err, "ld")
229 #define __get_user_asm2(x, addr, err) \
230 __asm__ __volatile__( \
231 "1: lwz %1,0(%2)\n" \
232 "2: lwz %1+1,4(%2)\n" \
234 ".section .fixup,\"ax\"\n" \
240 ".section __ex_table,\"a\"\n" \
241 PPC_LONG_ALIGN "\n" \
245 : "=r" (err), "=&r" (x) \
246 : "b" (addr), "i" (-EFAULT), "0" (err))
249 #define __get_user_size(x, ptr, size, retval) \
252 __chk_user_ptr(ptr); \
253 if (size > sizeof(x)) \
254 (x) = __get_user_bad(); \
256 case 1: __get_user_asm(x, ptr, retval, "lbz"); break; \
257 case 2: __get_user_asm(x, ptr, retval, "lhz"); break; \
258 case 4: __get_user_asm(x, ptr, retval, "lwz"); break; \
259 case 8: __get_user_asm2(x, ptr, retval); break; \
260 default: (x) = __get_user_bad(); \
264 #define __get_user_nocheck(x, ptr, size) \
267 unsigned long __gu_val; \
268 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
269 __chk_user_ptr(ptr); \
270 if (!is_kernel_addr((unsigned long)__gu_addr)) \
272 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
273 (x) = (__typeof__(*(ptr)))__gu_val; \
277 #ifndef __powerpc64__
278 #define __get_user64_nocheck(x, ptr, size) \
281 long long __gu_val; \
282 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
283 __chk_user_ptr(ptr); \
284 if (!is_kernel_addr((unsigned long)__gu_addr)) \
286 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
287 (x) = (__typeof__(*(ptr)))__gu_val; \
292 #define __get_user_check(x, ptr, size) \
294 long __gu_err = -EFAULT; \
295 unsigned long __gu_val = 0; \
296 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
298 if (access_ok(VERIFY_READ, __gu_addr, (size))) \
299 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
300 (x) = (__typeof__(*(ptr)))__gu_val; \
304 #define __get_user_nosleep(x, ptr, size) \
307 unsigned long __gu_val; \
308 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
309 __chk_user_ptr(ptr); \
310 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
311 (x) = (__typeof__(*(ptr)))__gu_val; \
319 const void __user *
from,
unsigned long size);
321 #ifndef __powerpc64__
324 const void __user *
from,
unsigned long n)
338 static inline unsigned long copy_to_user(
void __user *to,
339 const void *from,
unsigned long n)
355 #define __copy_in_user(to, from, size) \
356 __copy_tofrom_user((to), (from), (size))
358 extern unsigned long copy_from_user(
void *to,
const void __user *from,
360 extern unsigned long copy_to_user(
void __user *to,
const void *from,
362 extern unsigned long copy_in_user(
void __user *to,
const void __user *from,
368 const void __user *from,
unsigned long n)
370 if (__builtin_constant_p(n) && (n <= 8)) {
371 unsigned long ret = 1;
394 const void *from,
unsigned long n)
396 if (__builtin_constant_p(n) && (n <= 8)) {
397 unsigned long ret = 1;
420 const void __user *from,
unsigned long size)
427 const void *from,
unsigned long size)