1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PARISC_UACCESS_H
3 #define __PARISC_UACCESS_H
6 * User space memory access functions
11 #include <linux/bug.h>
12 #include <linux/string.h>
14 #define TASK_SIZE_MAX DEFAULT_TASK_SIZE
15 #include <asm/pgtable.h>
16 #include <asm-generic/access_ok.h>
18 #define put_user __put_user
19 #define get_user __get_user
21 #if !defined(CONFIG_64BIT)
22 #define LDD_USER(sr, val, ptr) __get_user_asm64(sr, val, ptr)
23 #define STD_USER(sr, x, ptr) __put_user_asm64(sr, x, ptr)
25 #define LDD_USER(sr, val, ptr) __get_user_asm(sr, val, "ldd", ptr)
26 #define STD_USER(sr, x, ptr) __put_user_asm(sr, "std", x, ptr)
30 * The exception table contains two values: the first is the relative offset to
31 * the address of the instruction that is allowed to fault, and the second is
32 * the relative offset to the address of the fixup routine. Since relative
33 * addresses are used, 32bit values are sufficient even on 64bit kernel.
36 #define ARCH_HAS_RELATIVE_EXTABLE
37 struct exception_table_entry {
38 int insn; /* relative address of insn that is allowed to fault. */
39 int fixup; /* relative address of fixup routine */
42 #define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\
43 ".section __ex_table,\"aw\"\n" \
45 ".word (" #fault_addr " - .), (" #except_addr " - .)\n\t" \
49 * ASM_EXCEPTIONTABLE_ENTRY_EFAULT() creates a special exception table entry
50 * (with lowest bit set) for which the fault handler in fixup_exception() will
51 * load -EFAULT into %r29 for a read or write fault, and zeroes the target
52 * register in case of a read fault in get_user().
54 #define ASM_EXCEPTIONTABLE_REG 29
55 #define ASM_EXCEPTIONTABLE_VAR(__variable) \
56 register long __variable __asm__ ("r29") = 0
57 #define ASM_EXCEPTIONTABLE_ENTRY_EFAULT( fault_addr, except_addr )\
58 ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr + 1)
60 #define __get_user_internal(sr, val, ptr) \
62 ASM_EXCEPTIONTABLE_VAR(__gu_err); \
64 switch (sizeof(*(ptr))) { \
65 case 1: __get_user_asm(sr, val, "ldb", ptr); break; \
66 case 2: __get_user_asm(sr, val, "ldh", ptr); break; \
67 case 4: __get_user_asm(sr, val, "ldw", ptr); break; \
68 case 8: LDD_USER(sr, val, ptr); break; \
69 default: BUILD_BUG(); \
75 #define __get_user(val, ptr) \
77 __get_user_internal(SR_USER, val, ptr); \
80 #define __get_user_asm(sr, val, ldx, ptr) \
82 register long __gu_val; \
84 __asm__("1: " ldx " 0(%%sr%2,%3),%0\n" \
86 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
87 : "=r"(__gu_val), "+r"(__gu_err) \
88 : "i"(sr), "r"(ptr)); \
90 (val) = (__force __typeof__(*(ptr))) __gu_val; \
93 #define __get_kernel_nofault(dst, src, type, err_label) \
97 __err = __get_user_internal(SR_KERNEL, __z, (type *)(src)); \
98 if (unlikely(__err)) \
101 *(type *)(dst) = __z; \
105 #if !defined(CONFIG_64BIT)
107 #define __get_user_asm64(sr, val, ptr) \
110 unsigned long long l; \
111 __typeof__(*(ptr)) t; \
114 __asm__(" copy %%r0,%R0\n" \
115 "1: ldw 0(%%sr%2,%3),%0\n" \
116 "2: ldw 4(%%sr%2,%3),%R0\n" \
118 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
119 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \
120 : "=&r"(__gu_tmp.l), "+r"(__gu_err) \
121 : "i"(sr), "r"(ptr)); \
123 (val) = __gu_tmp.t; \
126 #endif /* !defined(CONFIG_64BIT) */
129 #define __put_user_internal(sr, x, ptr) \
131 ASM_EXCEPTIONTABLE_VAR(__pu_err); \
133 switch (sizeof(*(ptr))) { \
134 case 1: __put_user_asm(sr, "stb", x, ptr); break; \
135 case 2: __put_user_asm(sr, "sth", x, ptr); break; \
136 case 4: __put_user_asm(sr, "stw", x, ptr); break; \
137 case 8: STD_USER(sr, x, ptr); break; \
138 default: BUILD_BUG(); \
144 #define __put_user(x, ptr) \
146 __typeof__(&*(ptr)) __ptr = ptr; \
147 __typeof__(*(__ptr)) __x = (__typeof__(*(__ptr)))(x); \
148 __put_user_internal(SR_USER, __x, __ptr); \
151 #define __put_kernel_nofault(dst, src, type, err_label) \
153 type __z = *(type *)(src); \
155 __err = __put_user_internal(SR_KERNEL, __z, (type *)(dst)); \
156 if (unlikely(__err)) \
164 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
165 * instead of writing. This is because they do not write to any memory
166 * gcc knows about, so there are no aliasing issues. These macros must
167 * also be aware that fixups are executed in the context of the fault,
168 * and any registers used there must be listed as clobbers.
169 * The register holding the possible EFAULT error (ASM_EXCEPTIONTABLE_REG)
170 * is already listed as input and output register.
173 #define __put_user_asm(sr, stx, x, ptr) \
174 __asm__ __volatile__ ( \
175 "1: " stx " %1,0(%%sr%2,%3)\n" \
177 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
179 : "r"(x), "i"(sr), "r"(ptr))
182 #if !defined(CONFIG_64BIT)
184 #define __put_user_asm64(sr, __val, ptr) do { \
185 __asm__ __volatile__ ( \
186 "1: stw %1,0(%%sr%2,%3)\n" \
187 "2: stw %R1,4(%%sr%2,%3)\n" \
189 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
190 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \
192 : "r"(__val), "i"(sr), "r"(ptr)); \
195 #endif /* !defined(CONFIG_64BIT) */
199 * Complex access routines -- external declarations
202 extern long strncpy_from_user(char *, const char __user *, long);
203 extern __must_check unsigned lclear_user(void __user *, unsigned long);
204 extern __must_check long strnlen_user(const char __user *src, long n);
206 * Complex access routines -- macros
209 #define clear_user lclear_user
210 #define __clear_user lclear_user
212 unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src,
214 unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src,
216 #define INLINE_COPY_TO_USER
217 #define INLINE_COPY_FROM_USER
220 int fixup_exception(struct pt_regs *regs);
222 #endif /* __PARISC_UACCESS_H */