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