uaccess.h 9.8 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8 9 10
#ifndef __PARISC_UACCESS_H
#define __PARISC_UACCESS_H

/*
 * User space memory access functions
 */
#include <linux/sched.h>
#include <asm/page.h>
#include <asm/system.h>
#include <asm/cache.h>
11
#include <asm-generic/uaccess.h>
Linus Torvalds's avatar
Linus Torvalds committed
12 13 14 15 16 17 18 19 20 21

#define VERIFY_READ 0
#define VERIFY_WRITE 1

#define KERNEL_DS	((mm_segment_t){0})
#define USER_DS 	((mm_segment_t){1})

#define segment_eq(a,b)	((a).seg == (b).seg)

#define get_ds()	(KERNEL_DS)
Matthew Wilcox's avatar
Matthew Wilcox committed
22 23
#define get_fs()	(current_thread_info()->addr_limit)
#define set_fs(x)	(current_thread_info()->addr_limit = (x))
Linus Torvalds's avatar
Linus Torvalds committed
24 25 26 27 28 29 30 31

/*
 * Note that since kernel addresses are in a separate address space on
 * parisc, we don't need to do anything for access_ok() or verify_area().
 * We just let the page fault handler do the right thing. This also means
 * that put_user is the same as __put_user, etc.
 */

32 33 34 35 36
extern int __get_kernel_bad(void);
extern int __get_user_bad(void);
extern int __put_kernel_bad(void);
extern int __put_user_bad(void);

Linus Torvalds's avatar
Linus Torvalds committed
37 38 39 40 41 42
#define access_ok(type,addr,size)   (1)
#define verify_area(type,addr,size) (0)

#define put_user __put_user
#define get_user __get_user

Matthew Wilcox's avatar
Matthew Wilcox committed
43
#if BITS_PER_LONG == 32
44 45 46 47
#define LDD_KERNEL(ptr)		__get_kernel_bad();
#define LDD_USER(ptr)		__get_user_bad();
#define STD_KERNEL(x, ptr)	__put_kernel_asm64(x,ptr)
#define STD_USER(x, ptr)	__put_user_asm64(x,ptr)
Matthew Wilcox's avatar
Matthew Wilcox committed
48 49 50 51 52 53 54
#else
#define LDD_KERNEL(ptr) __get_kernel_asm("ldd",ptr)
#define LDD_USER(ptr) __get_user_asm("ldd",ptr)
#define STD_KERNEL(x, ptr) __put_kernel_asm("std",x,ptr)
#define STD_USER(x, ptr) __put_user_asm("std",x,ptr)
#endif

Linus Torvalds's avatar
Linus Torvalds committed
55 56 57 58 59 60 61 62 63 64 65
/*
 * The exception table contains two values: the first is an address
 * for an instruction that is allowed to fault, and the second is
 * the number of bytes to skip if a fault occurs. We also support in
 * two bit flags: 0x2 tells the exception handler to clear register
 * r9 and 0x1 tells the exception handler to put -EFAULT in r8.
 * This allows us to handle the simple cases for put_user and
 * get_user without having to have .fixup sections.
 */

struct exception_table_entry {
66
	unsigned long insn;  /* address of insn that is allowed to fault.   */
Matthew Wilcox's avatar
Matthew Wilcox committed
67
	long skip;           /* pcoq skip | r9 clear flag | r8 -EFAULT flag */
Linus Torvalds's avatar
Linus Torvalds committed
68 69 70 71 72 73 74 75 76 77 78 79
};

#define __get_user(x,ptr)                               \
({                                                      \
	register long __gu_err __asm__ ("r8") = 0;      \
	register long __gu_val __asm__ ("r9") = 0;      \
							\
	if (segment_eq(get_fs(),KERNEL_DS)) {           \
	    switch (sizeof(*(ptr))) {                   \
	    case 1: __get_kernel_asm("ldb",ptr); break; \
	    case 2: __get_kernel_asm("ldh",ptr); break; \
	    case 4: __get_kernel_asm("ldw",ptr); break; \
Matthew Wilcox's avatar
Matthew Wilcox committed
80
	    case 8: LDD_KERNEL(ptr); break;		\
81
	    default: __get_kernel_bad(); break;         \
Linus Torvalds's avatar
Linus Torvalds committed
82 83 84 85 86 87 88
	    }                                           \
	}                                               \
	else {                                          \
	    switch (sizeof(*(ptr))) {                   \
	    case 1: __get_user_asm("ldb",ptr); break;   \
	    case 2: __get_user_asm("ldh",ptr); break;   \
	    case 4: __get_user_asm("ldw",ptr); break;   \
Matthew Wilcox's avatar
Matthew Wilcox committed
89
	    case 8: LDD_USER(ptr);  break;		\
90
	    default: __get_user_bad(); break;           \
Linus Torvalds's avatar
Linus Torvalds committed
91 92 93 94 95 96 97
	    }                                           \
	}                                               \
							\
	(x) = (__typeof__(*(ptr))) __gu_val;            \
	__gu_err;                                       \
})

