]>
Commit | Line | Data |
---|---|---|
1965aae3 PA |
1 | #ifndef _ASM_X86_UACCESS_32_H |
2 | #define _ASM_X86_UACCESS_32_H | |
1da177e4 LT |
3 | |
4 | /* | |
5 | * User space memory access functions | |
6 | */ | |
1da177e4 | 7 | #include <linux/string.h> |
14e6d17d | 8 | #include <asm/asm.h> |
1da177e4 LT |
9 | #include <asm/page.h> |
10 | ||
b1fcec7f JP |
11 | unsigned long __must_check __copy_to_user_ll |
12 | (void __user *to, const void *from, unsigned long n); | |
13 | unsigned long __must_check __copy_from_user_ll | |
14 | (void *to, const void __user *from, unsigned long n); | |
15 | unsigned long __must_check __copy_from_user_ll_nozero | |
16 | (void *to, const void __user *from, unsigned long n); | |
b1fcec7f JP |
17 | unsigned long __must_check __copy_from_user_ll_nocache_nozero |
18 | (void *to, const void __user *from, unsigned long n); | |
1da177e4 | 19 | |
6d1c4261 AK |
20 | /** |
21 | * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking. | |
22 | * @to: Destination address, in user space. | |
23 | * @from: Source address, in kernel space. | |
24 | * @n: Number of bytes to copy. | |
25 | * | |
26 | * Context: User context only. | |
27 | * | |
28 | * Copy data from kernel space to user space. Caller must check | |
29 | * the specified block with access_ok() before calling this function. | |
30 | * The caller should also make sure he pins the user space address | |
4fe48782 | 31 | * so that we don't result in page fault and sleep. |
1da177e4 | 32 | */ |
652050ae | 33 | static __always_inline unsigned long __must_check |
1da177e4 LT |
34 | __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n) |
35 | { | |
5b710f34 | 36 | check_object_size(from, n, true); |
1da177e4 LT |
37 | return __copy_to_user_ll(to, from, n); |
38 | } | |
39 | ||
1da177e4 | 40 | /** |
9c7fff6e RD |
41 | * __copy_to_user: - Copy a block of data into user space, with less checking. |
42 | * @to: Destination address, in user space. | |
43 | * @from: Source address, in kernel space. | |
1da177e4 LT |
44 | * @n: Number of bytes to copy. |
45 | * | |
b3c395ef DH |
46 | * Context: User context only. This function may sleep if pagefaults are |
47 | * enabled. | |
1da177e4 | 48 | * |
9c7fff6e | 49 | * Copy data from kernel space to user space. Caller must check |
1da177e4 LT |
50 | * the specified block with access_ok() before calling this function. |
51 | * | |
52 | * Returns number of bytes that could not be copied. | |
53 | * On success, this will be zero. | |
1da177e4 | 54 | */ |
9c7fff6e RD |
55 | static __always_inline unsigned long __must_check |
56 | __copy_to_user(void __user *to, const void *from, unsigned long n) | |
57 | { | |
3ee1afa3 | 58 | might_fault(); |
c10d38dd | 59 | return __copy_to_user_inatomic(to, from, n); |
9c7fff6e RD |
60 | } |
61 | ||
652050ae | 62 | static __always_inline unsigned long |
1da177e4 LT |
63 | __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) |
64 | { | |
7c12d811 N |
65 | return __copy_from_user_ll_nozero(to, from, n); |
66 | } | |
9c7fff6e RD |
67 | |
68 | /** | |
69 | * __copy_from_user: - Copy a block of data from user space, with less checking. | |
70 | * @to: Destination address, in kernel space. | |
71 | * @from: Source address, in user space. | |
72 | * @n: Number of bytes to copy. | |
73 | * | |
b3c395ef DH |
74 | * Context: User context only. This function may sleep if pagefaults are |
75 | * enabled. | |
9c7fff6e RD |
76 | * |
77 | * Copy data from user space to kernel space. Caller must check | |
78 | * the specified block with access_ok() before calling this function. | |
79 | * | |
80 | * Returns number of bytes that could not be copied. | |
81 | * On success, this will be zero. | |
82 | * | |
83 | * If some data could not be copied, this function will pad the copied | |
84 | * data to the requested size using zero bytes. | |
85 | * | |
86 | * An alternate version - __copy_from_user_inatomic() - may be called from | |
87 | * atomic context and will fail rather than sleep. In this case the | |
88 | * uncopied bytes will *NOT* be padded with zeros. See fs/filemap.h | |
89 | * for explanation of why this is needed. | |
90 | */ | |
7c12d811 N |
91 | static __always_inline unsigned long |
92 | __copy_from_user(void *to, const void __user *from, unsigned long n) | |
93 | { | |
3ee1afa3 | 94 | might_fault(); |
5b710f34 | 95 | check_object_size(to, n, false); |
1da177e4 LT |
96 | if (__builtin_constant_p(n)) { |
97 | unsigned long ret; | |
98 | ||
99 | switch (n) { | |
100 | case 1: | |
de9e478b | 101 | __uaccess_begin(); |
1da177e4 | 102 | __get_user_size(*(u8 *)to, from, 1, ret, 1); |
de9e478b | 103 | __uaccess_end(); |
1da177e4 LT |
104 | return ret; |
105 | case 2: | |
de9e478b | 106 | __uaccess_begin(); |
1da177e4 | 107 | __get_user_size(*(u16 *)to, from, 2, ret, 2); |
de9e478b | 108 | __uaccess_end(); |
1da177e4 LT |
109 | return ret; |
110 | case 4: | |
de9e478b | 111 | __uaccess_begin(); |
1da177e4 | 112 | __get_user_size(*(u32 *)to, from, 4, ret, 4); |
de9e478b | 113 | __uaccess_end(); |
1da177e4 LT |
114 | return ret; |
115 | } | |
116 | } | |
117 | return __copy_from_user_ll(to, from, n); | |
118 | } | |
119 | ||
652050ae | 120 | static __always_inline unsigned long |
b1fcec7f JP |
121 | __copy_from_user_inatomic_nocache(void *to, const void __user *from, |
122 | unsigned long n) | |
1da177e4 | 123 | { |
7c12d811 | 124 | return __copy_from_user_ll_nocache_nozero(to, from, n); |
c22ce143 HY |
125 | } |
126 | ||
1965aae3 | 127 | #endif /* _ASM_X86_UACCESS_32_H */ |