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#define USERFAULTFD_IOC 0xAA
17#define USERFAULTFD_IOC_NEW _IO(USERFAULTFD_IOC, 0x00)
18
19
20
21
22
23
24
25#define UFFD_API ((__u64)0xAA)
26#define UFFD_API_REGISTER_MODES (UFFDIO_REGISTER_MODE_MISSING | \
27 UFFDIO_REGISTER_MODE_WP | \
28 UFFDIO_REGISTER_MODE_MINOR)
29#define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \
30 UFFD_FEATURE_EVENT_FORK | \
31 UFFD_FEATURE_EVENT_REMAP | \
32 UFFD_FEATURE_EVENT_REMOVE | \
33 UFFD_FEATURE_EVENT_UNMAP | \
34 UFFD_FEATURE_MISSING_HUGETLBFS | \
35 UFFD_FEATURE_MISSING_SHMEM | \
36 UFFD_FEATURE_SIGBUS | \
37 UFFD_FEATURE_THREAD_ID | \
38 UFFD_FEATURE_MINOR_HUGETLBFS | \
39 UFFD_FEATURE_MINOR_SHMEM | \
40 UFFD_FEATURE_EXACT_ADDRESS | \
41 UFFD_FEATURE_WP_HUGETLBFS_SHMEM | \
42 UFFD_FEATURE_WP_UNPOPULATED)
43#define UFFD_API_IOCTLS \
44 ((__u64)1 << _UFFDIO_REGISTER | \
45 (__u64)1 << _UFFDIO_UNREGISTER | \
46 (__u64)1 << _UFFDIO_API)
47#define UFFD_API_RANGE_IOCTLS \
48 ((__u64)1 << _UFFDIO_WAKE | \
49 (__u64)1 << _UFFDIO_COPY | \
50 (__u64)1 << _UFFDIO_ZEROPAGE | \
51 (__u64)1 << _UFFDIO_WRITEPROTECT | \
52 (__u64)1 << _UFFDIO_CONTINUE)
53#define UFFD_API_RANGE_IOCTLS_BASIC \
54 ((__u64)1 << _UFFDIO_WAKE | \
55 (__u64)1 << _UFFDIO_COPY | \
56 (__u64)1 << _UFFDIO_CONTINUE | \
57 (__u64)1 << _UFFDIO_WRITEPROTECT)
58
59
60
61
62
63
64
65
66
67#define _UFFDIO_REGISTER (0x00)
68#define _UFFDIO_UNREGISTER (0x01)
69#define _UFFDIO_WAKE (0x02)
70#define _UFFDIO_COPY (0x03)
71#define _UFFDIO_ZEROPAGE (0x04)
72#define _UFFDIO_WRITEPROTECT (0x06)
73#define _UFFDIO_CONTINUE (0x07)
74#define _UFFDIO_API (0x3F)
75
76
77#define UFFDIO 0xAA
78#define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \
79 struct uffdio_api)
80#define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \
81 struct uffdio_register)
82#define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \
83 struct uffdio_range)
84#define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \
85 struct uffdio_range)
86#define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \
87 struct uffdio_copy)
88#define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
89 struct uffdio_zeropage)
90#define UFFDIO_WRITEPROTECT _IOWR(UFFDIO, _UFFDIO_WRITEPROTECT, \
91 struct uffdio_writeprotect)
92#define UFFDIO_CONTINUE _IOWR(UFFDIO, _UFFDIO_CONTINUE, \
93 struct uffdio_continue)
94
95
96struct uffd_msg {
97 __u8 event;
98
99 __u8 reserved1;
100 __u16 reserved2;
101 __u32 reserved3;
102
103 union {
104 struct {
105 __u64 flags;
106 __u64 address;
107 union {
108 __u32 ptid;
109 } feat;
110 } pagefault;
111
112 struct {
113 __u32 ufd;
114 } fork;
115
116 struct {
117 __u64 from;
118 __u64 to;
119 __u64 len;
120 } remap;
121
122 struct {
123 __u64 start;
124 __u64 end;
125 } remove;
126
127 struct {
128
129 __u64 reserved1;
130 __u64 reserved2;
131 __u64 reserved3;
132 } reserved;
133 } arg;
134} __attribute__((packed));
135
136
137
138
139#define UFFD_EVENT_PAGEFAULT 0x12
140#define UFFD_EVENT_FORK 0x13
141#define UFFD_EVENT_REMAP 0x14
142#define UFFD_EVENT_REMOVE 0x15
143#define UFFD_EVENT_UNMAP 0x16
144
145
146#define UFFD_PAGEFAULT_FLAG_WRITE (1<<0)
147#define UFFD_PAGEFAULT_FLAG_WP (1<<1)
148#define UFFD_PAGEFAULT_FLAG_MINOR (1<<2)
149
150struct uffdio_api {
151
152 __u64 api;
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
215#define UFFD_FEATURE_EVENT_FORK (1<<1)
216#define UFFD_FEATURE_EVENT_REMAP (1<<2)
217#define UFFD_FEATURE_EVENT_REMOVE (1<<3)
218#define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4)
219#define UFFD_FEATURE_MISSING_SHMEM (1<<5)
220#define UFFD_FEATURE_EVENT_UNMAP (1<<6)
221#define UFFD_FEATURE_SIGBUS (1<<7)
222#define UFFD_FEATURE_THREAD_ID (1<<8)
223#define UFFD_FEATURE_MINOR_HUGETLBFS (1<<9)
224#define UFFD_FEATURE_MINOR_SHMEM (1<<10)
225#define UFFD_FEATURE_EXACT_ADDRESS (1<<11)
226#define UFFD_FEATURE_WP_HUGETLBFS_SHMEM (1<<12)
227#define UFFD_FEATURE_WP_UNPOPULATED (1<<13)
228 __u64 features;
229
230 __u64 ioctls;
231};
232
233struct uffdio_range {
234 __u64 start;
235 __u64 len;
236};
237
238struct uffdio_register {
239 struct uffdio_range range;
240#define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0)
241#define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1)
242#define UFFDIO_REGISTER_MODE_MINOR ((__u64)1<<2)
243 __u64 mode;
244
245
246
247
248
249 __u64 ioctls;
250};
251
252struct uffdio_copy {
253 __u64 dst;
254 __u64 src;
255 __u64 len;
256#define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)
257
258
259
260
261
262
263#define UFFDIO_COPY_MODE_WP ((__u64)1<<1)
264 __u64 mode;
265
266
267
268
269
270 __s64 copy;
271};
272
273struct uffdio_zeropage {
274 struct uffdio_range range;
275#define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
276 __u64 mode;
277
278
279
280
281
282 __s64 zeropage;
283};
284
285struct uffdio_writeprotect {
286 struct uffdio_range range;
287
288
289
290
291
292
293
294
295
296
297
298
299
300#define UFFDIO_WRITEPROTECT_MODE_WP ((__u64)1<<0)
301#define UFFDIO_WRITEPROTECT_MODE_DONTWAKE ((__u64)1<<1)
302 __u64 mode;
303};
304
305struct uffdio_continue {
306 struct uffdio_range range;
307#define UFFDIO_CONTINUE_MODE_DONTWAKE ((__u64)1<<0)
308
309
310
311
312
313
314#define UFFDIO_CONTINUE_MODE_WP ((__u64)1<<1)
315 __u64 mode;
316
317
318
319
320
321 __s64 mapped;
322};
323
324
325
326
327
328
329
330
331#define UFFD_USER_MODE_ONLY 1
332
333#endif
334