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