uaccess.h 22 KB

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