1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __ASM_OPENRISC_UACCESS_H
20#define __ASM_OPENRISC_UACCESS_H
21
22
23
24
25#include <linux/prefetch.h>
26#include <linux/string.h>
27#include <asm/page.h>
28#include <asm/extable.h>
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#define KERNEL_DS (~0UL)
45#define get_ds() (KERNEL_DS)
46
47#define USER_DS (TASK_SIZE)
48#define get_fs() (current_thread_info()->addr_limit)
49#define set_fs(x) (current_thread_info()->addr_limit = (x))
50
51#define segment_eq(a, b) ((a) == (b))
52
53
54
55
56#define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs()-size))
57
58
59#define __addr_ok(addr) ((unsigned long) addr < get_fs())
60
61#define access_ok(type, addr, size) \
62 __range_ok((unsigned long)addr, (unsigned long)size)
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82#define get_user(x, ptr) \
83 __get_user_check((x), (ptr), sizeof(*(ptr)))
84#define put_user(x, ptr) \
85 __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
86
87#define __get_user(x, ptr) \
88 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
89#define __put_user(x, ptr) \
90 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
91
92extern long __put_user_bad(void);
93
94#define __put_user_nocheck(x, ptr, size) \
95({ \
96 long __pu_err; \
97 __put_user_size((x), (ptr), (size), __pu_err); \
98 __pu_err; \
99})
100
101#define __put_user_check(x, ptr, size) \
102({ \
103 long __pu_err = -EFAULT; \
104 __typeof__(*(ptr)) *__pu_addr = (ptr); \
105 if (access_ok(VERIFY_WRITE, __pu_addr, size)) \
106 __put_user_size((x), __pu_addr, (size), __pu_err); \
107 __pu_err; \
108})
109
110#define __put_user_size(x, ptr, size, retval) \
111do { \
112 retval = 0; \
113 switch (size) { \
114 case 1: __put_user_asm(x, ptr, retval, "l.sb"); break; \
115 case 2: __put_user_asm(x, ptr, retval, "l.sh"); break; \
116 case 4: __put_user_asm(x, ptr, retval, "l.sw"); break; \
117 case 8: __put_user_asm2(x, ptr, retval); break; \
118 default: __put_user_bad(); \
119 } \
120} while (0)
121
122struct __large_struct {
123 unsigned long buf[100];
124};
125#define __m(x) (*(struct __large_struct *)(x))
126
127
128
129
130
131
132#define __put_user_asm(x, addr, err, op) \
133 __asm__ __volatile__( \
134 "1: "op" 0(%2),%1\n" \
135 "2:\n" \
136 ".section .fixup,\"ax\"\n" \
137 "3: l.addi %0,r0,%3\n" \
138 " l.j 2b\n" \
139 " l.nop\n" \
140 ".previous\n" \
141 ".section __ex_table,\"a\"\n" \
142 " .align 2\n" \
143 " .long 1b,3b\n" \
144 ".previous" \
145 : "=r"(err) \
146 : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))
147
148#define __put_user_asm2(x, addr, err) \
149 __asm__ __volatile__( \
150 "1: l.sw 0(%2),%1\n" \
151 "2: l.sw 4(%2),%H1\n" \
152 "3:\n" \
153 ".section .fixup,\"ax\"\n" \
154 "4: l.addi %0,r0,%3\n" \
155 " l.j 3b\n" \
156 " l.nop\n" \
157 ".previous\n" \
158 ".section __ex_table,\"a\"\n" \
159 " .align 2\n" \
160 " .long 1b,4b\n" \
161 " .long 2b,4b\n" \
162 ".previous" \
163 : "=r"(err) \
164 : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))
165
166#define __get_user_nocheck(x, ptr, size) \
167({ \
168 long __gu_err, __gu_val; \
169 __get_user_size(__gu_val, (ptr), (size), __gu_err); \
170 (x) = (__force __typeof__(*(ptr)))__gu_val; \
171 __gu_err; \
172})
173
174#define __get_user_check(x, ptr, size) \
175({ \
176 long __gu_err = -EFAULT, __gu_val = 0; \
177 const __typeof__(*(ptr)) * __gu_addr = (ptr); \
178 if (access_ok(VERIFY_READ, __gu_addr, size)) \
179 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
180 (x) = (__force __typeof__(*(ptr)))__gu_val; \
181 __gu_err; \
182})
183
184extern long __get_user_bad(void);
185
186#define __get_user_size(x, ptr, size, retval) \
187do { \
188 retval = 0; \
189 switch (size) { \
190 case 1: __get_user_asm(x, ptr, retval, "l.lbz"); break; \
191 case 2: __get_user_asm(x, ptr, retval, "l.lhz"); break; \
192 case 4: __get_user_asm(x, ptr, retval, "l.lwz"); break; \
193 case 8: __get_user_asm2(x, ptr, retval); break; \
194 default: (x) = __get_user_bad(); \
195 } \
196} while (0)
197
198#define __get_user_asm(x, addr, err, op) \
199 __asm__ __volatile__( \
200 "1: "op" %1,0(%2)\n" \
201 "2:\n" \
202 ".section .fixup,\"ax\"\n" \
203 "3: l.addi %0,r0,%3\n" \
204 " l.addi %1,r0,0\n" \
205 " l.j 2b\n" \
206 " l.nop\n" \
207 ".previous\n" \
208 ".section __ex_table,\"a\"\n" \
209 " .align 2\n" \
210 " .long 1b,3b\n" \
211 ".previous" \
212 : "=r"(err), "=r"(x) \
213 : "r"(addr), "i"(-EFAULT), "0"(err))
214
215#define __get_user_asm2(x, addr, err) \
216 __asm__ __volatile__( \
217 "1: l.lwz %1,0(%2)\n" \
218 "2: l.lwz %H1,4(%2)\n" \
219 "3:\n" \
220 ".section .fixup,\"ax\"\n" \
221 "4: l.addi %0,r0,%3\n" \
222 " l.addi %1,r0,0\n" \
223 " l.addi %H1,r0,0\n" \
224 " l.j 3b\n" \
225 " l.nop\n" \
226 ".previous\n" \
227 ".section __ex_table,\"a\"\n" \
228 " .align 2\n" \
229 " .long 1b,4b\n" \
230 " .long 2b,4b\n" \
231 ".previous" \
232 : "=r"(err), "=&r"(x) \
233 : "r"(addr), "i"(-EFAULT), "0"(err))
234
235
236
237extern unsigned long __must_check
238__copy_tofrom_user(void *to, const void *from, unsigned long size);
239static inline unsigned long
240raw_copy_from_user(void *to, const void __user *from, unsigned long size)
241{
242 return __copy_tofrom_user(to, (__force const void *)from, size);
243}
244static inline unsigned long
245raw_copy_to_user(void *to, const void __user *from, unsigned long size)
246{
247 return __copy_tofrom_user((__force void *)to, from, size);
248}
249#define INLINE_COPY_FROM_USER
250#define INLINE_COPY_TO_USER
251
252extern unsigned long __clear_user(void *addr, unsigned long size);
253
254static inline __must_check unsigned long
255clear_user(void *addr, unsigned long size)
256{
257 if (likely(access_ok(VERIFY_WRITE, addr, size)))
258 size = __clear_user(addr, size);
259 return size;
260}
261
262#define user_addr_max() \
263 (uaccess_kernel() ? ~0UL : TASK_SIZE)
264
265extern long strncpy_from_user(char *dest, const char __user *src, long count);
266
267extern __must_check long strnlen_user(const char __user *str, long n);
268
269#endif
270