1
2
3
4
5
6
7
8
9
10 #ifndef _LINUX_USERFAULTFD_H
11 #define _LINUX_USERFAULTFD_H
12
13 #include <linux/types.h>
14
15
16
17
18
19
20
21 #define UFFD_API ((__u64)0xAA)
22 #define UFFD_API_FEATURES (UFFD_FEATURE_EVENT_FORK | \
23 UFFD_FEATURE_EVENT_REMAP | \
24 UFFD_FEATURE_EVENT_REMOVE | \
25 UFFD_FEATURE_EVENT_UNMAP | \
26 UFFD_FEATURE_MISSING_HUGETLBFS | \
27 UFFD_FEATURE_MISSING_SHMEM | \
28 UFFD_FEATURE_SIGBUS | \
29 UFFD_FEATURE_THREAD_ID)
30 #define UFFD_API_IOCTLS \
31 ((__u64)1 << _UFFDIO_REGISTER | \
32 (__u64)1 << _UFFDIO_UNREGISTER | \
33 (__u64)1 << _UFFDIO_API)
34 #define UFFD_API_RANGE_IOCTLS \
35 ((__u64)1 << _UFFDIO_WAKE | \
36 (__u64)1 << _UFFDIO_COPY | \
37 (__u64)1 << _UFFDIO_ZEROPAGE)
38 #define UFFD_API_RANGE_IOCTLS_BASIC \
39 ((__u64)1 << _UFFDIO_WAKE | \
40 (__u64)1 << _UFFDIO_COPY)
41
42
43
44
45
46
47
48
49
50 #define _UFFDIO_REGISTER (0x00)
51 #define _UFFDIO_UNREGISTER (0x01)
52 #define _UFFDIO_WAKE (0x02)
53 #define _UFFDIO_COPY (0x03)
54 #define _UFFDIO_ZEROPAGE (0x04)
55 #define _UFFDIO_API (0x3F)
56
57
58 #define UFFDIO 0xAA
59 #define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \
60 struct uffdio_api)
61 #define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \
62 struct uffdio_register)
63 #define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \
64 struct uffdio_range)
65 #define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \
66 struct uffdio_range)
67 #define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \
68 struct uffdio_copy)
69 #define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
70 struct uffdio_zeropage)
71
72
73 struct uffd_msg {
74 __u8 event;
75
76 __u8 reserved1;
77 __u16 reserved2;
78 __u32 reserved3;
79
80 union {
81 struct {
82 __u64 flags;
83 __u64 address;
84 union {
85 __u32 ptid;
86 } feat;
87 } pagefault;
88
89 struct {
90 __u32 ufd;
91 } fork;
92
93 struct {
94 __u64 from;
95 __u64 to;
96 __u64 len;
97 } remap;
98
99 struct {
100 __u64 start;
101 __u64 end;
102 } remove;
103
104 struct {
105
106 __u64 reserved1;
107 __u64 reserved2;
108 __u64 reserved3;
109 } reserved;
110 } arg;
111 } __packed;
112
113
114
115
116 #define UFFD_EVENT_PAGEFAULT 0x12
117 #define UFFD_EVENT_FORK 0x13
118 #define UFFD_EVENT_REMAP 0x14
119 #define UFFD_EVENT_REMOVE 0x15
120 #define UFFD_EVENT_UNMAP 0x16
121
122
123 #define UFFD_PAGEFAULT_FLAG_WRITE (1<<0)
124 #define UFFD_PAGEFAULT_FLAG_WP (1<<1)
125
126 struct uffdio_api {
127
128 __u64 api;
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170 #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
171 #define UFFD_FEATURE_EVENT_FORK (1<<1)
172 #define UFFD_FEATURE_EVENT_REMAP (1<<2)
173 #define UFFD_FEATURE_EVENT_REMOVE (1<<3)
174 #define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4)
175 #define UFFD_FEATURE_MISSING_SHMEM (1<<5)
176 #define UFFD_FEATURE_EVENT_UNMAP (1<<6)
177 #define UFFD_FEATURE_SIGBUS (1<<7)
178 #define UFFD_FEATURE_THREAD_ID (1<<8)
179 __u64 features;
180
181 __u64 ioctls;
182 };
183
184 struct uffdio_range {
185 __u64 start;
186 __u64 len;
187 };
188
189 struct uffdio_register {
190 struct uffdio_range range;
191 #define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0)
192 #define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1)
193 __u64 mode;
194
195
196
197
198
199 __u64 ioctls;
200 };
201
202 struct uffdio_copy {
203 __u64 dst;
204 __u64 src;
205 __u64 len;
206
207
208
209
210
211
212 #define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)
213 __u64 mode;
214
215
216
217
218
219 __s64 copy;
220 };
221
222 struct uffdio_zeropage {
223 struct uffdio_range range;
224 #define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
225 __u64 mode;
226
227
228
229
230
231 __s64 zeropage;
232 };
233
234 #endif