]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef __PARISC_UACCESS_H |
3 | #define __PARISC_UACCESS_H | |
4 | ||
5 | /* | |
6 | * User space memory access functions | |
7 | */ | |
1da177e4 | 8 | #include <asm/page.h> |
1da177e4 | 9 | #include <asm/cache.h> |
1da177e4 | 10 | |
8dd95c68 | 11 | #include <linux/bug.h> |
aace880f | 12 | #include <linux/string.h> |
1da177e4 | 13 | |
12700c17 AB |
14 | #define TASK_SIZE_MAX DEFAULT_TASK_SIZE |
15 | #include <asm/pgtable.h> | |
16 | #include <asm-generic/access_ok.h> | |
1da177e4 | 17 | |
1da177e4 LT |
18 | #define put_user __put_user |
19 | #define get_user __get_user | |
20 | ||
ca72a223 | 21 | #if !defined(CONFIG_64BIT) |
67102872 HD |
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) | |
1da177e4 | 24 | #else |
67102872 HD |
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) | |
1da177e4 LT |
27 | #endif |
28 | ||
29 | /* | |
cb910c17 HD |
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. | |
1da177e4 LT |
34 | */ |
35 | ||
0de79858 | 36 | #define ARCH_HAS_RELATIVE_EXTABLE |
1da177e4 | 37 | struct exception_table_entry { |
0de79858 HD |
38 | int insn; /* relative address of insn that is allowed to fault. */ |
39 | int fixup; /* relative address of fixup routine */ | |
1da177e4 LT |
40 | }; |
41 | ||
0b3d643f HD |
42 | #define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\ |
43 | ".section __ex_table,\"aw\"\n" \ | |
a80aeb86 | 44 | ".align 4\n" \ |
0de79858 | 45 | ".word (" #fault_addr " - .), (" #except_addr " - .)\n\t" \ |
0b3d643f HD |
46 | ".previous\n" |
47 | ||
d19f5e41 HD |
48 | /* |
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 | |
4b9d2a73 | 51 | * load -EFAULT into %r29 for a read or write fault, and zeroes the target |
d19f5e41 HD |
52 | * register in case of a read fault in get_user(). |
53 | */ | |
4b9d2a73 HD |
54 | #define ASM_EXCEPTIONTABLE_REG 29 |
55 | #define ASM_EXCEPTIONTABLE_VAR(__variable) \ | |
56 | register long __variable __asm__ ("r29") = 0 | |
d19f5e41 HD |
57 | #define ASM_EXCEPTIONTABLE_ENTRY_EFAULT( fault_addr, except_addr )\ |
58 | ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr + 1) | |
59 | ||
67102872 | 60 | #define __get_user_internal(sr, val, ptr) \ |
3f795cef | 61 | ({ \ |
4b9d2a73 | 62 | ASM_EXCEPTIONTABLE_VAR(__gu_err); \ |
3f795cef HD |
63 | \ |
64 | switch (sizeof(*(ptr))) { \ | |
67102872 HD |
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; \ | |
3f795cef HD |
69 | default: BUILD_BUG(); \ |
70 | } \ | |
71 | \ | |
72 | __gu_err; \ | |
1da177e4 LT |
73 | }) |
74 | ||
3f795cef HD |
75 | #define __get_user(val, ptr) \ |
76 | ({ \ | |
5613a930 | 77 | __get_user_internal(SR_USER, val, ptr); \ |
3f795cef HD |
78 | }) |
79 | ||
67102872 | 80 | #define __get_user_asm(sr, val, ldx, ptr) \ |
3f795cef HD |
81 | { \ |
82 | register long __gu_val; \ | |
83 | \ | |
5613a930 | 84 | __asm__("1: " ldx " 0(%%sr%2,%3),%0\n" \ |
d19f5e41 HD |
85 | "9:\n" \ |
86 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ | |
dbd0b423 | 87 | : "=r"(__gu_val), "+r"(__gu_err) \ |
5613a930 | 88 | : "i"(sr), "r"(ptr)); \ |
3f795cef HD |
89 | \ |
90 | (val) = (__force __typeof__(*(ptr))) __gu_val; \ | |
91 | } | |
1da177e4 | 92 | |
67102872 HD |
93 | #define __get_kernel_nofault(dst, src, type, err_label) \ |
94 | { \ | |
95 | type __z; \ | |
96 | long __err; \ | |
5613a930 | 97 | __err = __get_user_internal(SR_KERNEL, __z, (type *)(src)); \ |
67102872 HD |
98 | if (unlikely(__err)) \ |
99 | goto err_label; \ | |
100 | else \ | |
101 | *(type *)(dst) = __z; \ | |
102 | } | |
103 | ||
104 | ||
d2ad824f HD |
105 | #if !defined(CONFIG_64BIT) |
106 | ||
67102872 | 107 | #define __get_user_asm64(sr, val, ptr) \ |
3f795cef HD |
108 | { \ |
109 | union { \ | |
110 | unsigned long long l; \ | |
111 | __typeof__(*(ptr)) t; \ | |
112 | } __gu_tmp; \ | |
113 | \ | |
d19f5e41 | 114 | __asm__(" copy %%r0,%R0\n" \ |
5613a930 HD |
115 | "1: ldw 0(%%sr%2,%3),%0\n" \ |
116 | "2: ldw 4(%%sr%2,%3),%R0\n" \ | |
d19f5e41 HD |
117 | "9:\n" \ |
118 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ | |
119 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ | |
dbd0b423 | 120 | : "=&r"(__gu_tmp.l), "+r"(__gu_err) \ |
5613a930 | 121 | : "i"(sr), "r"(ptr)); \ |
3f795cef HD |
122 | \ |
123 | (val) = __gu_tmp.t; \ | |
124 | } | |
d2ad824f HD |
125 | |
126 | #endif /* !defined(CONFIG_64BIT) */ | |
127 | ||
128 | ||
67102872 | 129 | #define __put_user_internal(sr, x, ptr) \ |
1da177e4 | 130 | ({ \ |
4b9d2a73 | 131 | ASM_EXCEPTIONTABLE_VAR(__pu_err); \ |
1da177e4 | 132 | \ |
06bff6b9 | 133 | switch (sizeof(*(ptr))) { \ |
dbd0b423 HD |
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; \ | |
3f795cef HD |
138 | default: BUILD_BUG(); \ |
139 | } \ | |
1da177e4 LT |
140 | \ |
141 | __pu_err; \ | |
142 | }) | |
143 | ||
3f795cef HD |
144 | #define __put_user(x, ptr) \ |
145 | ({ \ | |
dbd0b423 HD |
146 | __typeof__(&*(ptr)) __ptr = ptr; \ |
147 | __typeof__(*(__ptr)) __x = (__typeof__(*(__ptr)))(x); \ | |
5613a930 | 148 | __put_user_internal(SR_USER, __x, __ptr); \ |
3f795cef HD |
149 | }) |
150 | ||
67102872 HD |
151 | #define __put_kernel_nofault(dst, src, type, err_label) \ |
152 | { \ | |
153 | type __z = *(type *)(src); \ | |
154 | long __err; \ | |
5613a930 | 155 | __err = __put_user_internal(SR_KERNEL, __z, (type *)(dst)); \ |
67102872 HD |
156 | if (unlikely(__err)) \ |
157 | goto err_label; \ | |
158 | } | |
159 | ||
160 | ||
161 | ||
3f795cef | 162 | |
1da177e4 LT |
163 | /* |
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 | |
3fd3a74f | 166 | * gcc knows about, so there are no aliasing issues. These macros must |
d19f5e41 HD |
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. | |
4b9d2a73 HD |
169 | * The register holding the possible EFAULT error (ASM_EXCEPTIONTABLE_REG) |
170 | * is already listed as input and output register. | |
1da177e4 LT |
171 | */ |
172 | ||
67102872 HD |
173 | #define __put_user_asm(sr, stx, x, ptr) \ |
174 | __asm__ __volatile__ ( \ | |
5613a930 | 175 | "1: " stx " %1,0(%%sr%2,%3)\n" \ |
67102872 HD |
176 | "9:\n" \ |
177 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ | |
dbd0b423 | 178 | : "+r"(__pu_err) \ |
5613a930 | 179 | : "r"(x), "i"(sr), "r"(ptr)) |
1da177e4 | 180 | |
1da177e4 | 181 | |
ca72a223 | 182 | #if !defined(CONFIG_64BIT) |
94a1981d | 183 | |
67102872 HD |
184 | #define __put_user_asm64(sr, __val, ptr) do { \ |
185 | __asm__ __volatile__ ( \ | |
5613a930 HD |
186 | "1: stw %1,0(%%sr%2,%3)\n" \ |
187 | "2: stw %R1,4(%%sr%2,%3)\n" \ | |
67102872 HD |
188 | "9:\n" \ |
189 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(1b, 9b) \ | |
190 | ASM_EXCEPTIONTABLE_ENTRY_EFAULT(2b, 9b) \ | |
dbd0b423 | 191 | : "+r"(__pu_err) \ |
5613a930 | 192 | : "r"(__val), "i"(sr), "r"(ptr)); \ |
1da177e4 LT |
193 | } while (0) |
194 | ||
ca72a223 | 195 | #endif /* !defined(CONFIG_64BIT) */ |
1da177e4 LT |
196 | |
197 | ||
198 | /* | |
199 | * Complex access routines -- external declarations | |
200 | */ | |
201 | ||
b1195c0e | 202 | extern long strncpy_from_user(char *, const char __user *, long); |
67102872 | 203 | extern __must_check unsigned lclear_user(void __user *, unsigned long); |
1260dea6 | 204 | extern __must_check long strnlen_user(const char __user *src, long n); |
1da177e4 LT |
205 | /* |
206 | * Complex access routines -- macros | |
207 | */ | |
208 | ||
1da177e4 LT |
209 | #define clear_user lclear_user |
210 | #define __clear_user lclear_user | |
211 | ||
f64fd180 AV |
212 | unsigned long __must_check raw_copy_to_user(void __user *dst, const void *src, |
213 | unsigned long len); | |
214 | unsigned long __must_check raw_copy_from_user(void *dst, const void __user *src, | |
215 | unsigned long len); | |
f64fd180 AV |
216 | #define INLINE_COPY_TO_USER |
217 | #define INLINE_COPY_FROM_USER | |
888c31fc | 218 | |
e448372c | 219 | struct pt_regs; |
c61c25eb KM |
220 | int fixup_exception(struct pt_regs *regs); |
221 | ||
1da177e4 | 222 | #endif /* __PARISC_UACCESS_H */ |