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