uaccess.h 21 KB

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