uaccess.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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/errno.h>
  13. #include <linux/thread_info.h>
  14. #include <asm/page.h>
  15. #include <asm/setup.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, roksum; \
  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" (roksum) \
  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 if pagefaults are
  79. * enabled.
  80. *
  81. * Checks if a pointer to a block of memory in user space is valid.
  82. *
  83. * Returns true (nonzero) if the memory block may be valid, false (zero)
  84. * if it is definitely invalid.
  85. *
  86. * Note that, depending on architecture, this function probably just
  87. * checks that the pointer is in the user space range - after calling
  88. * this function, memory access functions may still return -EFAULT.
  89. */
  90. #ifdef CONFIG_MMU
  91. #define access_ok(type, addr, size) (likely(__range_ok(addr, size) == 0))
  92. #else
  93. static inline int access_ok(int type, const void *addr, unsigned long size)
  94. {
  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 if pagefaults are
  138. * enabled.
  139. *
  140. * This macro copies a single simple variable from user space to kernel
  141. * space. It supports simple types like char and int, but not larger
  142. * data types like structures or arrays.
  143. *
  144. * @ptr must have pointer-to-simple-variable type, and the result of
  145. * dereferencing @ptr must be assignable to @x without a cast.
  146. *
  147. * Returns zero on success, or -EFAULT on error.
  148. * On error, the variable @x is set to zero.
  149. */
  150. #define get_user(x, ptr) \
  151. __get_user_check((x), (ptr), sizeof(*(ptr)))
  152. /**
  153. * put_user: - Write a simple value into user space.
  154. * @x: Value to copy to user space.
  155. * @ptr: Destination address, in user space.
  156. *
  157. * Context: User context only. This function may sleep if pagefaults are
  158. * enabled.
  159. *
  160. * This macro copies a single simple value from kernel space to user
  161. * space. It supports simple types like char and int, but not larger
  162. * data types like structures or arrays.
  163. *
  164. * @ptr must have pointer-to-simple-variable type, and @x must be assignable
  165. * to the result of dereferencing @ptr.
  166. *
  167. * Returns zero on success, or -EFAULT on error.
  168. */
  169. #define put_user(x, ptr) \
  170. __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
  171. /**
  172. * __get_user: - Get a simple variable from user space, with less checking.
  173. * @x: Variable to store result.
  174. * @ptr: Source address, in user space.
  175. *
  176. * Context: User context only. This function may sleep if pagefaults are
  177. * enabled.
  178. *
  179. * This macro copies a single simple variable from user space to kernel
  180. * space. It supports simple types like char and int, but not larger
  181. * data types like structures or arrays.
  182. *
  183. * @ptr must have pointer-to-simple-variable type, and the result of
  184. * dereferencing @ptr must be assignable to @x without a cast.
  185. *
  186. * Caller must check the pointer with access_ok() before calling this
  187. * function.
  188. *
  189. * Returns zero on success, or -EFAULT on error.
  190. * On error, the variable @x is set to zero.
  191. */
  192. #define __get_user(x, ptr) \
  193. __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
  194. #define __get_user_nocheck(x, ptr, size) \
  195. ({ \
  196. long __gu_err = 0; \
  197. unsigned long __gu_val = 0; \
  198. might_fault(); \
  199. __get_user_size(__gu_val, (ptr), (size), __gu_err); \
  200. (x) = (__force __typeof__(*(ptr)))__gu_val; \
  201. __gu_err; \
  202. })
  203. #define __get_user_check(x, ptr, size) \
  204. ({ \
  205. long __gu_err = -EFAULT; \
  206. unsigned long __gu_val = 0; \
  207. const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
  208. might_fault(); \
  209. if (access_ok(VERIFY_READ, __gu_addr, size)) \
  210. __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
  211. (x) = (__force __typeof__(*(ptr)))__gu_val; \
  212. __gu_err; \
  213. })
  214. extern long __get_user_bad(void);
  215. #define __get_user_size(x, ptr, size, retval) \
  216. do { \
  217. retval = 0; \
  218. __chk_user_ptr(ptr); \
  219. switch (size) { \
  220. case 1: __get_user_asm(x, ptr, retval, "ub"); break; \
  221. case 2: __get_user_asm(x, ptr, retval, "uh"); break; \
  222. case 4: __get_user_asm(x, ptr, retval, ""); break; \
  223. default: (x) = __get_user_bad(); \
  224. } \
  225. } while (0)
  226. #define __get_user_asm(x, addr, err, itype) \
  227. __asm__ __volatile__( \
  228. " .fillinsn\n" \
  229. "1: ld"itype" %1,@%2\n" \
  230. " .fillinsn\n" \
  231. "2:\n" \
  232. ".section .fixup,\"ax\"\n" \
  233. " .balign 4\n" \
  234. "3: ldi %0,%3\n" \
  235. " seth r14,#high(2b)\n" \
  236. " or3 r14,r14,#low(2b)\n" \
  237. " jmp r14\n" \
  238. ".previous\n" \
  239. ".section __ex_table,\"a\"\n" \
  240. " .balign 4\n" \
  241. " .long 1b,3b\n" \
  242. ".previous" \
  243. : "=&r" (err), "=&r" (x) \
  244. : "r" (addr), "i" (-EFAULT), "0" (err) \
  245. : "r14", "memory")
  246. /**
  247. * __put_user: - Write a simple value into user space, with less checking.
  248. * @x: Value to copy to user space.
  249. * @ptr: Destination address, in user space.
  250. *
  251. * Context: User context only. This function may sleep if pagefaults are
  252. * enabled.
  253. *
  254. * This macro copies a single simple value from kernel space to user
  255. * space. It supports simple types like char and int, but not larger
  256. * data types like structures or arrays.
  257. *
  258. * @ptr must have pointer-to-simple-variable type, and @x must be assignable
  259. * to the result of dereferencing @ptr.
  260. *
  261. * Caller must check the pointer with access_ok() before calling this
  262. * function.
  263. *
  264. * Returns zero on success, or -EFAULT on error.
  265. */
  266. #define __put_user(x, ptr) \
  267. __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
  268. #define __put_user_nocheck(x, ptr, size) \
  269. ({ \
  270. long __pu_err; \
  271. might_fault(); \
  272. __put_user_size((x), (ptr), (size), __pu_err); \
  273. __pu_err; \
  274. })
  275. #define __put_user_check(x, ptr, size) \
  276. ({ \
  277. long __pu_err = -EFAULT; \
  278. __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
  279. might_fault(); \
  280. if (access_ok(VERIFY_WRITE, __pu_addr, size)) \
  281. __put_user_size((x), __pu_addr, (size), __pu_err); \
  282. __pu_err; \
  283. })
  284. #if defined(__LITTLE_ENDIAN__)
  285. #define __put_user_u64(x, addr, err) \
  286. __asm__ __volatile__( \
  287. " .fillinsn\n" \
  288. "1: st %L1,@%2\n" \
  289. " .fillinsn\n" \
  290. "2: st %H1,@(4,%2)\n" \
  291. " .fillinsn\n" \
  292. "3:\n" \
  293. ".section .fixup,\"ax\"\n" \
  294. " .balign 4\n" \
  295. "4: ldi %0,%3\n" \
  296. " seth r14,#high(3b)\n" \
  297. " or3 r14,r14,#low(3b)\n" \
  298. " jmp r14\n" \
  299. ".previous\n" \
  300. ".section __ex_table,\"a\"\n" \
  301. " .balign 4\n" \
  302. " .long 1b,4b\n" \
  303. " .long 2b,4b\n" \
  304. ".previous" \
  305. : "=&r" (err) \
  306. : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err) \
  307. : "r14", "memory")
  308. #elif defined(__BIG_ENDIAN__)
  309. #define __put_user_u64(x, addr, err) \
  310. __asm__ __volatile__( \
  311. " .fillinsn\n" \
  312. "1: st %H1,@%2\n" \
  313. " .fillinsn\n" \
  314. "2: st %L1,@(4,%2)\n" \
  315. " .fillinsn\n" \
  316. "3:\n" \
  317. ".section .fixup,\"ax\"\n" \
  318. " .balign 4\n" \
  319. "4: ldi %0,%3\n" \
  320. " seth r14,#high(3b)\n" \
  321. " or3 r14,r14,#low(3b)\n" \
  322. " jmp r14\n" \
  323. ".previous\n" \
  324. ".section __ex_table,\"a\"\n" \
  325. " .balign 4\n" \
  326. " .long 1b,4b\n" \
  327. " .long 2b,4b\n" \
  328. ".previous" \
  329. : "=&r" (err) \
  330. : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err) \
  331. : "r14", "memory")
  332. #else
  333. #error no endian defined
  334. #endif
  335. extern void __put_user_bad(void);
  336. #define __put_user_size(x, ptr, size, retval) \
  337. do { \
  338. retval = 0; \
  339. __chk_user_ptr(ptr); \
  340. switch (size) { \
  341. case 1: __put_user_asm(x, ptr, retval, "b"); break; \
  342. case 2: __put_user_asm(x, ptr, retval, "h"); break; \
  343. case 4: __put_user_asm(x, ptr, retval, ""); break; \
  344. case 8: __put_user_u64((__typeof__(*ptr))(x), ptr, retval); break;\
  345. default: __put_user_bad(); \
  346. } \
  347. } while (0)
  348. struct __large_struct { unsigned long buf[100]; };
  349. #define __m(x) (*(struct __large_struct *)(x))
  350. /*
  351. * Tell gcc we read from memory instead of writing: this is because
  352. * we do not write to any memory gcc knows about, so there are no
  353. * aliasing issues.
  354. */
  355. #define __put_user_asm(x, addr, err, itype) \
  356. __asm__ __volatile__( \
  357. " .fillinsn\n" \
  358. "1: st"itype" %1,@%2\n" \
  359. " .fillinsn\n" \
  360. "2:\n" \
  361. ".section .fixup,\"ax\"\n" \
  362. " .balign 4\n" \
  363. "3: ldi %0,%3\n" \
  364. " seth r14,#high(2b)\n" \
  365. " or3 r14,r14,#low(2b)\n" \
  366. " jmp r14\n" \
  367. ".previous\n" \
  368. ".section __ex_table,\"a\"\n" \
  369. " .balign 4\n" \
  370. " .long 1b,3b\n" \
  371. ".previous" \
  372. : "=&r" (err) \
  373. : "r" (x), "r" (addr), "i" (-EFAULT), "0" (err) \
  374. : "r14", "memory")
  375. /*
  376. * Here we special-case 1, 2 and 4-byte copy_*_user invocations. On a fault
  377. * we return the initial request size (1, 2 or 4), as copy_*_user should do.
  378. * If a store crosses a page boundary and gets a fault, the m32r will not write
  379. * anything, so this is accurate.
  380. */
  381. /*
  382. * Copy To/From Userspace
  383. */
  384. /* Generic arbitrary sized copy. */
  385. /* Return the number of bytes NOT copied. */
  386. #define __copy_user(to, from, size) \
  387. do { \
  388. unsigned long __dst, __src, __c; \
  389. __asm__ __volatile__ ( \
  390. " mv r14, %0\n" \
  391. " or r14, %1\n" \
  392. " beq %0, %1, 9f\n" \
  393. " beqz %2, 9f\n" \
  394. " and3 r14, r14, #3\n" \
  395. " bnez r14, 2f\n" \
  396. " and3 %2, %2, #3\n" \
  397. " beqz %3, 2f\n" \
  398. " addi %0, #-4 ; word_copy \n" \
  399. " .fillinsn\n" \
  400. "0: ld r14, @%1+\n" \
  401. " addi %3, #-1\n" \
  402. " .fillinsn\n" \
  403. "1: st r14, @+%0\n" \
  404. " bnez %3, 0b\n" \
  405. " beqz %2, 9f\n" \
  406. " addi %0, #4\n" \
  407. " .fillinsn\n" \
  408. "2: ldb r14, @%1 ; byte_copy \n" \
  409. " .fillinsn\n" \
  410. "3: stb r14, @%0\n" \
  411. " addi %1, #1\n" \
  412. " addi %2, #-1\n" \
  413. " addi %0, #1\n" \
  414. " bnez %2, 2b\n" \
  415. " .fillinsn\n" \
  416. "9:\n" \
  417. ".section .fixup,\"ax\"\n" \
  418. " .balign 4\n" \
  419. "5: addi %3, #1\n" \
  420. " addi %1, #-4\n" \
  421. " .fillinsn\n" \
  422. "6: slli %3, #2\n" \
  423. " add %2, %3\n" \
  424. " addi %0, #4\n" \
  425. " .fillinsn\n" \
  426. "7: seth r14, #high(9b)\n" \
  427. " or3 r14, r14, #low(9b)\n" \
  428. " jmp r14\n" \
  429. ".previous\n" \
  430. ".section __ex_table,\"a\"\n" \
  431. " .balign 4\n" \
  432. " .long 0b,6b\n" \
  433. " .long 1b,5b\n" \
  434. " .long 2b,9b\n" \
  435. " .long 3b,9b\n" \
  436. ".previous\n" \
  437. : "=&r" (__dst), "=&r" (__src), "=&r" (size), \
  438. "=&r" (__c) \
  439. : "0" (to), "1" (from), "2" (size), "3" (size / 4) \
  440. : "r14", "memory"); \
  441. } while (0)
  442. #define __copy_user_zeroing(to, from, size) \
  443. do { \
  444. unsigned long __dst, __src, __c; \
  445. __asm__ __volatile__ ( \
  446. " mv r14, %0\n" \
  447. " or r14, %1\n" \
  448. " beq %0, %1, 9f\n" \
  449. " beqz %2, 9f\n" \
  450. " and3 r14, r14, #3\n" \
  451. " bnez r14, 2f\n" \
  452. " and3 %2, %2, #3\n" \
  453. " beqz %3, 2f\n" \
  454. " addi %0, #-4 ; word_copy \n" \
  455. " .fillinsn\n" \
  456. "0: ld r14, @%1+\n" \
  457. " addi %3, #-1\n" \
  458. " .fillinsn\n" \
  459. "1: st r14, @+%0\n" \
  460. " bnez %3, 0b\n" \
  461. " beqz %2, 9f\n" \
  462. " addi %0, #4\n" \
  463. " .fillinsn\n" \
  464. "2: ldb r14, @%1 ; byte_copy \n" \
  465. " .fillinsn\n" \
  466. "3: stb r14, @%0\n" \
  467. " addi %1, #1\n" \
  468. " addi %2, #-1\n" \
  469. " addi %0, #1\n" \
  470. " bnez %2, 2b\n" \
  471. " .fillinsn\n" \
  472. "9:\n" \
  473. ".section .fixup,\"ax\"\n" \
  474. " .balign 4\n" \
  475. "5: addi %3, #1\n" \
  476. " addi %1, #-4\n" \
  477. " .fillinsn\n" \
  478. "6: slli %3, #2\n" \
  479. " add %2, %3\n" \
  480. " addi %0, #4\n" \
  481. " .fillinsn\n" \
  482. "7: ldi r14, #0 ; store zero \n" \
  483. " .fillinsn\n" \
  484. "8: addi %2, #-1\n" \
  485. " stb r14, @%0 ; ACE? \n" \
  486. " addi %0, #1\n" \
  487. " bnez %2, 8b\n" \
  488. " seth r14, #high(9b)\n" \
  489. " or3 r14, r14, #low(9b)\n" \
  490. " jmp r14\n" \
  491. ".previous\n" \
  492. ".section __ex_table,\"a\"\n" \
  493. " .balign 4\n" \
  494. " .long 0b,6b\n" \
  495. " .long 1b,5b\n" \
  496. " .long 2b,7b\n" \
  497. " .long 3b,7b\n" \
  498. ".previous\n" \
  499. : "=&r" (__dst), "=&r" (__src), "=&r" (size), \
  500. "=&r" (__c) \
  501. : "0" (to), "1" (from), "2" (size), "3" (size / 4) \
  502. : "r14", "memory"); \
  503. } while (0)
  504. /* We let the __ versions of copy_from/to_user inline, because they're often
  505. * used in fast paths and have only a small space overhead.
  506. */
  507. static inline unsigned long __generic_copy_from_user_nocheck(void *to,
  508. const void __user *from, unsigned long n)
  509. {
  510. __copy_user_zeroing(to, from, n);
  511. return n;
  512. }
  513. static inline unsigned long __generic_copy_to_user_nocheck(void __user *to,
  514. const void *from, unsigned long n)
  515. {
  516. __copy_user(to, from, n);
  517. return n;
  518. }
  519. unsigned long __generic_copy_to_user(void __user *, const void *, unsigned long);
  520. unsigned long __generic_copy_from_user(void *, const void __user *, unsigned long);
  521. /**
  522. * __copy_to_user: - Copy a block of data into user space, with less checking.
  523. * @to: Destination address, in user space.
  524. * @from: Source address, in kernel space.
  525. * @n: Number of bytes to copy.
  526. *
  527. * Context: User context only. This function may sleep if pagefaults are
  528. * enabled.
  529. *
  530. * Copy data from kernel space to user space. Caller must check
  531. * the specified block with access_ok() before calling this function.
  532. *
  533. * Returns number of bytes that could not be copied.
  534. * On success, this will be zero.
  535. */
  536. #define __copy_to_user(to, from, n) \
  537. __generic_copy_to_user_nocheck((to), (from), (n))
  538. #define __copy_to_user_inatomic __copy_to_user
  539. #define __copy_from_user_inatomic __copy_from_user
  540. /**
  541. * copy_to_user: - Copy a block of data into user space.
  542. * @to: Destination address, in user space.
  543. * @from: Source address, in kernel space.
  544. * @n: Number of bytes to copy.
  545. *
  546. * Context: User context only. This function may sleep if pagefaults are
  547. * enabled.
  548. *
  549. * Copy data from kernel space to user space.
  550. *
  551. * Returns number of bytes that could not be copied.
  552. * On success, this will be zero.
  553. */
  554. #define copy_to_user(to, from, n) \
  555. ({ \
  556. might_fault(); \
  557. __generic_copy_to_user((to), (from), (n)); \
  558. })
  559. /**
  560. * __copy_from_user: - Copy a block of data from user space, with less checking. * @to: Destination address, in kernel space.
  561. * @from: Source address, in user space.
  562. * @n: Number of bytes to copy.
  563. *
  564. * Context: User context only. This function may sleep if pagefaults are
  565. * enabled.
  566. *
  567. * Copy data from user space to kernel space. Caller must check
  568. * the specified block with access_ok() before calling this function.
  569. *
  570. * Returns number of bytes that could not be copied.
  571. * On success, this will be zero.
  572. *
  573. * If some data could not be copied, this function will pad the copied
  574. * data to the requested size using zero bytes.
  575. */
  576. #define __copy_from_user(to, from, n) \
  577. __generic_copy_from_user_nocheck((to), (from), (n))
  578. /**
  579. * copy_from_user: - Copy a block of data from user space.
  580. * @to: Destination address, in kernel space.
  581. * @from: Source address, in user space.
  582. * @n: Number of bytes to copy.
  583. *
  584. * Context: User context only. This function may sleep if pagefaults are
  585. * enabled.
  586. *
  587. * Copy data from user space to kernel space.
  588. *
  589. * Returns number of bytes that could not be copied.
  590. * On success, this will be zero.
  591. *
  592. * If some data could not be copied, this function will pad the copied
  593. * data to the requested size using zero bytes.
  594. */
  595. #define copy_from_user(to, from, n) \
  596. ({ \
  597. might_fault(); \
  598. __generic_copy_from_user((to), (from), (n)); \
  599. })
  600. long __must_check strncpy_from_user(char *dst, const char __user *src,
  601. long count);
  602. long __must_check __strncpy_from_user(char *dst,
  603. const char __user *src, long count);
  604. /**
  605. * __clear_user: - Zero a block of memory in user space, with less checking.
  606. * @to: Destination address, in user space.
  607. * @n: Number of bytes to zero.
  608. *
  609. * Zero a block of memory in user space. Caller must check
  610. * the specified block with access_ok() before calling this function.
  611. *
  612. * Returns number of bytes that could not be cleared.
  613. * On success, this will be zero.
  614. */
  615. unsigned long __clear_user(void __user *mem, unsigned long len);
  616. /**
  617. * clear_user: - Zero a block of memory in user space.
  618. * @to: Destination address, in user space.
  619. * @n: Number of bytes to zero.
  620. *
  621. * Zero a block of memory in user space. Caller must check
  622. * the specified block with access_ok() before calling this function.
  623. *
  624. * Returns number of bytes that could not be cleared.
  625. * On success, this will be zero.
  626. */
  627. unsigned long clear_user(void __user *mem, unsigned long len);
  628. /**
  629. * strlen_user: - Get the size of a string in user space.
  630. * @str: The string to measure.
  631. *
  632. * Context: User context only. This function may sleep if pagefaults are
  633. * enabled.
  634. *
  635. * Get the size of a NUL-terminated string in user space.
  636. *
  637. * Returns the size of the string INCLUDING the terminating NUL.
  638. * On exception, returns 0.
  639. *
  640. * If there is a limit on the length of a valid string, you may wish to
  641. * consider using strnlen_user() instead.
  642. */
  643. #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
  644. long strnlen_user(const char __user *str, long n);
  645. #endif /* _ASM_M32R_UACCESS_H */