uaccess.h 23 KB

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