blob: ff4cf9dab8d226a74ce360c4a1ac7b91265ae96b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __PARISC_UACCESS_H
2#define __PARISC_UACCESS_H
3
4/*
5 * User space memory access functions
6 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/page.h>
8#include <asm/system.h>
9#include <asm/cache.h>
Helge Deller888c31f2010-02-01 19:56:33 +000010#include <asm/errno.h>
Arnd Bergmann5b17e1c2009-05-13 22:56:30 +000011#include <asm-generic/uaccess-unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#define VERIFY_READ 0
14#define VERIFY_WRITE 1
15
16#define KERNEL_DS ((mm_segment_t){0})
17#define USER_DS ((mm_segment_t){1})
18
19#define segment_eq(a,b) ((a).seg == (b).seg)
20
21#define get_ds() (KERNEL_DS)
22#define get_fs() (current_thread_info()->addr_limit)
23#define set_fs(x) (current_thread_info()->addr_limit = (x))
24
25/*
26 * Note that since kernel addresses are in a separate address space on
Jesper Juhle49332b2005-05-01 08:59:08 -070027 * parisc, we don't need to do anything for access_ok().
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * We just let the page fault handler do the right thing. This also means
29 * that put_user is the same as __put_user, etc.
30 */
31
32extern int __get_kernel_bad(void);
33extern int __get_user_bad(void);
34extern int __put_kernel_bad(void);
35extern int __put_user_bad(void);
36
37static inline long access_ok(int type, const void __user * addr,
38 unsigned long size)
39{
40 return 1;
41}
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define put_user __put_user
44#define get_user __get_user
45
Helge Dellerca72a222006-12-20 00:35:57 +010046#if !defined(CONFIG_64BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define LDD_KERNEL(ptr) __get_kernel_bad();
48#define LDD_USER(ptr) __get_user_bad();
49#define STD_KERNEL(x, ptr) __put_kernel_asm64(x,ptr)
50#define STD_USER(x, ptr) __put_user_asm64(x,ptr)
Helge Deller94a19812006-12-19 22:33:58 +010051#define ASM_WORD_INSN ".word\t"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#else
Helge Deller94a19812006-12-19 22:33:58 +010053#define LDD_KERNEL(ptr) __get_kernel_asm("ldd",ptr)
54#define LDD_USER(ptr) __get_user_asm("ldd",ptr)
55#define STD_KERNEL(x, ptr) __put_kernel_asm("std",x,ptr)
56#define STD_USER(x, ptr) __put_user_asm("std",x,ptr)
57#define ASM_WORD_INSN ".dword\t"
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#endif
59
60/*
61 * The exception table contains two values: the first is an address
62 * for an instruction that is allowed to fault, and the second is
63 * the address to the fixup routine.
64 */
65
66struct exception_table_entry {
67 unsigned long insn; /* address of insn that is allowed to fault. */
68 long fixup; /* fixup routine */
69};
70
Helge Deller0b3d6432007-01-28 14:52:57 +010071#define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\
72 ".section __ex_table,\"aw\"\n" \
73 ASM_WORD_INSN #fault_addr ", " #except_addr "\n\t" \
74 ".previous\n"
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076/*
77 * The page fault handler stores, in a per-cpu area, the following information
78 * if a fixup routine is available.
79 */
80struct exception_data {
81 unsigned long fault_ip;
82 unsigned long fault_space;
83 unsigned long fault_addr;
84};
85
86#define __get_user(x,ptr) \
87({ \
88 register long __gu_err __asm__ ("r8") = 0; \
89 register long __gu_val __asm__ ("r9") = 0; \
90 \
91 if (segment_eq(get_fs(),KERNEL_DS)) { \
92 switch (sizeof(*(ptr))) { \
93 case 1: __get_kernel_asm("ldb",ptr); break; \
94 case 2: __get_kernel_asm("ldh",ptr); break; \
95 case 4: __get_kernel_asm("ldw",ptr); break; \
96 case 8: LDD_KERNEL(ptr); break; \
97 default: __get_kernel_bad(); break; \
98 } \
99 } \
100 else { \
101 switch (sizeof(*(ptr))) { \
102 case 1: __get_user_asm("ldb",ptr); break; \
103 case 2: __get_user_asm("ldh",ptr); break; \
104 case 4: __get_user_asm("ldw",ptr); break; \
105 case 8: LDD_USER(ptr); break; \
106 default: __get_user_bad(); break; \
107 } \
108 } \
109 \
110 (x) = (__typeof__(*(ptr))) __gu_val; \
111 __gu_err; \
112})
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define __get_kernel_asm(ldx,ptr) \
Helge Deller0b3d6432007-01-28 14:52:57 +0100115 __asm__("\n1:\t" ldx "\t0(%2),%0\n\t" \
116 ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 : "=r"(__gu_val), "=r"(__gu_err) \
118 : "r"(ptr), "1"(__gu_err) \
119 : "r1");
120
121#define __get_user_asm(ldx,ptr) \
Helge Deller0b3d6432007-01-28 14:52:57 +0100122 __asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n\t" \
123 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_get_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 : "=r"(__gu_val), "=r"(__gu_err) \
125 : "r"(ptr), "1"(__gu_err) \
126 : "r1");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128#define __put_user(x,ptr) \
129({ \
130 register long __pu_err __asm__ ("r8") = 0; \
131 __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \
132 \
133 if (segment_eq(get_fs(),KERNEL_DS)) { \
134 switch (sizeof(*(ptr))) { \
135 case 1: __put_kernel_asm("stb",__x,ptr); break; \
136 case 2: __put_kernel_asm("sth",__x,ptr); break; \
137 case 4: __put_kernel_asm("stw",__x,ptr); break; \
138 case 8: STD_KERNEL(__x,ptr); break; \
139 default: __put_kernel_bad(); break; \
140 } \
141 } \
142 else { \
143 switch (sizeof(*(ptr))) { \
144 case 1: __put_user_asm("stb",__x,ptr); break; \
145 case 2: __put_user_asm("sth",__x,ptr); break; \
146 case 4: __put_user_asm("stw",__x,ptr); break; \
147 case 8: STD_USER(__x,ptr); break; \
148 default: __put_user_bad(); break; \
149 } \
150 } \
151 \
152 __pu_err; \
153})
154
155/*
156 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
157 * instead of writing. This is because they do not write to any memory
Carlos O'Donell3fd3a742006-04-22 14:47:21 -0600158 * gcc knows about, so there are no aliasing issues. These macros must
159 * also be aware that "fixup_put_user_skip_[12]" are executed in the
160 * context of the fault, and any registers used there must be listed
161 * as clobbers. In this case only "r1" is used by the current routines.
162 * r8/r9 are already listed as err/val.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 */
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165#define __put_kernel_asm(stx,x,ptr) \
166 __asm__ __volatile__ ( \
Helge Deller0b3d6432007-01-28 14:52:57 +0100167 "\n1:\t" stx "\t%2,0(%1)\n\t" \
168 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_put_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 : "=r"(__pu_err) \
Carlos O'Donell3fd3a742006-04-22 14:47:21 -0600170 : "r"(ptr), "r"(x), "0"(__pu_err) \
171 : "r1")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173#define __put_user_asm(stx,x,ptr) \
174 __asm__ __volatile__ ( \
Helge Deller0b3d6432007-01-28 14:52:57 +0100175 "\n1:\t" stx "\t%2,0(%%sr3,%1)\n\t" \
176 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_put_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 : "=r"(__pu_err) \
178 : "r"(ptr), "r"(x), "0"(__pu_err) \
179 : "r1")
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Helge Dellerca72a222006-12-20 00:35:57 +0100182#if !defined(CONFIG_64BIT)
Helge Deller94a19812006-12-19 22:33:58 +0100183
184#define __put_kernel_asm64(__val,ptr) do { \
185 u64 __val64 = (u64)(__val); \
186 u32 hi = (__val64) >> 32; \
187 u32 lo = (__val64) & 0xffffffff; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 __asm__ __volatile__ ( \
Helge Deller0b3d6432007-01-28 14:52:57 +0100189 "\n1:\tstw %2,0(%1)" \
190 "\n2:\tstw %3,4(%1)\n\t" \
191 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_put_user_skip_2)\
192 ASM_EXCEPTIONTABLE_ENTRY(2b,fixup_put_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 : "=r"(__pu_err) \
194 : "r"(ptr), "r"(hi), "r"(lo), "0"(__pu_err) \
195 : "r1"); \
196} while (0)
197
Helge Deller94a19812006-12-19 22:33:58 +0100198#define __put_user_asm64(__val,ptr) do { \
199 u64 __val64 = (u64)(__val); \
200 u32 hi = (__val64) >> 32; \
201 u32 lo = (__val64) & 0xffffffff; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 __asm__ __volatile__ ( \
Helge Deller0b3d6432007-01-28 14:52:57 +0100203 "\n1:\tstw %2,0(%%sr3,%1)" \
204 "\n2:\tstw %3,4(%%sr3,%1)\n\t" \
205 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_put_user_skip_2)\
206 ASM_EXCEPTIONTABLE_ENTRY(2b,fixup_put_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 : "=r"(__pu_err) \
208 : "r"(ptr), "r"(hi), "r"(lo), "0"(__pu_err) \
209 : "r1"); \
210} while (0)
211
Helge Dellerca72a222006-12-20 00:35:57 +0100212#endif /* !defined(CONFIG_64BIT) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214
215/*
216 * Complex access routines -- external declarations
217 */
218
219extern unsigned long lcopy_to_user(void __user *, const void *, unsigned long);
220extern unsigned long lcopy_from_user(void *, const void __user *, unsigned long);
221extern unsigned long lcopy_in_user(void __user *, const void __user *, unsigned long);
222extern long lstrncpy_from_user(char *, const char __user *, long);
223extern unsigned lclear_user(void __user *,unsigned long);
224extern long lstrnlen_user(const char __user *,long);
225
226/*
227 * Complex access routines -- macros
228 */
229
230#define strncpy_from_user lstrncpy_from_user
231#define strnlen_user lstrnlen_user
232#define strlen_user(str) lstrnlen_user(str, 0x7fffffffL)
233#define clear_user lclear_user
234#define __clear_user lclear_user
235
236unsigned long copy_to_user(void __user *dst, const void *src, unsigned long len);
237#define __copy_to_user copy_to_user
Helge Deller888c31f2010-02-01 19:56:33 +0000238unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239unsigned long copy_in_user(void __user *dst, const void __user *src, unsigned long len);
240#define __copy_in_user copy_in_user
241#define __copy_to_user_inatomic __copy_to_user
242#define __copy_from_user_inatomic __copy_from_user
243
Helge Deller888c31f2010-02-01 19:56:33 +0000244extern void copy_from_user_overflow(void)
245#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
246 __compiletime_error("copy_from_user() buffer size is not provably correct")
247#else
248 __compiletime_warning("copy_from_user() buffer size is not provably correct")
249#endif
250;
251
252static inline unsigned long __must_check copy_from_user(void *to,
253 const void __user *from,
254 unsigned long n)
255{
256 int sz = __compiletime_object_size(to);
257 int ret = -EFAULT;
258
259 if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
260 ret = __copy_from_user(to, from, n);
261 else
262 copy_from_user_overflow();
263
264 return ret;
265}
266
Helge Dellere4483722009-01-13 20:52:46 +0100267struct pt_regs;
Kyle McMartinc61c25e2008-12-20 02:29:06 +0000268int fixup_exception(struct pt_regs *regs);
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270#endif /* __PARISC_UACCESS_H */