Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _ASM_M32R_UACCESS_H |
| 2 | #define _ASM_M32R_UACCESS_H |
| 3 | |
| 4 | /* |
| 5 | * linux/include/asm-m32r/uaccess.h |
| 6 | * |
| 7 | * M32R version. |
| 8 | * Copyright (C) 2004 Hirokazu Takata <takata at linux-m32r.org> |
| 9 | */ |
| 10 | |
| 11 | #undef UACCESS_DEBUG |
| 12 | |
| 13 | #ifdef UACCESS_DEBUG |
| 14 | #define UAPRINTK(args...) printk(args) |
| 15 | #else |
| 16 | #define UAPRINTK(args...) |
| 17 | #endif /* UACCESS_DEBUG */ |
| 18 | |
| 19 | /* |
| 20 | * User space memory access functions |
| 21 | */ |
| 22 | #include <linux/config.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/thread_info.h> |
| 25 | #include <asm/page.h> |
| 26 | |
| 27 | #define VERIFY_READ 0 |
| 28 | #define VERIFY_WRITE 1 |
| 29 | |
| 30 | /* |
| 31 | * The fs value determines whether argument validity checking should be |
| 32 | * performed or not. If get_fs() == USER_DS, checking is performed, with |
| 33 | * get_fs() == KERNEL_DS, checking is bypassed. |
| 34 | * |
| 35 | * For historical reasons, these macros are grossly misnamed. |
| 36 | */ |
| 37 | |
| 38 | #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) |
| 39 | |
| 40 | #ifdef CONFIG_MMU |
| 41 | #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) |
| 42 | #define USER_DS MAKE_MM_SEG(PAGE_OFFSET) |
| 43 | #else |
| 44 | #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) |
| 45 | #define USER_DS MAKE_MM_SEG(0xFFFFFFFF) |
| 46 | #endif /* CONFIG_MMU */ |
| 47 | |
| 48 | #define get_ds() (KERNEL_DS) |
| 49 | #ifdef CONFIG_MMU |
| 50 | #define get_fs() (current_thread_info()->addr_limit) |
| 51 | #define set_fs(x) (current_thread_info()->addr_limit = (x)) |
| 52 | #else |
| 53 | static inline mm_segment_t get_fs(void) |
| 54 | { |
| 55 | return USER_DS; |
| 56 | } |
| 57 | |
| 58 | static inline void set_fs(mm_segment_t s) |
| 59 | { |
| 60 | } |
| 61 | #endif /* CONFIG_MMU */ |
| 62 | |
| 63 | #define segment_eq(a,b) ((a).seg == (b).seg) |
| 64 | |
| 65 | #define __addr_ok(addr) \ |
| 66 | ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg)) |
| 67 | |
| 68 | /* |
| 69 | * Test whether a block of memory is a valid user space address. |
| 70 | * Returns 0 if the range is valid, nonzero otherwise. |
| 71 | * |
| 72 | * This is equivalent to the following test: |
| 73 | * (u33)addr + (u33)size >= (u33)current->addr_limit.seg |
| 74 | * |
| 75 | * This needs 33-bit arithmetic. We have a carry... |
| 76 | */ |
| 77 | #define __range_ok(addr,size) ({ \ |
| 78 | unsigned long flag, sum; \ |
| 79 | __chk_user_ptr(addr); \ |
| 80 | asm ( \ |
| 81 | " cmpu %1, %1 ; clear cbit\n" \ |
| 82 | " addx %1, %3 ; set cbit if overflow\n" \ |
| 83 | " subx %0, %0\n" \ |
| 84 | " cmpu %4, %1\n" \ |
| 85 | " subx %0, %5\n" \ |
| 86 | : "=&r"(flag), "=r"(sum) \ |
| 87 | : "1"(addr), "r"((int)(size)), \ |
| 88 | "r"(current_thread_info()->addr_limit.seg), "r"(0) \ |
| 89 | : "cbit" ); \ |
| 90 | flag; }) |
| 91 | |
| 92 | /** |
| 93 | * access_ok: - Checks if a user space pointer is valid |
| 94 | * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that |
| 95 | * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe |
| 96 | * to write to a block, it is always safe to read from it. |
| 97 | * @addr: User space pointer to start of block to check |
| 98 | * @size: Size of block to check |
| 99 | * |
| 100 | * Context: User context only. This function may sleep. |
| 101 | * |
| 102 | * Checks if a pointer to a block of memory in user space is valid. |
| 103 | * |
| 104 | * Returns true (nonzero) if the memory block may be valid, false (zero) |
| 105 | * if it is definitely invalid. |
| 106 | * |
| 107 | * Note that, depending on architecture, this function probably just |
| 108 | * checks that the pointer is in the user space range - after calling |
| 109 | * this function, memory access functions may still return -EFAULT. |
| 110 | */ |
| 111 | #ifdef CONFIG_MMU |
| 112 | #define access_ok(type,addr,size) (likely(__range_ok(addr,size) == 0)) |
| 113 | #else |
| 114 | static inline int access_ok(int type, const void *addr, unsigned long size) |
| 115 | { |
| 116 | extern unsigned long memory_start, memory_end; |
| 117 | unsigned long val = (unsigned long)addr; |
| 118 | |
| 119 | return ((val >= memory_start) && ((val + size) < memory_end)); |
| 120 | } |
| 121 | #endif /* CONFIG_MMU */ |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* |
| 124 | * The exception table consists of pairs of addresses: the first is the |
| 125 | * address of an instruction that is allowed to fault, and the second is |
| 126 | * the address at which the program should continue. No registers are |
| 127 | * modified, so it is entirely up to the continuation code to figure out |
| 128 | * what to do. |
| 129 | * |
| 130 | * All the routines below use bits of fixup code that are out of line |
| 131 | * with the main instruction path. This means when everything is well, |
| 132 | * we don't even have to jump over them. Further, they do not intrude |
| 133 | * on our cache or tlb entries. |
| 134 | */ |
| 135 | |
| 136 | struct exception_table_entry |
| 137 | { |
| 138 | unsigned long insn, fixup; |
| 139 | }; |
| 140 | |
| 141 | extern int fixup_exception(struct pt_regs *regs); |
| 142 | |
| 143 | /* |
| 144 | * These are the main single-value transfer routines. They automatically |
| 145 | * use the right size if we just have the right pointer type. |
| 146 | * |
| 147 | * This gets kind of ugly. We want to return _two_ values in "get_user()" |
| 148 | * and yet we don't want to do any pointers, because that is too much |
| 149 | * of a performance impact. Thus we have a few rather ugly macros here, |
| 150 | * and hide all the uglyness from the user. |
| 151 | * |
| 152 | * The "__xxx" versions of the user access functions are versions that |
| 153 | * do not verify the address space, that must have been done previously |
| 154 | * with a separate "access_ok()" call (this is used when we do multiple |
| 155 | * accesses to the same area of user memory). |
| 156 | */ |
| 157 | |
| 158 | extern void __get_user_1(void); |
| 159 | extern void __get_user_2(void); |
| 160 | extern void __get_user_4(void); |
| 161 | |
| 162 | #ifndef MODULE |
| 163 | #define __get_user_x(size,ret,x,ptr) \ |
| 164 | __asm__ __volatile__( \ |
| 165 | " mv r0, %0\n" \ |
| 166 | " mv r1, %1\n" \ |
| 167 | " bl __get_user_" #size "\n" \ |
| 168 | " mv %0, r0\n" \ |
| 169 | " mv %1, r1\n" \ |
| 170 | : "=r"(ret), "=r"(x) \ |
| 171 | : "0"(ptr) \ |
| 172 | : "r0", "r1", "r14" ) |
| 173 | #else /* MODULE */ |
| 174 | /* |
| 175 | * Use "jl" instead of "bl" for MODULE |
| 176 | */ |
| 177 | #define __get_user_x(size,ret,x,ptr) \ |
| 178 | __asm__ __volatile__( \ |
| 179 | " mv r0, %0\n" \ |
| 180 | " mv r1, %1\n" \ |
| 181 | " seth lr, #high(__get_user_" #size ")\n" \ |
| 182 | " or3 lr, lr, #low(__get_user_" #size ")\n" \ |
| 183 | " jl lr\n" \ |
| 184 | " mv %0, r0\n" \ |
| 185 | " mv %1, r1\n" \ |
| 186 | : "=r"(ret), "=r"(x) \ |
| 187 | : "0"(ptr) \ |
| 188 | : "r0", "r1", "r14" ) |
| 189 | #endif |
| 190 | |
| 191 | /* Careful: we have to cast the result to the type of the pointer for sign |
| 192 | reasons */ |
| 193 | /** |
| 194 | * get_user: - Get a simple variable from user space. |
| 195 | * @x: Variable to store result. |
| 196 | * @ptr: Source address, in user space. |
| 197 | * |
| 198 | * Context: User context only. This function may sleep. |
| 199 | * |
| 200 | * This macro copies a single simple variable from user space to kernel |
| 201 | * space. It supports simple types like char and int, but not larger |
| 202 | * data types like structures or arrays. |
| 203 | * |
| 204 | * @ptr must have pointer-to-simple-variable type, and the result of |
| 205 | * dereferencing @ptr must be assignable to @x without a cast. |
| 206 | * |
| 207 | * Returns zero on success, or -EFAULT on error. |
| 208 | * On error, the variable @x is set to zero. |
| 209 | */ |
| 210 | #define get_user(x,ptr) \ |
Al Viro | a880948 | 2005-09-26 06:19:28 +0100 | [diff] [blame] | 211 | ({ int __ret_gu; \ |
| 212 | unsigned long __val_gu; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | __chk_user_ptr(ptr); \ |
| 214 | switch(sizeof (*(ptr))) { \ |
| 215 | case 1: __get_user_x(1,__ret_gu,__val_gu,ptr); break; \ |
| 216 | case 2: __get_user_x(2,__ret_gu,__val_gu,ptr); break; \ |
| 217 | case 4: __get_user_x(4,__ret_gu,__val_gu,ptr); break; \ |
| 218 | default: __get_user_x(X,__ret_gu,__val_gu,ptr); break; \ |
| 219 | } \ |
| 220 | (x) = (__typeof__(*(ptr)))__val_gu; \ |
| 221 | __ret_gu; \ |
| 222 | }) |
| 223 | |
| 224 | extern void __put_user_bad(void); |
| 225 | |
| 226 | /** |
| 227 | * put_user: - Write a simple value into user space. |
| 228 | * @x: Value to copy to user space. |
| 229 | * @ptr: Destination address, in user space. |
| 230 | * |
| 231 | * Context: User context only. This function may sleep. |
| 232 | * |
| 233 | * This macro copies a single simple value from kernel space to user |
| 234 | * space. It supports simple types like char and int, but not larger |
| 235 | * data types like structures or arrays. |
| 236 | * |
| 237 | * @ptr must have pointer-to-simple-variable type, and @x must be assignable |
| 238 | * to the result of dereferencing @ptr. |
| 239 | * |
| 240 | * Returns zero on success, or -EFAULT on error. |
| 241 | */ |
| 242 | #define put_user(x,ptr) \ |
| 243 | __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr))) |
| 244 | |
| 245 | |
| 246 | /** |
| 247 | * __get_user: - Get a simple variable from user space, with less checking. |
| 248 | * @x: Variable to store result. |
| 249 | * @ptr: Source address, in user space. |
| 250 | * |
| 251 | * Context: User context only. This function may sleep. |
| 252 | * |
| 253 | * This macro copies a single simple variable from user space to kernel |
| 254 | * space. It supports simple types like char and int, but not larger |
| 255 | * data types like structures or arrays. |
| 256 | * |
| 257 | * @ptr must have pointer-to-simple-variable type, and the result of |
| 258 | * dereferencing @ptr must be assignable to @x without a cast. |
| 259 | * |
| 260 | * Caller must check the pointer with access_ok() before calling this |
| 261 | * function. |
| 262 | * |
| 263 | * Returns zero on success, or -EFAULT on error. |
| 264 | * On error, the variable @x is set to zero. |
| 265 | */ |
| 266 | #define __get_user(x,ptr) \ |
| 267 | __get_user_nocheck((x),(ptr),sizeof(*(ptr))) |
| 268 | |
| 269 | |
| 270 | /** |
| 271 | * __put_user: - Write a simple value into user space, with less checking. |
| 272 | * @x: Value to copy to user space. |
| 273 | * @ptr: Destination address, in user space. |
| 274 | * |
| 275 | * Context: User context only. This function may sleep. |
| 276 | * |
| 277 | * This macro copies a single simple value from kernel space to user |
| 278 | * space. It supports simple types like char and int, but not larger |
| 279 | * data types like structures or arrays. |
| 280 | * |
| 281 | * @ptr must have pointer-to-simple-variable type, and @x must be assignable |
| 282 | * to the result of dereferencing @ptr. |
| 283 | * |
| 284 | * Caller must check the pointer with access_ok() before calling this |
| 285 | * function. |
| 286 | * |
| 287 | * Returns zero on success, or -EFAULT on error. |
| 288 | */ |
| 289 | #define __put_user(x,ptr) \ |
| 290 | __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr))) |
| 291 | |
| 292 | #define __put_user_nocheck(x,ptr,size) \ |
| 293 | ({ \ |
| 294 | long __pu_err; \ |
| 295 | __put_user_size((x),(ptr),(size),__pu_err); \ |
| 296 | __pu_err; \ |
| 297 | }) |
| 298 | |
| 299 | |
| 300 | #define __put_user_check(x,ptr,size) \ |
| 301 | ({ \ |
| 302 | long __pu_err = -EFAULT; \ |
| 303 | __typeof__(*(ptr)) __user *__pu_addr = (ptr); \ |
| 304 | might_sleep(); \ |
| 305 | if (access_ok(VERIFY_WRITE,__pu_addr,size)) \ |
| 306 | __put_user_size((x),__pu_addr,(size),__pu_err); \ |
| 307 | __pu_err; \ |
| 308 | }) |
| 309 | |
| 310 | #if defined(__LITTLE_ENDIAN__) |
| 311 | #define __put_user_u64(x, addr, err) \ |
| 312 | __asm__ __volatile__( \ |
| 313 | " .fillinsn\n" \ |
| 314 | "1: st %L1,@%2\n" \ |
| 315 | " .fillinsn\n" \ |
| 316 | "2: st %H1,@(4,%2)\n" \ |
| 317 | " .fillinsn\n" \ |
| 318 | "3:\n" \ |
| 319 | ".section .fixup,\"ax\"\n" \ |
| 320 | " .balign 4\n" \ |
| 321 | "4: ldi %0,%3\n" \ |
| 322 | " seth r14,#high(3b)\n" \ |
| 323 | " or3 r14,r14,#low(3b)\n" \ |
| 324 | " jmp r14\n" \ |
| 325 | ".previous\n" \ |
| 326 | ".section __ex_table,\"a\"\n" \ |
| 327 | " .balign 4\n" \ |
| 328 | " .long 1b,4b\n" \ |
| 329 | " .long 2b,4b\n" \ |
| 330 | ".previous" \ |
| 331 | : "=r"(err) \ |
| 332 | : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err) \ |
| 333 | : "r14", "memory") |
| 334 | |
| 335 | #elif defined(__BIG_ENDIAN__) |
| 336 | #define __put_user_u64(x, addr, err) \ |
| 337 | __asm__ __volatile__( \ |
| 338 | " .fillinsn\n" \ |
| 339 | "1: st %H1,@%2\n" \ |
| 340 | " .fillinsn\n" \ |
| 341 | "2: st %L1,@(4,%2)\n" \ |
| 342 | " .fillinsn\n" \ |
| 343 | "3:\n" \ |
| 344 | ".section .fixup,\"ax\"\n" \ |
| 345 | " .balign 4\n" \ |
| 346 | "4: ldi %0,%3\n" \ |
| 347 | " seth r14,#high(3b)\n" \ |
| 348 | " or3 r14,r14,#low(3b)\n" \ |
| 349 | " jmp r14\n" \ |
| 350 | ".previous\n" \ |
| 351 | ".section __ex_table,\"a\"\n" \ |
| 352 | " .balign 4\n" \ |
| 353 | " .long 1b,4b\n" \ |
| 354 | " .long 2b,4b\n" \ |
| 355 | ".previous" \ |
| 356 | : "=r"(err) \ |
| 357 | : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err) \ |
| 358 | : "r14", "memory") |
| 359 | #else |
| 360 | #error no endian defined |
| 361 | #endif |
| 362 | |
| 363 | #define __put_user_size(x,ptr,size,retval) \ |
| 364 | do { \ |
| 365 | retval = 0; \ |
| 366 | __chk_user_ptr(ptr); \ |
| 367 | switch (size) { \ |
| 368 | case 1: __put_user_asm(x,ptr,retval,"b"); break; \ |
| 369 | case 2: __put_user_asm(x,ptr,retval,"h"); break; \ |
| 370 | case 4: __put_user_asm(x,ptr,retval,""); break; \ |
| 371 | case 8: __put_user_u64((__typeof__(*ptr))(x),ptr,retval); break;\ |
| 372 | default: __put_user_bad(); \ |
| 373 | } \ |
| 374 | } while (0) |
| 375 | |
| 376 | struct __large_struct { unsigned long buf[100]; }; |
| 377 | #define __m(x) (*(struct __large_struct *)(x)) |
| 378 | |
| 379 | /* |
| 380 | * Tell gcc we read from memory instead of writing: this is because |
| 381 | * we do not write to any memory gcc knows about, so there are no |
| 382 | * aliasing issues. |
| 383 | */ |
| 384 | #define __put_user_asm(x, addr, err, itype) \ |
| 385 | __asm__ __volatile__( \ |
| 386 | " .fillinsn\n" \ |
| 387 | "1: st"itype" %1,@%2\n" \ |
| 388 | " .fillinsn\n" \ |
| 389 | "2:\n" \ |
| 390 | ".section .fixup,\"ax\"\n" \ |
| 391 | " .balign 4\n" \ |
| 392 | "3: ldi %0,%3\n" \ |
| 393 | " seth r14,#high(2b)\n" \ |
| 394 | " or3 r14,r14,#low(2b)\n" \ |
| 395 | " jmp r14\n" \ |
| 396 | ".previous\n" \ |
| 397 | ".section __ex_table,\"a\"\n" \ |
| 398 | " .balign 4\n" \ |
| 399 | " .long 1b,3b\n" \ |
| 400 | ".previous" \ |
| 401 | : "=r"(err) \ |
| 402 | : "r"(x), "r"(addr), "i"(-EFAULT), "0"(err) \ |
| 403 | : "r14", "memory") |
| 404 | |
| 405 | #define __get_user_nocheck(x,ptr,size) \ |
| 406 | ({ \ |
Al Viro | a880948 | 2005-09-26 06:19:28 +0100 | [diff] [blame] | 407 | long __gu_err; \ |
| 408 | unsigned long __gu_val; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | __get_user_size(__gu_val,(ptr),(size),__gu_err); \ |
| 410 | (x) = (__typeof__(*(ptr)))__gu_val; \ |
| 411 | __gu_err; \ |
| 412 | }) |
| 413 | |
| 414 | extern long __get_user_bad(void); |
| 415 | |
| 416 | #define __get_user_size(x,ptr,size,retval) \ |
| 417 | do { \ |
| 418 | retval = 0; \ |
| 419 | __chk_user_ptr(ptr); \ |
| 420 | switch (size) { \ |
| 421 | case 1: __get_user_asm(x,ptr,retval,"ub"); break; \ |
| 422 | case 2: __get_user_asm(x,ptr,retval,"uh"); break; \ |
| 423 | case 4: __get_user_asm(x,ptr,retval,""); break; \ |
| 424 | default: (x) = __get_user_bad(); \ |
| 425 | } \ |
| 426 | } while (0) |
| 427 | |
| 428 | #define __get_user_asm(x, addr, err, itype) \ |
| 429 | __asm__ __volatile__( \ |
| 430 | " .fillinsn\n" \ |
| 431 | "1: ld"itype" %1,@%2\n" \ |
| 432 | " .fillinsn\n" \ |
| 433 | "2:\n" \ |
| 434 | ".section .fixup,\"ax\"\n" \ |
| 435 | " .balign 4\n" \ |
| 436 | "3: ldi %0,%3\n" \ |
| 437 | " seth r14,#high(2b)\n" \ |
| 438 | " or3 r14,r14,#low(2b)\n" \ |
| 439 | " jmp r14\n" \ |
| 440 | ".previous\n" \ |
| 441 | ".section __ex_table,\"a\"\n" \ |
| 442 | " .balign 4\n" \ |
| 443 | " .long 1b,3b\n" \ |
| 444 | ".previous" \ |
| 445 | : "=r"(err), "=&r"(x) \ |
| 446 | : "r"(addr), "i"(-EFAULT), "0"(err) \ |
| 447 | : "r14", "memory") |
| 448 | |
| 449 | /* |
| 450 | * Here we special-case 1, 2 and 4-byte copy_*_user invocations. On a fault |
| 451 | * we return the initial request size (1, 2 or 4), as copy_*_user should do. |
| 452 | * If a store crosses a page boundary and gets a fault, the m32r will not write |
| 453 | * anything, so this is accurate. |
| 454 | */ |
| 455 | |
| 456 | |
| 457 | /* |
| 458 | * Copy To/From Userspace |
| 459 | */ |
| 460 | |
| 461 | /* Generic arbitrary sized copy. */ |
| 462 | /* Return the number of bytes NOT copied. */ |
| 463 | #define __copy_user(to,from,size) \ |
| 464 | do { \ |
| 465 | unsigned long __dst, __src, __c; \ |
| 466 | __asm__ __volatile__ ( \ |
| 467 | " mv r14, %0\n" \ |
| 468 | " or r14, %1\n" \ |
| 469 | " beq %0, %1, 9f\n" \ |
| 470 | " beqz %2, 9f\n" \ |
| 471 | " and3 r14, r14, #3\n" \ |
| 472 | " bnez r14, 2f\n" \ |
| 473 | " and3 %2, %2, #3\n" \ |
| 474 | " beqz %3, 2f\n" \ |
| 475 | " addi %0, #-4 ; word_copy \n" \ |
| 476 | " .fillinsn\n" \ |
| 477 | "0: ld r14, @%1+\n" \ |
| 478 | " addi %3, #-1\n" \ |
| 479 | " .fillinsn\n" \ |
| 480 | "1: st r14, @+%0\n" \ |
| 481 | " bnez %3, 0b\n" \ |
| 482 | " beqz %2, 9f\n" \ |
| 483 | " addi %0, #4\n" \ |
| 484 | " .fillinsn\n" \ |
| 485 | "2: ldb r14, @%1 ; byte_copy \n" \ |
| 486 | " .fillinsn\n" \ |
| 487 | "3: stb r14, @%0\n" \ |
| 488 | " addi %1, #1\n" \ |
| 489 | " addi %2, #-1\n" \ |
| 490 | " addi %0, #1\n" \ |
| 491 | " bnez %2, 2b\n" \ |
| 492 | " .fillinsn\n" \ |
| 493 | "9:\n" \ |
| 494 | ".section .fixup,\"ax\"\n" \ |
| 495 | " .balign 4\n" \ |
| 496 | "5: addi %3, #1\n" \ |
| 497 | " addi %1, #-4\n" \ |
| 498 | " .fillinsn\n" \ |
| 499 | "6: slli %3, #2\n" \ |
| 500 | " add %2, %3\n" \ |
| 501 | " addi %0, #4\n" \ |
| 502 | " .fillinsn\n" \ |
| 503 | "7: seth r14, #high(9b)\n" \ |
| 504 | " or3 r14, r14, #low(9b)\n" \ |
| 505 | " jmp r14\n" \ |
| 506 | ".previous\n" \ |
| 507 | ".section __ex_table,\"a\"\n" \ |
| 508 | " .balign 4\n" \ |
| 509 | " .long 0b,6b\n" \ |
| 510 | " .long 1b,5b\n" \ |
| 511 | " .long 2b,9b\n" \ |
| 512 | " .long 3b,9b\n" \ |
| 513 | ".previous\n" \ |
| 514 | : "=&r"(__dst), "=&r"(__src), "=&r"(size), "=&r"(__c) \ |
| 515 | : "0"(to), "1"(from), "2"(size), "3"(size / 4) \ |
| 516 | : "r14", "memory"); \ |
| 517 | } while (0) |
| 518 | |
| 519 | #define __copy_user_zeroing(to,from,size) \ |
| 520 | do { \ |
| 521 | unsigned long __dst, __src, __c; \ |
| 522 | __asm__ __volatile__ ( \ |
| 523 | " mv r14, %0\n" \ |
| 524 | " or r14, %1\n" \ |
| 525 | " beq %0, %1, 9f\n" \ |
| 526 | " beqz %2, 9f\n" \ |
| 527 | " and3 r14, r14, #3\n" \ |
| 528 | " bnez r14, 2f\n" \ |
| 529 | " and3 %2, %2, #3\n" \ |
| 530 | " beqz %3, 2f\n" \ |
| 531 | " addi %0, #-4 ; word_copy \n" \ |
| 532 | " .fillinsn\n" \ |
| 533 | "0: ld r14, @%1+\n" \ |
| 534 | " addi %3, #-1\n" \ |
| 535 | " .fillinsn\n" \ |
| 536 | "1: st r14, @+%0\n" \ |
| 537 | " bnez %3, 0b\n" \ |
| 538 | " beqz %2, 9f\n" \ |
| 539 | " addi %0, #4\n" \ |
| 540 | " .fillinsn\n" \ |
| 541 | "2: ldb r14, @%1 ; byte_copy \n" \ |
| 542 | " .fillinsn\n" \ |
| 543 | "3: stb r14, @%0\n" \ |
| 544 | " addi %1, #1\n" \ |
| 545 | " addi %2, #-1\n" \ |
| 546 | " addi %0, #1\n" \ |
| 547 | " bnez %2, 2b\n" \ |
| 548 | " .fillinsn\n" \ |
| 549 | "9:\n" \ |
| 550 | ".section .fixup,\"ax\"\n" \ |
| 551 | " .balign 4\n" \ |
| 552 | "5: addi %3, #1\n" \ |
| 553 | " addi %1, #-4\n" \ |
| 554 | " .fillinsn\n" \ |
| 555 | "6: slli %3, #2\n" \ |
| 556 | " add %2, %3\n" \ |
| 557 | " addi %0, #4\n" \ |
| 558 | " .fillinsn\n" \ |
| 559 | "7: ldi r14, #0 ; store zero \n" \ |
| 560 | " .fillinsn\n" \ |
| 561 | "8: addi %2, #-1\n" \ |
| 562 | " stb r14, @%0 ; ACE? \n" \ |
| 563 | " addi %0, #1\n" \ |
| 564 | " bnez %2, 8b\n" \ |
| 565 | " seth r14, #high(9b)\n" \ |
| 566 | " or3 r14, r14, #low(9b)\n" \ |
| 567 | " jmp r14\n" \ |
| 568 | ".previous\n" \ |
| 569 | ".section __ex_table,\"a\"\n" \ |
| 570 | " .balign 4\n" \ |
| 571 | " .long 0b,6b\n" \ |
| 572 | " .long 1b,5b\n" \ |
| 573 | " .long 2b,7b\n" \ |
| 574 | " .long 3b,7b\n" \ |
| 575 | ".previous\n" \ |
| 576 | : "=&r"(__dst), "=&r"(__src), "=&r"(size), "=&r"(__c) \ |
| 577 | : "0"(to), "1"(from), "2"(size), "3"(size / 4) \ |
| 578 | : "r14", "memory"); \ |
| 579 | } while (0) |
| 580 | |
| 581 | |
| 582 | /* We let the __ versions of copy_from/to_user inline, because they're often |
| 583 | * used in fast paths and have only a small space overhead. |
| 584 | */ |
| 585 | static inline unsigned long __generic_copy_from_user_nocheck(void *to, |
| 586 | const void __user *from, unsigned long n) |
| 587 | { |
| 588 | __copy_user_zeroing(to,from,n); |
| 589 | return n; |
| 590 | } |
| 591 | |
| 592 | static inline unsigned long __generic_copy_to_user_nocheck(void __user *to, |
| 593 | const void *from, unsigned long n) |
| 594 | { |
| 595 | __copy_user(to,from,n); |
| 596 | return n; |
| 597 | } |
| 598 | |
Al Viro | a880948 | 2005-09-26 06:19:28 +0100 | [diff] [blame] | 599 | unsigned long __generic_copy_to_user(void __user *, const void *, unsigned long); |
| 600 | unsigned long __generic_copy_from_user(void *, const void __user *, unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | /** |
| 603 | * __copy_to_user: - Copy a block of data into user space, with less checking. |
| 604 | * @to: Destination address, in user space. |
| 605 | * @from: Source address, in kernel space. |
| 606 | * @n: Number of bytes to copy. |
| 607 | * |
| 608 | * Context: User context only. This function may sleep. |
| 609 | * |
| 610 | * Copy data from kernel space to user space. Caller must check |
| 611 | * the specified block with access_ok() before calling this function. |
| 612 | * |
| 613 | * Returns number of bytes that could not be copied. |
| 614 | * On success, this will be zero. |
| 615 | */ |
| 616 | #define __copy_to_user(to,from,n) \ |
| 617 | __generic_copy_to_user_nocheck((to),(from),(n)) |
| 618 | |
| 619 | #define __copy_to_user_inatomic __copy_to_user |
| 620 | #define __copy_from_user_inatomic __copy_from_user |
| 621 | |
| 622 | /** |
| 623 | * copy_to_user: - Copy a block of data into user space. |
| 624 | * @to: Destination address, in user space. |
| 625 | * @from: Source address, in kernel space. |
| 626 | * @n: Number of bytes to copy. |
| 627 | * |
| 628 | * Context: User context only. This function may sleep. |
| 629 | * |
| 630 | * Copy data from kernel space to user space. |
| 631 | * |
| 632 | * Returns number of bytes that could not be copied. |
| 633 | * On success, this will be zero. |
| 634 | */ |
| 635 | #define copy_to_user(to,from,n) \ |
| 636 | ({ \ |
| 637 | might_sleep(); \ |
| 638 | __generic_copy_to_user((to),(from),(n)); \ |
| 639 | }) |
| 640 | |
| 641 | /** |
| 642 | * __copy_from_user: - Copy a block of data from user space, with less checking. * @to: Destination address, in kernel space. |
| 643 | * @from: Source address, in user space. |
| 644 | * @n: Number of bytes to copy. |
| 645 | * |
| 646 | * Context: User context only. This function may sleep. |
| 647 | * |
| 648 | * Copy data from user space to kernel space. Caller must check |
| 649 | * the specified block with access_ok() before calling this function. |
| 650 | * |
| 651 | * Returns number of bytes that could not be copied. |
| 652 | * On success, this will be zero. |
| 653 | * |
| 654 | * If some data could not be copied, this function will pad the copied |
| 655 | * data to the requested size using zero bytes. |
| 656 | */ |
| 657 | #define __copy_from_user(to,from,n) \ |
| 658 | __generic_copy_from_user_nocheck((to),(from),(n)) |
| 659 | |
| 660 | /** |
| 661 | * copy_from_user: - Copy a block of data from user space. |
| 662 | * @to: Destination address, in kernel space. |
| 663 | * @from: Source address, in user space. |
| 664 | * @n: Number of bytes to copy. |
| 665 | * |
| 666 | * Context: User context only. This function may sleep. |
| 667 | * |
| 668 | * Copy data from user space to kernel space. |
| 669 | * |
| 670 | * Returns number of bytes that could not be copied. |
| 671 | * On success, this will be zero. |
| 672 | * |
| 673 | * If some data could not be copied, this function will pad the copied |
| 674 | * data to the requested size using zero bytes. |
| 675 | */ |
| 676 | #define copy_from_user(to,from,n) \ |
| 677 | ({ \ |
| 678 | might_sleep(); \ |
| 679 | __generic_copy_from_user((to),(from),(n)); \ |
| 680 | }) |
| 681 | |
| 682 | long __must_check strncpy_from_user(char *dst, const char __user *src, |
| 683 | long count); |
| 684 | long __must_check __strncpy_from_user(char *dst, |
| 685 | const char __user *src, long count); |
| 686 | |
| 687 | /** |
| 688 | * __clear_user: - Zero a block of memory in user space, with less checking. |
| 689 | * @to: Destination address, in user space. |
| 690 | * @n: Number of bytes to zero. |
| 691 | * |
| 692 | * Zero a block of memory in user space. Caller must check |
| 693 | * the specified block with access_ok() before calling this function. |
| 694 | * |
| 695 | * Returns number of bytes that could not be cleared. |
| 696 | * On success, this will be zero. |
| 697 | */ |
| 698 | unsigned long __clear_user(void __user *mem, unsigned long len); |
| 699 | |
| 700 | /** |
| 701 | * clear_user: - Zero a block of memory in user space. |
| 702 | * @to: Destination address, in user space. |
| 703 | * @n: Number of bytes to zero. |
| 704 | * |
| 705 | * Zero a block of memory in user space. Caller must check |
| 706 | * the specified block with access_ok() before calling this function. |
| 707 | * |
| 708 | * Returns number of bytes that could not be cleared. |
| 709 | * On success, this will be zero. |
| 710 | */ |
| 711 | unsigned long clear_user(void __user *mem, unsigned long len); |
| 712 | |
| 713 | /** |
| 714 | * strlen_user: - Get the size of a string in user space. |
| 715 | * @str: The string to measure. |
| 716 | * |
| 717 | * Context: User context only. This function may sleep. |
| 718 | * |
| 719 | * Get the size of a NUL-terminated string in user space. |
| 720 | * |
| 721 | * Returns the size of the string INCLUDING the terminating NUL. |
| 722 | * On exception, returns 0. |
| 723 | * |
| 724 | * If there is a limit on the length of a valid string, you may wish to |
| 725 | * consider using strnlen_user() instead. |
| 726 | */ |
| 727 | #define strlen_user(str) strnlen_user(str, ~0UL >> 1) |
| 728 | long strnlen_user(const char __user *str, long n); |
| 729 | |
| 730 | #endif /* _ASM_M32R_UACCESS_H */ |