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" \
44 ".word (" #fault_addr " - .), (" #except_addr " - .)\n\t" \
48 * ASM_EXCEPTIONTABLE_ENTRY_EFAULT() creates a special exception table entry
49 * (with lowest bit set) for which the fault handler in fixup_exception() will
50 * load -EFAULT into %r29 for a read or write fault, and zeroes the target
51 * register in case of a read fault in get_user().
53 #define ASM_EXCEPTIONTABLE_REG 29
54 #define ASM_EXCEPTIONTABLE_VAR(__variable) \
55 register long __variable __asm__ ("r29") = 0
56 #define ASM_EXCEPTIONTABLE_ENTRY_EFAULT( fault_addr, except_addr )\
57 ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr + 1)
59 #define __get_user_internal(sr, val, ptr) \
61 ASM_EXCEPTIONTABLE_VAR(__gu_err); \
63 switch (sizeof(*(ptr))) { \
64 case 1: __get_user_asm(sr, val, "ldb", ptr); break; \
65 case 2: __get_user_asm(sr, val, "ldh", ptr); break; \
66 case 4: __get_user_asm(sr, val, "ldw", ptr); break; \
67 case 8: LDD_USER(sr, val, ptr); break; \
68 default: BUILD_BUG(); \
74 #define __get_user(val, ptr) \
76 __get_user_internal(SR_USER, val, ptr); \
79 #define __get_user_asm(sr, val, ldx, ptr) \
81 register long __gu_val; \
83 __asm__("1: " ldx " 0(%%sr%2,%3),%0\n" \
85 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
86 : "=r"(__gu_val), "+r"(__gu_err) \
87 : "i"(sr), "r"(ptr)); \
89 (val) = (__force __typeof__(*(ptr))) __gu_val; \
92 #define __get_kernel_nofault(dst, src, type, err_label) \
96 __err = __get_user_internal(SR_KERNEL, __z, (type *)(src)); \
97 if (unlikely(__err)) \
100 *(type *)(dst) = __z; \
104 #if !defined(CONFIG_64BIT)
106 #define __get_user_asm64(sr, val, ptr) \
109 unsigned long long l; \
110 __typeof__(*(ptr)) t; \
113 __asm__(" copy %%r0,%R0\n" \
114 "1: ldw 0(%%sr%2,%3),%0\n" \
115 "2: ldw 4(%%sr%2,%3),%R0\n" \
117 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
118 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \
119 : "=&r"(__gu_tmp.l), "+r"(__gu_err) \
120 : "i"(sr), "r"(ptr)); \
122 (val) = __gu_tmp.t; \
125 #endif /* !defined(CONFIG_64BIT) */
128 #define __put_user_internal(sr, x, ptr) \
130 ASM_EXCEPTIONTABLE_VAR(__pu_err); \
132 switch (sizeof(*(ptr))) { \
133 case 1: __put_user_asm(sr, "stb", x, ptr); break; \
134 case 2: __put_user_asm(sr, "sth", x, ptr); break; \
135 case 4: __put_user_asm(sr, "stw", x, ptr); break; \
136 case 8: STD_USER(sr, x, ptr); break; \
137 default: BUILD_BUG(); \
143 #define __put_user(x, ptr) \
145 __typeof__(&*(ptr)) __ptr = ptr; \
146 __typeof__(*(__ptr)) __x = (__typeof__(*(__ptr)))(x); \
147 __put_user_internal(SR_USER, __x, __ptr); \
150 #define __put_kernel_nofault(dst, src, type, err_label) \
152 type __z = *(type *)(src); \
154 __err = __put_user_internal(SR_KERNEL, __z, (type *)(dst)); \
155 if (unlikely(__err)) \
163 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
164 * instead of writing. This is because they do not write to any memory
165 * gcc knows about, so there are no aliasing issues. These macros must
166 * also be aware that fixups are executed in the context of the fault,
167 * and any registers used there must be listed as clobbers.
168 * The register holding the possible EFAULT error (ASM_EXCEPTIONTABLE_REG)
169 * is already listed as input and output register.
172 #define __put_user_asm(sr, stx, x, ptr) \
173 __asm__ __volatile__ ( \
174 "1: " stx " %1,0(%%sr%2,%3)\n" \
176 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
178 : "r"(x), "i"(sr), "r"(ptr))
181 #if !defined(CONFIG_64BIT)
183 #define __put_user_asm64(sr, __val, ptr) do { \
184 __asm__ __volatile__ ( \
185 "1: stw %1,0(%%sr%2,%3)\n" \
186 "2: stw %R1,4(%%sr%2,%3)\n" \
188 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \
189 ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \
191 : "r"(__val), "i"(sr), "r"(ptr)); \
194 #endif /* !defined(CONFIG_64BIT) */
198 * Complex access routines -- external declarations
201 extern long strncpy_from_user(char *, const char __user *, long);
202 extern __must_check unsigned lclear_user(void __user *, unsigned long);
203 extern __must_check long strnlen_user(const char __user *src, long n);
205 * Complex access routines -- macros
208 #define clear_user lclear_user
209 #define __clear_user lclear_user
211 unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src,
213 unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src,
215 #define INLINE_COPY_TO_USER
216 #define INLINE_COPY_FROM_USER
219 int fixup_exception(struct pt_regs *regs);
221 #endif /* __PARISC_UACCESS_H */