Matthew Wilcox's avatar
Matthew Wilcox committed
98 99 100 101
#ifdef __LP64__
#define __get_kernel_asm(ldx,ptr)                       \
	__asm__("\n1:\t" ldx "\t0(%2),%0\n"             \
		"2:\n"					\
102
		"\t.section __ex_table,\"aw\"\n"         \
Matthew Wilcox's avatar
Matthew Wilcox committed
103 104 105 106 107 108 109 110 111
		 "\t.dword\t1b\n"                       \
		 "\t.dword\t(2b-1b)+3\n"                \
		 "\t.previous"                          \
		: "=r"(__gu_val), "=r"(__gu_err)        \
		: "r"(ptr), "1"(__gu_err));

#define __get_user_asm(ldx,ptr)                         \
	__asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n"       \
		"2:\n"					\
112
		"\t.section __ex_table,\"aw\"\n"         \
Matthew Wilcox's avatar
Matthew Wilcox committed
113 114 115 116 117 118
		 "\t.dword\t1b\n"                       \
		 "\t.dword\t(2b-1b)+3\n"                \
		 "\t.previous"                          \
		: "=r"(__gu_val), "=r"(__gu_err)        \
		: "r"(ptr), "1"(__gu_err));
#else
Linus Torvalds's avatar
Linus Torvalds committed
119 120 121
#define __get_kernel_asm(ldx,ptr)                       \
	__asm__("\n1:\t" ldx "\t0(%2),%0\n"             \
		"2:\n"					\
122
		"\t.section __ex_table,\"aw\"\n"         \
Linus Torvalds's avatar
Linus Torvalds committed
123 124 125 126 127 128 129 130 131
		 "\t.word\t1b\n"                        \
		 "\t.word\t(2b-1b)+3\n"                 \
		 "\t.previous"                          \
		: "=r"(__gu_val), "=r"(__gu_err)        \
		: "r"(ptr), "1"(__gu_err));

#define __get_user_asm(ldx,ptr)                         \
	__asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n"       \
		"2:\n"					\
132
		"\t.section __ex_table,\"aw\"\n"         \
Linus Torvalds's avatar
Linus Torvalds committed
133 134 135 136 137
		 "\t.word\t1b\n"                        \
		 "\t.word\t(2b-1b)+3\n"                 \
		 "\t.previous"                          \
		: "=r"(__gu_val), "=r"(__gu_err)        \
		: "r"(ptr), "1"(__gu_err));
138
#endif /* !__LP64__ */
Linus Torvalds's avatar
Linus Torvalds committed
139 140 141 142 143 144 145 146 147 148

#define __put_user(x,ptr)                                       \
({								\
	register long __pu_err __asm__ ("r8") = 0;		\
								\
	if (segment_eq(get_fs(),KERNEL_DS)) {                   \
	    switch (sizeof(*(ptr))) {                           \
	    case 1: __put_kernel_asm("stb",x,ptr); break;       \
	    case 2: __put_kernel_asm("sth",x,ptr); break;       \
	    case 4: __put_kernel_asm("stw",x,ptr); break;       \
Matthew Wilcox's avatar
Matthew Wilcox committed
149
	    case 8: STD_KERNEL(x,ptr); break;			\
150
	    default: __put_kernel_bad(); break;			\
Linus Torvalds's avatar
Linus Torvalds committed
151 152 153 154 155 156 157
	    }                                                   \
	}                                                       \
	else {                                                  \
	    switch (sizeof(*(ptr))) {                           \
	    case 1: __put_user_asm("stb",x,ptr); break;         \
	    case 2: __put_user_asm("sth",x,ptr); break;         \
	    case 4: __put_user_asm("stw",x,ptr); break;         \
Matthew Wilcox's avatar
Matthew Wilcox committed
158
	    case 8: STD_USER(x,ptr); break;			\
159
	    default: __put_user_bad(); break;			\
Linus Torvalds's avatar
Linus Torvalds committed
160 161 162 163 164 165 166 167 168 169 170 171
	    }                                                   \
	}                                                       \
								\
	__pu_err;						\
})

/*
 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
 * instead of writing. This is because they do not write to any memory
 * gcc knows about, so there are no aliasing issues.
 */

Matthew Wilcox's avatar
Matthew Wilcox committed
172 173 174 175 176
#ifdef __LP64__
#define __put_kernel_asm(stx,x,ptr)                         \
	__asm__ __volatile__ (                              \
		"\n1:\t" stx "\t%2,0(%1)\n"                 \
		"2:\n"					    \
177
		"\t.section __ex_table,\"aw\"\n"             \
Matthew Wilcox's avatar
Matthew Wilcox committed
178 179 180 181 182 183 184 185 186 187
		 "\t.dword\t1b\n"                           \
		 "\t.dword\t(2b-1b)+1\n"                    \
		 "\t.previous"                              \
		: "=r"(__pu_err)                            \
		: "r"(ptr), "r"(x), "0"(__pu_err))

