]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/alpha/include/asm/uaccess.h
1 #ifndef __ALPHA_UACCESS_H
2 #define __ALPHA_UACCESS_H
5 * The fs value determines whether argument validity checking should be
6 * performed or not. If get_fs() == USER_DS, checking is performed, with
7 * get_fs() == KERNEL_DS, checking is bypassed.
9 * Or at least it did once upon a time. Nowadays it is a mask that
10 * defines which bits of the address space are off limits. This is a
11 * wee bit faster than the above.
13 * For historical reasons, these macros are grossly misnamed.
16 #define KERNEL_DS ((mm_segment_t) { 0UL })
17 #define USER_DS ((mm_segment_t) { -0x40000000000UL })
19 #define get_fs() (current_thread_info()->addr_limit)
20 #define get_ds() (KERNEL_DS)
21 #define set_fs(x) (current_thread_info()->addr_limit = (x))
23 #define segment_eq(a, b) ((a).seg == (b).seg)
26 * Is a address valid? This does a straightforward calculation rather
30 * - "addr" doesn't have any high-bits set
31 * - AND "size" doesn't have any high-bits set
32 * - AND "addr+size" doesn't have any high-bits set
33 * - OR we are in kernel mode.
35 #define __access_ok(addr, size, segment) \
36 (((segment).seg & (addr | size | (addr+size))) == 0)
38 #define access_ok(type, addr, size) \
40 __chk_user_ptr(addr); \
41 __access_ok(((unsigned long)(addr)), (size), get_fs()); \
45 * These are the main single-value transfer routines. They automatically
46 * use the right size if we just have the right pointer type.
48 * As the alpha uses the same address space for kernel and user
49 * data, we can just do these as direct assignments. (Of course, the
50 * exception handling means that it's no longer "just"...)
53 * (a) re-use the arguments for side effects (sizeof/typeof is ok)
54 * (b) require any knowledge of processes at this stage
56 #define put_user(x, ptr) \
57 __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)), get_fs())
58 #define get_user(x, ptr) \
59 __get_user_check((x), (ptr), sizeof(*(ptr)), get_fs())
62 * The "__xxx" versions do not do address space checking, useful when
63 * doing multiple accesses to the same area (the programmer has to do the
64 * checks by hand with "access_ok()")
66 #define __put_user(x, ptr) \
67 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
68 #define __get_user(x, ptr) \
69 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
72 * The "lda %1, 2b-1b(%0)" bits are magic to get the assembler to
73 * encode the bits we need for resolving the exception. See the
74 * more extensive comments with fixup_inline_exception below for
78 extern void __get_user_unknown(void);
80 #define __get_user_nocheck(x, ptr, size) \
83 unsigned long __gu_val; \
84 __chk_user_ptr(ptr); \
86 case 1: __get_user_8(ptr); break; \
87 case 2: __get_user_16(ptr); break; \
88 case 4: __get_user_32(ptr); break; \
89 case 8: __get_user_64(ptr); break; \
90 default: __get_user_unknown(); break; \
92 (x) = (__force __typeof__(*(ptr))) __gu_val; \
96 #define __get_user_check(x, ptr, size, segment) \
98 long __gu_err = -EFAULT; \
99 unsigned long __gu_val = 0; \
100 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
101 if (__access_ok((unsigned long)__gu_addr, size, segment)) { \
104 case 1: __get_user_8(__gu_addr); break; \
105 case 2: __get_user_16(__gu_addr); break; \
106 case 4: __get_user_32(__gu_addr); break; \
107 case 8: __get_user_64(__gu_addr); break; \
108 default: __get_user_unknown(); break; \
111 (x) = (__force __typeof__(*(ptr))) __gu_val; \
115 struct __large_struct
{ unsigned long buf
[100]; };
116 #define __m(x) (*(struct __large_struct __user *)(x))
118 #define __get_user_64(addr) \
119 __asm__("1: ldq %0,%2\n" \
121 ".section __ex_table,\"a\"\n" \
123 " lda %0, 2b-1b(%1)\n" \
125 : "=r"(__gu_val), "=r"(__gu_err) \
126 : "m"(__m(addr)), "1"(__gu_err))
128 #define __get_user_32(addr) \
129 __asm__("1: ldl %0,%2\n" \
131 ".section __ex_table,\"a\"\n" \
133 " lda %0, 2b-1b(%1)\n" \
135 : "=r"(__gu_val), "=r"(__gu_err) \
136 : "m"(__m(addr)), "1"(__gu_err))
139 /* Those lucky bastards with ev56 and later CPUs can do byte/word moves. */
141 #define __get_user_16(addr) \
142 __asm__("1: ldwu %0,%2\n" \
144 ".section __ex_table,\"a\"\n" \
146 " lda %0, 2b-1b(%1)\n" \
148 : "=r"(__gu_val), "=r"(__gu_err) \
149 : "m"(__m(addr)), "1"(__gu_err))
151 #define __get_user_8(addr) \
152 __asm__("1: ldbu %0,%2\n" \
154 ".section __ex_table,\"a\"\n" \
156 " lda %0, 2b-1b(%1)\n" \
158 : "=r"(__gu_val), "=r"(__gu_err) \
159 : "m"(__m(addr)), "1"(__gu_err))
161 /* Unfortunately, we can't get an unaligned access trap for the sub-word
162 load, so we have to do a general unaligned operation. */
164 #define __get_user_16(addr) \
167 __asm__("1: ldq_u %0,0(%3)\n" \
168 "2: ldq_u %1,1(%3)\n" \
169 " extwl %0,%3,%0\n" \
170 " extwh %1,%3,%1\n" \
173 ".section __ex_table,\"a\"\n" \
175 " lda %0, 3b-1b(%2)\n" \
177 " lda %0, 3b-2b(%2)\n" \
179 : "=&r"(__gu_val), "=&r"(__gu_tmp), "=r"(__gu_err) \
180 : "r"(addr), "2"(__gu_err)); \
183 #define __get_user_8(addr) \
184 __asm__("1: ldq_u %0,0(%2)\n" \
185 " extbl %0,%2,%0\n" \
187 ".section __ex_table,\"a\"\n" \
189 " lda %0, 2b-1b(%1)\n" \
191 : "=&r"(__gu_val), "=r"(__gu_err) \
192 : "r"(addr), "1"(__gu_err))
195 extern void __put_user_unknown(void);
197 #define __put_user_nocheck(x, ptr, size) \
200 __chk_user_ptr(ptr); \
202 case 1: __put_user_8(x, ptr); break; \
203 case 2: __put_user_16(x, ptr); break; \
204 case 4: __put_user_32(x, ptr); break; \
205 case 8: __put_user_64(x, ptr); break; \
206 default: __put_user_unknown(); break; \
211 #define __put_user_check(x, ptr, size, segment) \
213 long __pu_err = -EFAULT; \
214 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
215 if (__access_ok((unsigned long)__pu_addr, size, segment)) { \
218 case 1: __put_user_8(x, __pu_addr); break; \
219 case 2: __put_user_16(x, __pu_addr); break; \
220 case 4: __put_user_32(x, __pu_addr); break; \
221 case 8: __put_user_64(x, __pu_addr); break; \
222 default: __put_user_unknown(); break; \
229 * The "__put_user_xx()" macros tell gcc they read from memory
230 * instead of writing: this is because they do not write to
231 * any memory gcc knows about, so there are no aliasing issues
233 #define __put_user_64(x, addr) \
234 __asm__ __volatile__("1: stq %r2,%1\n" \
236 ".section __ex_table,\"a\"\n" \
238 " lda $31,2b-1b(%0)\n" \
241 : "m" (__m(addr)), "rJ" (x), "0"(__pu_err))
243 #define __put_user_32(x, addr) \
244 __asm__ __volatile__("1: stl %r2,%1\n" \
246 ".section __ex_table,\"a\"\n" \
248 " lda $31,2b-1b(%0)\n" \
251 : "m"(__m(addr)), "rJ"(x), "0"(__pu_err))
254 /* Those lucky bastards with ev56 and later CPUs can do byte/word moves. */
256 #define __put_user_16(x, addr) \
257 __asm__ __volatile__("1: stw %r2,%1\n" \
259 ".section __ex_table,\"a\"\n" \
261 " lda $31,2b-1b(%0)\n" \
264 : "m"(__m(addr)), "rJ"(x), "0"(__pu_err))
266 #define __put_user_8(x, addr) \
267 __asm__ __volatile__("1: stb %r2,%1\n" \
269 ".section __ex_table,\"a\"\n" \
271 " lda $31,2b-1b(%0)\n" \
274 : "m"(__m(addr)), "rJ"(x), "0"(__pu_err))
276 /* Unfortunately, we can't get an unaligned access trap for the sub-word
277 write, so we have to do a general unaligned operation. */
279 #define __put_user_16(x, addr) \
281 long __pu_tmp1, __pu_tmp2, __pu_tmp3, __pu_tmp4; \
282 __asm__ __volatile__( \
283 "1: ldq_u %2,1(%5)\n" \
284 "2: ldq_u %1,0(%5)\n" \
285 " inswh %6,%5,%4\n" \
286 " inswl %6,%5,%3\n" \
287 " mskwh %2,%5,%2\n" \
288 " mskwl %1,%5,%1\n" \
291 "3: stq_u %2,1(%5)\n" \
292 "4: stq_u %1,0(%5)\n" \
294 ".section __ex_table,\"a\"\n" \
296 " lda $31, 5b-1b(%0)\n" \
298 " lda $31, 5b-2b(%0)\n" \
300 " lda $31, 5b-3b(%0)\n" \
302 " lda $31, 5b-4b(%0)\n" \
304 : "=r"(__pu_err), "=&r"(__pu_tmp1), \
305 "=&r"(__pu_tmp2), "=&r"(__pu_tmp3), \
307 : "r"(addr), "r"((unsigned long)(x)), "0"(__pu_err)); \
310 #define __put_user_8(x, addr) \
312 long __pu_tmp1, __pu_tmp2; \
313 __asm__ __volatile__( \
314 "1: ldq_u %1,0(%4)\n" \
315 " insbl %3,%4,%2\n" \
316 " mskbl %1,%4,%1\n" \
318 "2: stq_u %1,0(%4)\n" \
320 ".section __ex_table,\"a\"\n" \
322 " lda $31, 3b-1b(%0)\n" \
324 " lda $31, 3b-2b(%0)\n" \
327 "=&r"(__pu_tmp1), "=&r"(__pu_tmp2) \
328 : "r"((unsigned long)(x)), "r"(addr), "0"(__pu_err)); \
334 * Complex access routines
337 /* This little bit of silliness is to get the GP loaded for a function
338 that ordinarily wouldn't. Otherwise we could have it done by the macro
339 directly, which can be optimized the linker. */
341 #define __module_address(sym) "r"(sym),
342 #define __module_call(ra, arg, sym) "jsr $" #ra ",(%" #arg ")," #sym
344 #define __module_address(sym)
345 #define __module_call(ra, arg, sym) "bsr $" #ra "," #sym " !samegp"
348 extern void __copy_user(void);
351 __copy_tofrom_user_nocheck(void *to
, const void *from
, long len
)
353 register void * __cu_to
__asm__("$6") = to
;
354 register const void * __cu_from
__asm__("$7") = from
;
355 register long __cu_len
__asm__("$0") = len
;
357 __asm__
__volatile__(
358 __module_call(28, 3, __copy_user
)
359 : "=r" (__cu_len
), "=r" (__cu_from
), "=r" (__cu_to
)
360 : __module_address(__copy_user
)
361 "0" (__cu_len
), "1" (__cu_from
), "2" (__cu_to
)
362 : "$1", "$2", "$3", "$4", "$5", "$28", "memory");
367 #define __copy_to_user(to, from, n) \
369 __chk_user_ptr(to); \
370 __copy_tofrom_user_nocheck((__force void *)(to), (from), (n)); \
372 #define __copy_from_user(to, from, n) \
374 __chk_user_ptr(from); \
375 __copy_tofrom_user_nocheck((to), (__force void *)(from), (n)); \
378 #define __copy_to_user_inatomic __copy_to_user
379 #define __copy_from_user_inatomic __copy_from_user
382 copy_to_user(void __user
*to
, const void *from
, long n
)
384 if (likely(__access_ok((unsigned long)to
, n
, get_fs())))
385 n
= __copy_tofrom_user_nocheck((__force
void *)to
, from
, n
);
390 copy_from_user(void *to
, const void __user
*from
, long n
)
393 if (likely(__access_ok((unsigned long)from
, n
, get_fs())))
394 res
= __copy_from_user_inatomic(to
, from
, n
);
396 memset(to
+ (n
- res
), 0, res
);
400 extern void __do_clear_user(void);
403 __clear_user(void __user
*to
, long len
)
405 register void __user
* __cl_to
__asm__("$6") = to
;
406 register long __cl_len
__asm__("$0") = len
;
407 __asm__
__volatile__(
408 __module_call(28, 2, __do_clear_user
)
409 : "=r"(__cl_len
), "=r"(__cl_to
)
410 : __module_address(__do_clear_user
)
411 "0"(__cl_len
), "1"(__cl_to
)
412 : "$1", "$2", "$3", "$4", "$5", "$28", "memory");
417 clear_user(void __user
*to
, long len
)
419 if (__access_ok((unsigned long)to
, len
, get_fs()))
420 len
= __clear_user(to
, len
);
424 #undef __module_address
427 #define user_addr_max() \
428 (uaccess_kernel() ? ~0UL : TASK_SIZE)
430 extern long strncpy_from_user(char *dest
, const char __user
*src
, long count
);
431 extern __must_check
long strlen_user(const char __user
*str
);
432 extern __must_check
long strnlen_user(const char __user
*str
, long n
);
435 * About the exception table:
437 * - insn is a 32-bit pc-relative offset from the faulting insn.
438 * - nextinsn is a 16-bit offset off of the faulting instruction
439 * (not off of the *next* instruction as branches are).
440 * - errreg is the register in which to place -EFAULT.
441 * - valreg is the final target register for the load sequence
442 * and will be zeroed.
444 * Either errreg or valreg may be $31, in which case nothing happens.
446 * The exception fixup information "just so happens" to be arranged
447 * as in a MEM format instruction. This lets us emit our three
450 * lda valreg, nextinsn(errreg)
454 struct exception_table_entry
457 union exception_fixup
{
460 signed int nextinsn
: 16;
461 unsigned int errreg
: 5;
462 unsigned int valreg
: 5;
467 /* Returns the new pc */
468 #define fixup_exception(map_reg, _fixup, pc) \
470 if ((_fixup)->fixup.bits.valreg != 31) \
471 map_reg((_fixup)->fixup.bits.valreg) = 0; \
472 if ((_fixup)->fixup.bits.errreg != 31) \
473 map_reg((_fixup)->fixup.bits.errreg) = -EFAULT; \
474 (pc) + (_fixup)->fixup.bits.nextinsn; \
477 #define ARCH_HAS_RELATIVE_EXTABLE
479 #define swap_ex_entry_fixup(a, b, tmp, delta) \
481 (a)->fixup.unit = (b)->fixup.unit; \
482 (b)->fixup.unit = (tmp).fixup.unit; \
486 #endif /* __ALPHA_UACCESS_H */