uaccess.h 22 KB

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