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