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#define UFFD_API_IOCTLS \
43 ((__u64)1 << _UFFDIO_REGISTER | \
44 (__u64)1 << _UFFDIO_UNREGISTER | \
45 (__u64)1 << _UFFDIO_API)
46#define UFFD_API_RANGE_IOCTLS \
47 ((__u64)1 << _UFFDIO_WAKE | \
48 (__u64)1 << _UFFDIO_COPY | \
49 (__u64)1 << _UFFDIO_ZEROPAGE | \
50 (__u64)1 << _UFFDIO_WRITEPROTECT | \
51 (__u64)1 << _UFFDIO_CONTINUE)
52#define UFFD_API_RANGE_IOCTLS_BASIC \
53 ((__u64)1 << _UFFDIO_WAKE | \
54 (__u64)1 << _UFFDIO_COPY | \
55 (__u64)1 << _UFFDIO_CONTINUE | \
56 (__u64)1 << _UFFDIO_WRITEPROTECT)
57
58
59
60
61
62
63
64
65
66#define _UFFDIO_REGISTER (0x00)
67#define _UFFDIO_UNREGISTER (0x01)
68#define _UFFDIO_WAKE (0x02)
69#define _UFFDIO_COPY (0x03)
70#define _UFFDIO_ZEROPAGE (0x04)
71#define _UFFDIO_WRITEPROTECT (0x06)
72#define _UFFDIO_CONTINUE (0x07)
73#define _UFFDIO_API (0x3F)
74
75
76#define UFFDIO 0xAA
77#define UFFDIO_API _IOWR(UFFDIO, _UFFDIO_API, \
78 struct uffdio_api)
79#define UFFDIO_REGISTER _IOWR(UFFDIO, _UFFDIO_REGISTER, \
80 struct uffdio_register)
81#define UFFDIO_UNREGISTER _IOR(UFFDIO, _UFFDIO_UNREGISTER, \
82 struct uffdio_range)
83#define UFFDIO_WAKE _IOR(UFFDIO, _UFFDIO_WAKE, \
84 struct uffdio_range)
85#define UFFDIO_COPY _IOWR(UFFDIO, _UFFDIO_COPY, \
86 struct uffdio_copy)
87#define UFFDIO_ZEROPAGE _IOWR(UFFDIO, _UFFDIO_ZEROPAGE, \
88 struct uffdio_zeropage)
89#define UFFDIO_WRITEPROTECT _IOWR(UFFDIO, _UFFDIO_WRITEPROTECT, \
90 struct uffdio_writeprotect)
91#define UFFDIO_CONTINUE _IOWR(UFFDIO, _UFFDIO_CONTINUE, \
92 struct uffdio_continue)
93
94
95struct uffd_msg {
96 __u8 event;
97
98 __u8 reserved1;
99 __u16 reserved2;
100 __u32 reserved3;
101
102 union {
103 struct {
104 __u64 flags;
105 __u64 address;
106 union {
107 __u32 ptid;
108 } feat;
109 } pagefault;
110
111 struct {
112 __u32 ufd;
113 } fork;
114
115 struct {
116 __u64 from;
117 __u64 to;
118 __u64 len;
119 } remap;
120
121 struct {
122 __u64 start;
123 __u64 end;
124 } remove;
125
126 struct {
127
128 __u64 reserved1;
129 __u64 reserved2;
130 __u64 reserved3;
131 } reserved;
132 } arg;
133} __attribute__((packed));
134
135
136
137
138#define UFFD_EVENT_PAGEFAULT 0x12
139#define UFFD_EVENT_FORK 0x13
140#define UFFD_EVENT_REMAP 0x14
141#define UFFD_EVENT_REMOVE 0x15
142#define UFFD_EVENT_UNMAP 0x16
143
144
145#define UFFD_PAGEFAULT_FLAG_WRITE (1<<0)
146#define UFFD_PAGEFAULT_FLAG_WP (1<<1)
147#define UFFD_PAGEFAULT_FLAG_MINOR (1<<2)
148
149struct uffdio_api {
150
151 __u64 api;
152
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#define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)
208#define UFFD_FEATURE_EVENT_FORK (1<<1)
209#define UFFD_FEATURE_EVENT_REMAP (1<<2)
210#define UFFD_FEATURE_EVENT_REMOVE (1<<3)
211#define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4)
212#define UFFD_FEATURE_MISSING_SHMEM (1<<5)
213#define UFFD_FEATURE_EVENT_UNMAP (1<<6)
214#define UFFD_FEATURE_SIGBUS (1<<7)
215#define UFFD_FEATURE_THREAD_ID (1<<8)
216#define UFFD_FEATURE_MINOR_HUGETLBFS (1<<9)
217#define UFFD_FEATURE_MINOR_SHMEM (1<<10)
218#define UFFD_FEATURE_EXACT_ADDRESS (1<<11)
219#define UFFD_FEATURE_WP_HUGETLBFS_SHMEM (1<<12)
220 __u64 features;
221
222 __u64 ioctls;
223};
224
225struct uffdio_range {
226 __u64 start;
227 __u64 len;
228};
229
230struct uffdio_register {
231 struct uffdio_range range;
232#define UFFDIO_REGISTER_MODE_MISSING ((__u64)1<<0)
233#define UFFDIO_REGISTER_MODE_WP ((__u64)1<<1)
234#define UFFDIO_REGISTER_MODE_MINOR ((__u64)1<<2)
235 __u64 mode;
236
237
238
239
240
241 __u64 ioctls;
242};
243
244struct uffdio_copy {
245 __u64 dst;
246 __u64 src;
247 __u64 len;
248#define UFFDIO_COPY_MODE_DONTWAKE ((__u64)1<<0)
249
250
251
252
253
254
255#define UFFDIO_COPY_MODE_WP ((__u64)1<<1)
256 __u64 mode;
257
258
259
260
261
262 __s64 copy;
263};
264
265struct uffdio_zeropage {
266 struct uffdio_range range;
267#define UFFDIO_ZEROPAGE_MODE_DONTWAKE ((__u64)1<<0)
268 __u64 mode;
269
270
271
272
273
274 __s64 zeropage;
275};
276
277struct uffdio_writeprotect {
278 struct uffdio_range range;
279
280
281
282
283
284
285
286
287
288
289
290
291
292#define UFFDIO_WRITEPROTECT_MODE_WP ((__u64)1<<0)
293#define UFFDIO_WRITEPROTECT_MODE_DONTWAKE ((__u64)1<<1)
294 __u64 mode;
295};
296
297struct uffdio_continue {
298 struct uffdio_range range;
299#define UFFDIO_CONTINUE_MODE_DONTWAKE ((__u64)1<<0)
300 __u64 mode;
301
302
303
304
305
306 __s64 mapped;
307};
308
309
310
311
312
313
314
315
316#define UFFD_USER_MODE_ONLY 1
317
318#endif
319