blob: a5cb070b54bf4ade7cce44e50f763a5223991e83 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/cache.h>
Helge Deller888c31f2010-02-01 19:56:33 +00009#include <asm/errno.h>
Arnd Bergmann5b17e1c2009-05-13 22:56:30 +000010#include <asm-generic/uaccess-unaligned.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Helge Deller8dd95c62014-10-21 21:29:09 +020012#include <linux/bug.h>
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#define VERIFY_READ 0
15#define VERIFY_WRITE 1
16
17#define KERNEL_DS ((mm_segment_t){0})
18#define USER_DS ((mm_segment_t){1})
19
20#define segment_eq(a,b) ((a).seg == (b).seg)
21
22#define get_ds() (KERNEL_DS)
23#define get_fs() (current_thread_info()->addr_limit)
24#define set_fs(x) (current_thread_info()->addr_limit = (x))
25
26/*
27 * Note that since kernel addresses are in a separate address space on
Jesper Juhle49332b2005-05-01 08:59:08 -070028 * parisc, we don't need to do anything for access_ok().
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * We just let the page fault handler do the right thing. This also means
30 * that put_user is the same as __put_user, etc.
31 */
32
Helge Dellera0ffa8f2013-11-19 23:31:35 +010033static inline long access_ok(int type, const void __user * addr,
34 unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
Helge Dellera0ffa8f2013-11-19 23:31:35 +010036 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define put_user __put_user
40#define get_user __get_user
41
Helge Dellerca72a222006-12-20 00:35:57 +010042#if !defined(CONFIG_64BIT)
Helge Deller8dd95c62014-10-21 21:29:09 +020043#define LDD_KERNEL(ptr) BUILD_BUG()
44#define LDD_USER(ptr) BUILD_BUG()
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#define STD_KERNEL(x, ptr) __put_kernel_asm64(x,ptr)
46#define STD_USER(x, ptr) __put_user_asm64(x,ptr)
Helge Deller94a19812006-12-19 22:33:58 +010047#define ASM_WORD_INSN ".word\t"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#else
Helge Deller94a19812006-12-19 22:33:58 +010049#define LDD_KERNEL(ptr) __get_kernel_asm("ldd",ptr)
50#define LDD_USER(ptr) __get_user_asm("ldd",ptr)
51#define STD_KERNEL(x, ptr) __put_kernel_asm("std",x,ptr)
52#define STD_USER(x, ptr) __put_user_asm("std",x,ptr)
53#define ASM_WORD_INSN ".dword\t"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#endif
55
56/*
57 * The exception table contains two values: the first is an address
58 * for an instruction that is allowed to fault, and the second is
Helge Deller61dbbae2013-10-13 21:11:30 +020059 * the address to the fixup routine. Even on a 64bit kernel we could
60 * use a 32bit (unsigned int) address here.
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 */
62
63struct exception_table_entry {
Helge Deller61dbbae2013-10-13 21:11:30 +020064 unsigned long insn; /* address of insn that is allowed to fault. */
65 unsigned long fixup; /* fixup routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
67
Helge Deller0b3d6432007-01-28 14:52:57 +010068#define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\
69 ".section __ex_table,\"aw\"\n" \
70 ASM_WORD_INSN #fault_addr ", " #except_addr "\n\t" \
71 ".previous\n"
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/*
74 * The page fault handler stores, in a per-cpu area, the following information
75 * if a fixup routine is available.
76 */
77struct exception_data {
78 unsigned long fault_ip;
79 unsigned long fault_space;
80 unsigned long fault_addr;
81};
82
83#define __get_user(x,ptr) \
84({ \
85 register long __gu_err __asm__ ("r8") = 0; \
86 register long __gu_val __asm__ ("r9") = 0; \
87 \
88 if (segment_eq(get_fs(),KERNEL_DS)) { \
89 switch (sizeof(*(ptr))) { \
90 case 1: __get_kernel_asm("ldb",ptr); break; \
91 case 2: __get_kernel_asm("ldh",ptr); break; \
92 case 4: __get_kernel_asm("ldw",ptr); break; \
93 case 8: LDD_KERNEL(ptr); break; \
Helge Deller8dd95c62014-10-21 21:29:09 +020094 default: BUILD_BUG(); break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 } \
96 } \
97 else { \
98 switch (sizeof(*(ptr))) { \
99 case 1: __get_user_asm("ldb",ptr); break; \
100 case 2: __get_user_asm("ldh",ptr); break; \
101 case 4: __get_user_asm("ldw",ptr); break; \
102 case 8: LDD_USER(ptr); break; \
Helge Deller8dd95c62014-10-21 21:29:09 +0200103 default: BUILD_BUG(); break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 } \
105 } \
106 \
107 (x) = (__typeof__(*(ptr))) __gu_val; \
108 __gu_err; \
109})
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define __get_kernel_asm(ldx,ptr) \
Helge Deller0b3d6432007-01-28 14:52:57 +0100112 __asm__("\n1:\t" ldx "\t0(%2),%0\n\t" \
113 ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 : "=r"(__gu_val), "=r"(__gu_err) \
115 : "r"(ptr), "1"(__gu_err) \
116 : "r1");
117
118#define __get_user_asm(ldx,ptr) \
Helge Deller0b3d6432007-01-28 14:52:57 +0100119 __asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n\t" \
120 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_get_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 : "=r"(__gu_val), "=r"(__gu_err) \
122 : "r"(ptr), "1"(__gu_err) \
123 : "r1");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125#define __put_user(x,ptr) \
126({ \
127 register long __pu_err __asm__ ("r8") = 0; \
128 __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \
129 \
130 if (segment_eq(get_fs(),KERNEL_DS)) { \
131 switch (sizeof(*(ptr))) { \
132 case 1: __put_kernel_asm("stb",__x,ptr); break; \
133 case 2: __put_kernel_asm("sth",__x,ptr); break; \
134 case 4: __put_kernel_asm("stw",__x,ptr); break; \
135 case 8: STD_KERNEL(__x,ptr); break; \
Helge Deller8dd95c62014-10-21 21:29:09 +0200136 default: BUILD_BUG(); break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 } \
138 } \
139 else { \
140 switch (sizeof(*(ptr))) { \
141 case 1: __put_user_asm("stb",__x,ptr); break; \
142 case 2: __put_user_asm("sth",__x,ptr); break; \
143 case 4: __put_user_asm("stw",__x,ptr); break; \
144 case 8: STD_USER(__x,ptr); break; \
Helge Deller8dd95c62014-10-21 21:29:09 +0200145 default: BUILD_BUG(); break; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 } \
147 } \
148 \
149 __pu_err; \
150})
151
152/*
153 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
154 * instead of writing. This is because they do not write to any memory
Carlos O'Donell3fd3a742006-04-22 14:47:21 -0600155 * gcc knows about, so there are no aliasing issues. These macros must
156 * also be aware that "fixup_put_user_skip_[12]" are executed in the
157 * context of the fault, and any registers used there must be listed
158 * as clobbers. In this case only "r1" is used by the current routines.
159 * r8/r9 are already listed as err/val.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 */
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#define __put_kernel_asm(stx,x,ptr) \
163 __asm__ __volatile__ ( \
Helge Deller0b3d6432007-01-28 14:52:57 +0100164 "\n1:\t" stx "\t%2,0(%1)\n\t" \
165 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_put_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 : "=r"(__pu_err) \
Carlos O'Donell3fd3a742006-04-22 14:47:21 -0600167 : "r"(ptr), "r"(x), "0"(__pu_err) \
168 : "r1")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170#define __put_user_asm(stx,x,ptr) \
171 __asm__ __volatile__ ( \
Helge Deller0b3d6432007-01-28 14:52:57 +0100172 "\n1:\t" stx "\t%2,0(%%sr3,%1)\n\t" \
173 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_put_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 : "=r"(__pu_err) \
175 : "r"(ptr), "r"(x), "0"(__pu_err) \
176 : "r1")
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Helge Dellerca72a222006-12-20 00:35:57 +0100179#if !defined(CONFIG_64BIT)
Helge Deller94a19812006-12-19 22:33:58 +0100180
181#define __put_kernel_asm64(__val,ptr) do { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 __asm__ __volatile__ ( \
Helge Deller0b3d6432007-01-28 14:52:57 +0100183 "\n1:\tstw %2,0(%1)" \
Will Deacon0f28b622013-04-22 12:53:43 +0000184 "\n2:\tstw %R2,4(%1)\n\t" \
Helge Deller0b3d6432007-01-28 14:52:57 +0100185 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_put_user_skip_2)\
186 ASM_EXCEPTIONTABLE_ENTRY(2b,fixup_put_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 : "=r"(__pu_err) \
Will Deacon0f28b622013-04-22 12:53:43 +0000188 : "r"(ptr), "r"(__val), "0"(__pu_err) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 : "r1"); \
190} while (0)
191
Helge Deller94a19812006-12-19 22:33:58 +0100192#define __put_user_asm64(__val,ptr) do { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 __asm__ __volatile__ ( \
Helge Deller0b3d6432007-01-28 14:52:57 +0100194 "\n1:\tstw %2,0(%%sr3,%1)" \
Will Deacon0f28b622013-04-22 12:53:43 +0000195 "\n2:\tstw %R2,4(%%sr3,%1)\n\t" \
Helge Deller0b3d6432007-01-28 14:52:57 +0100196 ASM_EXCEPTIONTABLE_ENTRY(1b,fixup_put_user_skip_2)\
197 ASM_EXCEPTIONTABLE_ENTRY(2b,fixup_put_user_skip_1)\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 : "=r"(__pu_err) \
Will Deacon0f28b622013-04-22 12:53:43 +0000199 : "r"(ptr), "r"(__val), "0"(__pu_err) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 : "r1"); \
201} while (0)
202
Helge Dellerca72a222006-12-20 00:35:57 +0100203#endif /* !defined(CONFIG_64BIT) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205
206/*
207 * Complex access routines -- external declarations
208 */
209
210extern unsigned long lcopy_to_user(void __user *, const void *, unsigned long);
211extern unsigned long lcopy_from_user(void *, const void __user *, unsigned long);
212extern unsigned long lcopy_in_user(void __user *, const void __user *, unsigned long);
James Bottomleyb1195c02012-05-26 09:48:19 +0100213extern long strncpy_from_user(char *, const char __user *, long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214extern unsigned lclear_user(void __user *,unsigned long);
215extern long lstrnlen_user(const char __user *,long);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216/*
217 * Complex access routines -- macros
218 */
Helge Dellera0ffa8f2013-11-19 23:31:35 +0100219#define user_addr_max() (~0UL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define strnlen_user lstrnlen_user
222#define strlen_user(str) lstrnlen_user(str, 0x7fffffffL)
223#define clear_user lclear_user
224#define __clear_user lclear_user
225
226unsigned long copy_to_user(void __user *dst, const void *src, unsigned long len);
227#define __copy_to_user copy_to_user
Helge Deller888c31f2010-02-01 19:56:33 +0000228unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229unsigned long copy_in_user(void __user *dst, const void __user *src, unsigned long len);
230#define __copy_in_user copy_in_user
231#define __copy_to_user_inatomic __copy_to_user
232#define __copy_from_user_inatomic __copy_from_user
233
Helge Deller888c31f2010-02-01 19:56:33 +0000234extern void copy_from_user_overflow(void)
235#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
236 __compiletime_error("copy_from_user() buffer size is not provably correct")
237#else
238 __compiletime_warning("copy_from_user() buffer size is not provably correct")
239#endif
240;
241
242static inline unsigned long __must_check copy_from_user(void *to,
243 const void __user *from,
244 unsigned long n)
245{
246 int sz = __compiletime_object_size(to);
247 int ret = -EFAULT;
248
249 if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
250 ret = __copy_from_user(to, from, n);
251 else
252 copy_from_user_overflow();
253
254 return ret;
255}
256
Helge Dellere4483722009-01-13 20:52:46 +0100257struct pt_regs;
Kyle McMartinc61c25e2008-12-20 02:29:06 +0000258int fixup_exception(struct pt_regs *regs);
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#endif /* __PARISC_UACCESS_H */