This source file includes following definitions.
- __access_ok
- raw_copy_to_user
- raw_copy_from_user
- xlate_dev_mem_ptr
- xlate_dev_kmem_ptr
1
2 #ifndef _ASM_IA64_UACCESS_H
3 #define _ASM_IA64_UACCESS_H
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #include <linux/compiler.h>
37 #include <linux/page-flags.h>
38 #include <linux/mm.h>
39
40 #include <asm/intrinsics.h>
41 #include <asm/pgtable.h>
42 #include <asm/io.h>
43 #include <asm/extable.h>
44
45
46
47
48 #define KERNEL_DS ((mm_segment_t) { ~0UL })
49 #define USER_DS ((mm_segment_t) { TASK_SIZE-1 })
50
51 #define get_fs() (current_thread_info()->addr_limit)
52 #define set_fs(x) (current_thread_info()->addr_limit = (x))
53
54 #define segment_eq(a, b) ((a).seg == (b).seg)
55
56
57
58
59
60
61
62 static inline int __access_ok(const void __user *p, unsigned long size)
63 {
64 unsigned long addr = (unsigned long)p;
65 unsigned long seg = get_fs().seg;
66 return likely(addr <= seg) &&
67 (seg == KERNEL_DS.seg || likely(REGION_OFFSET(addr) < RGN_MAP_LIMIT));
68 }
69 #define access_ok(addr, size) __access_ok((addr), (size))
70
71
72
73
74
75
76
77
78
79 #define put_user(x, ptr) __put_user_check((__typeof__(*(ptr))) (x), (ptr), sizeof(*(ptr)))
80 #define get_user(x, ptr) __get_user_check((x), (ptr), sizeof(*(ptr)))
81
82
83
84
85
86
87 #define __put_user(x, ptr) __put_user_nocheck((__typeof__(*(ptr))) (x), (ptr), sizeof(*(ptr)))
88 #define __get_user(x, ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
89
90 #ifdef ASM_SUPPORTED
91 struct __large_struct { unsigned long buf[100]; };
92 # define __m(x) (*(struct __large_struct __user *)(x))
93
94
95 asm (".section \"__ex_table\", \"a\"\n\t.previous");
96
97 # define __get_user_size(val, addr, n, err) \
98 do { \
99 register long __gu_r8 asm ("r8") = 0; \
100 register long __gu_r9 asm ("r9"); \
101 asm ("\n[1:]\tld"#n" %0=%2%P2\t// %0 and %1 get overwritten by exception handler\n" \
102 "\t.xdata4 \"__ex_table\", 1b-., 1f-.+4\n" \
103 "[1:]" \
104 : "=r"(__gu_r9), "=r"(__gu_r8) : "m"(__m(addr)), "1"(__gu_r8)); \
105 (err) = __gu_r8; \
106 (val) = __gu_r9; \
107 } while (0)
108
109
110
111
112
113
114 # define __put_user_size(val, addr, n, err) \
115 do { \
116 register long __pu_r8 asm ("r8") = 0; \
117 asm volatile ("\n[1:]\tst"#n" %1=%r2%P1\t// %0 gets overwritten by exception handler\n" \
118 "\t.xdata4 \"__ex_table\", 1b-., 1f-.\n" \
119 "[1:]" \
120 : "=r"(__pu_r8) : "m"(__m(addr)), "rO"(val), "0"(__pu_r8)); \
121 (err) = __pu_r8; \
122 } while (0)
123
124 #else
125 # define RELOC_TYPE 2
126 # define __get_user_size(val, addr, n, err) \
127 do { \
128 __ld_user("__ex_table", (unsigned long) addr, n, RELOC_TYPE); \
129 (err) = ia64_getreg(_IA64_REG_R8); \
130 (val) = ia64_getreg(_IA64_REG_R9); \
131 } while (0)
132 # define __put_user_size(val, addr, n, err) \
133 do { \
134 __st_user("__ex_table", (unsigned long) addr, n, RELOC_TYPE, \
135 (__force unsigned long) (val)); \
136 (err) = ia64_getreg(_IA64_REG_R8); \
137 } while (0)
138 #endif
139
140 extern void __get_user_unknown (void);
141
142
143
144
145
146
147 #define __do_get_user(check, x, ptr, size) \
148 ({ \
149 const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
150 __typeof__ (size) __gu_size = (size); \
151 long __gu_err = -EFAULT; \
152 unsigned long __gu_val = 0; \
153 if (!check || __access_ok(__gu_ptr, size)) \
154 switch (__gu_size) { \
155 case 1: __get_user_size(__gu_val, __gu_ptr, 1, __gu_err); break; \
156 case 2: __get_user_size(__gu_val, __gu_ptr, 2, __gu_err); break; \
157 case 4: __get_user_size(__gu_val, __gu_ptr, 4, __gu_err); break; \
158 case 8: __get_user_size(__gu_val, __gu_ptr, 8, __gu_err); break; \
159 default: __get_user_unknown(); break; \
160 } \
161 (x) = (__force __typeof__(*(__gu_ptr))) __gu_val; \
162 __gu_err; \
163 })
164
165 #define __get_user_nocheck(x, ptr, size) __do_get_user(0, x, ptr, size)
166 #define __get_user_check(x, ptr, size) __do_get_user(1, x, ptr, size)
167
168 extern void __put_user_unknown (void);
169
170
171
172
173
174 #define __do_put_user(check, x, ptr, size) \
175 ({ \
176 __typeof__ (x) __pu_x = (x); \
177 __typeof__ (*(ptr)) __user *__pu_ptr = (ptr); \
178 __typeof__ (size) __pu_size = (size); \
179 long __pu_err = -EFAULT; \
180 \
181 if (!check || __access_ok(__pu_ptr, __pu_size)) \
182 switch (__pu_size) { \
183 case 1: __put_user_size(__pu_x, __pu_ptr, 1, __pu_err); break; \
184 case 2: __put_user_size(__pu_x, __pu_ptr, 2, __pu_err); break; \
185 case 4: __put_user_size(__pu_x, __pu_ptr, 4, __pu_err); break; \
186 case 8: __put_user_size(__pu_x, __pu_ptr, 8, __pu_err); break; \
187 default: __put_user_unknown(); break; \
188 } \
189 __pu_err; \
190 })
191
192 #define __put_user_nocheck(x, ptr, size) __do_put_user(0, x, ptr, size)
193 #define __put_user_check(x, ptr, size) __do_put_user(1, x, ptr, size)
194
195
196
197
198 extern unsigned long __must_check __copy_user (void __user *to, const void __user *from,
199 unsigned long count);
200
201 static inline unsigned long
202 raw_copy_to_user(void __user *to, const void *from, unsigned long count)
203 {
204 return __copy_user(to, (__force void __user *) from, count);
205 }
206
207 static inline unsigned long
208 raw_copy_from_user(void *to, const void __user *from, unsigned long count)
209 {
210 return __copy_user((__force void __user *) to, from, count);
211 }
212
213 #define INLINE_COPY_FROM_USER
214 #define INLINE_COPY_TO_USER
215
216 extern unsigned long __do_clear_user (void __user *, unsigned long);
217
218 #define __clear_user(to, n) __do_clear_user(to, n)
219
220 #define clear_user(to, n) \
221 ({ \
222 unsigned long __cu_len = (n); \
223 if (__access_ok(to, __cu_len)) \
224 __cu_len = __do_clear_user(to, __cu_len); \
225 __cu_len; \
226 })
227
228
229
230
231
232
233 extern long __must_check __strncpy_from_user (char *to, const char __user *from, long to_len);
234
235 #define strncpy_from_user(to, from, n) \
236 ({ \
237 const char __user * __sfu_from = (from); \
238 long __sfu_ret = -EFAULT; \
239 if (__access_ok(__sfu_from, 0)) \
240 __sfu_ret = __strncpy_from_user((to), __sfu_from, (n)); \
241 __sfu_ret; \
242 })
243
244
245
246
247
248
249 extern unsigned long __strnlen_user (const char __user *, long);
250
251 #define strnlen_user(str, len) \
252 ({ \
253 const char __user *__su_str = (str); \
254 unsigned long __su_ret = 0; \
255 if (__access_ok(__su_str, 0)) \
256 __su_ret = __strnlen_user(__su_str, len); \
257 __su_ret; \
258 })
259
260 #define ARCH_HAS_TRANSLATE_MEM_PTR 1
261 static __inline__ void *
262 xlate_dev_mem_ptr(phys_addr_t p)
263 {
264 struct page *page;
265 void *ptr;
266
267 page = pfn_to_page(p >> PAGE_SHIFT);
268 if (PageUncached(page))
269 ptr = (void *)p + __IA64_UNCACHED_OFFSET;
270 else
271 ptr = __va(p);
272
273 return ptr;
274 }
275
276
277
278
279 static __inline__ void *
280 xlate_dev_kmem_ptr(void *p)
281 {
282 struct page *page;
283 void *ptr;
284
285 page = virt_to_page((unsigned long)p);
286 if (PageUncached(page))
287 ptr = (void *)__pa(p) + __IA64_UNCACHED_OFFSET;
288 else
289 ptr = p;
290
291 return ptr;
292 }
293
294 #endif