uaccess.h 21 KB

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