#define __put_user_asm(stx,x,ptr)                           \
	__asm__ __volatile__ (                              \
		"\n1:\t" stx "\t%2,0(%%sr3,%1)\n"           \
		"2:\n"					    \
188
		"\t.section __ex_table,\"aw\"\n"             \
Matthew Wilcox's avatar
Matthew Wilcox committed
189 190 191 192 193 194
		 "\t.dword\t1b\n"                           \
		 "\t.dword\t(2b-1b)+1\n"                    \
		 "\t.previous"                              \
		: "=r"(__pu_err)                            \
		: "r"(ptr), "r"(x), "0"(__pu_err))
#else
Linus Torvalds's avatar
Linus Torvalds committed
195 196 197 198
#define __put_kernel_asm(stx,x,ptr)                         \
	__asm__ __volatile__ (                              \
		"\n1:\t" stx "\t%2,0(%1)\n"                 \
		"2:\n"					    \
199
		"\t.section __ex_table,\"aw\"\n"             \
Linus Torvalds's avatar
Linus Torvalds committed
200 201 202 203 204 205 206 207 208 209
		 "\t.word\t1b\n"                            \
		 "\t.word\t(2b-1b)+1\n"                     \
		 "\t.previous"                              \
		: "=r"(__pu_err)                            \
		: "r"(ptr), "r"(x), "0"(__pu_err))

#define __put_user_asm(stx,x,ptr)                           \
	__asm__ __volatile__ (                              \
		"\n1:\t" stx "\t%2,0(%%sr3,%1)\n"           \
		"2:\n"					    \
210
		"\t.section __ex_table,\"aw\"\n"             \
Linus Torvalds's avatar
Linus Torvalds committed
211 212 213 214 215 216
		 "\t.word\t1b\n"                            \
		 "\t.word\t(2b-1b)+1\n"                     \
		 "\t.previous"                              \
		: "=r"(__pu_err)                            \
		: "r"(ptr), "r"(x), "0"(__pu_err))

Matthew Wilcox's avatar
Matthew Wilcox committed
217 218 219 220 221 222 223 224
static inline void __put_kernel_asm64(u64 x, void *ptr)
{
	u32 hi = x>>32;
	u32 lo = x&0xffffffff;
	__asm__ __volatile__ (
		"\n1:\tstw %1,0(%0)\n"
		"\n2:\tstw %2,4(%0)\n"
		"3:\n"
225
		"\t.section __ex_table,\"aw\"\n"
Matthew Wilcox's avatar
Matthew Wilcox committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
		 "\t.word\t1b\n"
		 "\t.word\t(3b-1b)+1\n"
		 "\t.word\t2b\n"
		 "\t.word\t(3b-2b)+1\n"
		 "\t.previous"
		: : "r"(ptr), "r"(hi), "r"(lo));

}

static inline void __put_user_asm64(u64 x, void *ptr)
{
	u32 hi = x>>32;
	u32 lo = x&0xffffffff;
	__asm__ __volatile__ (
		"\n1:\tstw %1,0(%%sr3,%0)\n"
		"\n2:\tstw %2,4(%%sr3,%0)\n"
		"3:\n"
243
		"\t.section __ex_table,\"aw\"\n"
Matthew Wilcox's avatar
Matthew Wilcox committed
244 245 246 247 248 249 250 251 252
		 "\t.word\t1b\n"
		 "\t.word\t(3b-1b)+1\n"
		 "\t.word\t2b\n"
		 "\t.word\t(3b-2b)+1\n"
		 "\t.previous"
		: : "r"(ptr), "r"(hi), "r"(lo));

}

253
#endif /* !__LP64__ */
Matthew Wilcox's avatar
Matthew Wilcox committed
254

Linus Torvalds's avatar
Linus Torvalds committed
255 256 257 258 259

/*
 * Complex access routines -- external declarations
 */

260 261 262 263 264 265
extern unsigned long lcopy_to_user(void __user *, const void *, unsigned long);
extern unsigned long lcopy_from_user(void *, const void __user *, unsigned long);
extern unsigned long lcopy_in_user(void __user *, const void __user *, unsigned long);
extern long lstrncpy_from_user(char *, const char __user *, long);
extern unsigned lclear_user(void __user *,unsigned long);
extern long lstrnlen_user(const char __user *,long);
Linus Torvalds's avatar
Linus Torvalds committed
266 267 268 269 270 271 272 273 274

/*
 * Complex access routines -- macros
 */

#define strncpy_from_user lstrncpy_from_user
#define strnlen_user lstrnlen_user
#define strlen_user(str) lstrnlen_user(str, 0x7fffffffL)
#define clear_user lclear_user
Matthew Wilcox's avatar
Matthew Wilcox committed
275
#define __clear_user lclear_user
Linus Torvalds's avatar
Linus Torvalds committed
276 277 278 279 280

#define copy_from_user lcopy_from_user
#define __copy_from_user lcopy_from_user
#define copy_to_user lcopy_to_user
#define __copy_to_user lcopy_to_user
281 282
#define copy_in_user lcopy_in_user
#define __copy_in_user lcopy_in_user
283 284
#define __copy_to_user_inatomic __copy_to_user
#define __copy_from_user_inatomic __copy_from_user
Linus Torvalds's avatar
Linus Torvalds committed
285 286

#endif /* __PARISC_UACCESS_H */