exmap 0.0.1

A low-level `exmap` userpace interface for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
/* automatically generated by rust-bindgen 0.63.0 */

#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage> {
    storage: Storage,
}
impl<Storage> __BindgenBitfieldUnit<Storage> {
    #[inline]
    pub const fn new(storage: Storage) -> Self {
        Self { storage }
    }
}
impl<Storage> __BindgenBitfieldUnit<Storage>
where
    Storage: AsRef<[u8]> + AsMut<[u8]>,
{
    #[inline]
    pub fn get_bit(&self, index: usize) -> bool {
        debug_assert!(index / 8 < self.storage.as_ref().len());
        let byte_index = index / 8;
        let byte = self.storage.as_ref()[byte_index];
        let bit_index = if cfg!(target_endian = "big") {
            7 - (index % 8)
        } else {
            index % 8
        };
        let mask = 1 << bit_index;
        byte & mask == mask
    }
    #[inline]
    pub fn set_bit(&mut self, index: usize, val: bool) {
        debug_assert!(index / 8 < self.storage.as_ref().len());
        let byte_index = index / 8;
        let byte = &mut self.storage.as_mut()[byte_index];
        let bit_index = if cfg!(target_endian = "big") {
            7 - (index % 8)
        } else {
            index % 8
        };
        let mask = 1 << bit_index;
        if val {
            *byte |= mask;
        } else {
            *byte &= !mask;
        }
    }
    #[inline]
    pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
        debug_assert!(bit_width <= 64);
        debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
        debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
        let mut val = 0;
        for i in 0..(bit_width as usize) {
            if self.get_bit(i + bit_offset) {
                let index = if cfg!(target_endian = "big") {
                    bit_width as usize - 1 - i
                } else {
                    i
                };
                val |= 1 << index;
            }
        }
        val
    }
    #[inline]
    pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
        debug_assert!(bit_width <= 64);
        debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
        debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
        for i in 0..(bit_width as usize) {
            let mask = 1 << i;
            let val_bit_is_set = val & mask == mask;
            let index = if cfg!(target_endian = "big") {
                bit_width as usize - 1 - i
            } else {
                i
            };
            self.set_bit(index + bit_offset, val_bit_is_set);
        }
    }
}
pub const EXMAP_PAGE_LEN_BITS: u32 = 12;
pub const EXMAP_PAGE_MAX_PAGES: u32 = 4096;
pub const EXMAP_USER_INTERFACE_PAGES: u32 = 512;
pub const EXMAP_OFF_EXMAP: u32 = 0;
pub const EXMAP_OFF_INTERFACE_BASE: i64 = -2305843009213693952;
pub const EXMAP_OFF_INTERFACE_MAX: i64 = -1152921504606846976;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct exmap_iov {
    pub anon1: exmap_iov__bindgen_ty_1,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union exmap_iov__bindgen_ty_1 {
    pub value: u64,
    pub anon1: ExmapIov,
    pub anon2: exmap_iov__bindgen_ty_1__bindgen_ty_2,
}
#[repr(C)]
#[repr(align(8))]
#[derive(Debug, Default, Copy, Clone)]
pub struct ExmapIov {
    pub _bitfield_align_1: [u64; 0],
    pub _bitfield_1: __BindgenBitfieldUnit<[u8; 8usize]>,
}
#[test]
fn bindgen_test_layout_ExmapIov() {
    assert_eq!(
        ::core::mem::size_of::<ExmapIov>(),
        8usize,
        concat!("Size of: ", stringify!(ExmapIov))
    );
    assert_eq!(
        ::core::mem::align_of::<ExmapIov>(),
        8usize,
        concat!("Alignment of ", stringify!(ExmapIov))
    );
}
impl ExmapIov {
    #[inline]
    pub fn page(&self) -> u64 {
        unsafe { ::core::mem::transmute(self._bitfield_1.get(0usize, 52u8) as u64) }
    }
    #[inline]
    pub fn set_page(&mut self, val: u64) {
        unsafe {
            let val: u64 = ::core::mem::transmute(val);
            self._bitfield_1.set(0usize, 52u8, val as u64)
        }
    }
    #[inline]
    pub fn len(&self) -> u64 {
        unsafe { ::core::mem::transmute(self._bitfield_1.get(52usize, 12u8) as u64) }
    }
    #[inline]
    pub fn set_len(&mut self, val: u64) {
        unsafe {
            let val: u64 = ::core::mem::transmute(val);
            self._bitfield_1.set(52usize, 12u8, val as u64)
        }
    }
    #[inline]
    pub fn new_bitfield_1(page: u64, len: u64) -> __BindgenBitfieldUnit<[u8; 8usize]> {
        let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 8usize]> = Default::default();
        __bindgen_bitfield_unit.set(0usize, 52u8, {
            let page: u64 = unsafe { ::core::mem::transmute(page) };
            page as u64
        });
        __bindgen_bitfield_unit.set(52usize, 12u8, {
            let len: u64 = unsafe { ::core::mem::transmute(len) };
            len as u64
        });
        __bindgen_bitfield_unit
    }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct exmap_iov__bindgen_ty_1__bindgen_ty_2 {
    pub res: i32,
    pub pages: i16,
}
#[test]
fn bindgen_test_layout_exmap_iov__bindgen_ty_1__bindgen_ty_2() {
    const UNINIT: ::core::mem::MaybeUninit<exmap_iov__bindgen_ty_1__bindgen_ty_2> =
        ::core::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::core::mem::size_of::<exmap_iov__bindgen_ty_1__bindgen_ty_2>(),
        8usize,
        concat!(
            "Size of: ",
            stringify!(exmap_iov__bindgen_ty_1__bindgen_ty_2)
        )
    );
    assert_eq!(
        ::core::mem::align_of::<exmap_iov__bindgen_ty_1__bindgen_ty_2>(),
        4usize,
        concat!(
            "Alignment of ",
            stringify!(exmap_iov__bindgen_ty_1__bindgen_ty_2)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).res) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_iov__bindgen_ty_1__bindgen_ty_2),
            "::",
            stringify!(res)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).pages) as usize - ptr as usize },
        4usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_iov__bindgen_ty_1__bindgen_ty_2),
            "::",
            stringify!(pages)
        )
    );
}
#[test]
fn bindgen_test_layout_exmap_iov__bindgen_ty_1() {
    const UNINIT: ::core::mem::MaybeUninit<exmap_iov__bindgen_ty_1> =
        ::core::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::core::mem::size_of::<exmap_iov__bindgen_ty_1>(),
        8usize,
        concat!("Size of: ", stringify!(exmap_iov__bindgen_ty_1))
    );
    assert_eq!(
        ::core::mem::align_of::<exmap_iov__bindgen_ty_1>(),
        8usize,
        concat!("Alignment of ", stringify!(exmap_iov__bindgen_ty_1))
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).value) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_iov__bindgen_ty_1),
            "::",
            stringify!(value)
        )
    );
}
impl Default for exmap_iov__bindgen_ty_1 {
    fn default() -> Self {
        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[test]
fn bindgen_test_layout_exmap_iov() {
    assert_eq!(
        ::core::mem::size_of::<exmap_iov>(),
        8usize,
        concat!("Size of: ", stringify!(exmap_iov))
    );
    assert_eq!(
        ::core::mem::align_of::<exmap_iov>(),
        8usize,
        concat!("Alignment of ", stringify!(exmap_iov))
    );
}
impl Default for exmap_iov {
    fn default() -> Self {
        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct exmap_user_interface {
    pub anon1: exmap_user_interface__bindgen_ty_1,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union exmap_user_interface__bindgen_ty_1 {
    pub iov: [exmap_iov; 512usize],
}
#[test]
fn bindgen_test_layout_exmap_user_interface__bindgen_ty_1() {
    const UNINIT: ::core::mem::MaybeUninit<exmap_user_interface__bindgen_ty_1> =
        ::core::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::core::mem::size_of::<exmap_user_interface__bindgen_ty_1>(),
        4096usize,
        concat!("Size of: ", stringify!(exmap_user_interface__bindgen_ty_1))
    );
    assert_eq!(
        ::core::mem::align_of::<exmap_user_interface__bindgen_ty_1>(),
        8usize,
        concat!(
            "Alignment of ",
            stringify!(exmap_user_interface__bindgen_ty_1)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).iov) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_user_interface__bindgen_ty_1),
            "::",
            stringify!(iov)
        )
    );
}
impl Default for exmap_user_interface__bindgen_ty_1 {
    fn default() -> Self {
        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[test]
fn bindgen_test_layout_exmap_user_interface() {
    assert_eq!(
        ::core::mem::size_of::<exmap_user_interface>(),
        4096usize,
        concat!("Size of: ", stringify!(exmap_user_interface))
    );
    assert_eq!(
        ::core::mem::align_of::<exmap_user_interface>(),
        8usize,
        concat!("Alignment of ", stringify!(exmap_user_interface))
    );
}
impl Default for exmap_user_interface {
    fn default() -> Self {
        let mut s = ::core::mem::MaybeUninit::<Self>::uninit();
        unsafe {
            ::core::ptr::write_bytes(s.as_mut_ptr(), 0, 1);
            s.assume_init()
        }
    }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct exmap_ioctl_setup {
    pub fd: ::core::ffi::c_int,
    pub max_interfaces: ::core::ffi::c_int,
    pub buffer_size: usize,
    pub flags: u64,
}
#[test]
fn bindgen_test_layout_exmap_ioctl_setup() {
    const UNINIT: ::core::mem::MaybeUninit<exmap_ioctl_setup> = ::core::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::core::mem::size_of::<exmap_ioctl_setup>(),
        24usize,
        concat!("Size of: ", stringify!(exmap_ioctl_setup))
    );
    assert_eq!(
        ::core::mem::align_of::<exmap_ioctl_setup>(),
        8usize,
        concat!("Alignment of ", stringify!(exmap_ioctl_setup))
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).fd) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_ioctl_setup),
            "::",
            stringify!(fd)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).max_interfaces) as usize - ptr as usize },
        4usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_ioctl_setup),
            "::",
            stringify!(max_interfaces)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).buffer_size) as usize - ptr as usize },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_ioctl_setup),
            "::",
            stringify!(buffer_size)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).flags) as usize - ptr as usize },
        16usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_ioctl_setup),
            "::",
            stringify!(flags)
        )
    );
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct exmap_action_params {
    pub interface: u16,
    pub iov_len: u16,
    pub opcode: u16,
    pub flags: u64,
}
#[test]
fn bindgen_test_layout_exmap_action_params() {
    const UNINIT: ::core::mem::MaybeUninit<exmap_action_params> =
        ::core::mem::MaybeUninit::uninit();
    let ptr = UNINIT.as_ptr();
    assert_eq!(
        ::core::mem::size_of::<exmap_action_params>(),
        16usize,
        concat!("Size of: ", stringify!(exmap_action_params))
    );
    assert_eq!(
        ::core::mem::align_of::<exmap_action_params>(),
        8usize,
        concat!("Alignment of ", stringify!(exmap_action_params))
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).interface) as usize - ptr as usize },
        0usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_action_params),
            "::",
            stringify!(interface)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).iov_len) as usize - ptr as usize },
        2usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_action_params),
            "::",
            stringify!(iov_len)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).opcode) as usize - ptr as usize },
        4usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_action_params),
            "::",
            stringify!(opcode)
        )
    );
    assert_eq!(
        unsafe { ::core::ptr::addr_of!((*ptr).flags) as usize - ptr as usize },
        8usize,
        concat!(
            "Offset of field: ",
            stringify!(exmap_action_params),
            "::",
            stringify!(flags)
        )
    );
}
pub const EXMAP_OP_READ: exmap_opcode = 0;
pub const EXMAP_OP_ALLOC: exmap_opcode = 1;
pub const EXMAP_OP_FREE: exmap_opcode = 2;
pub const EXMAP_OP_WRITE: exmap_opcode = 3;
pub type exmap_opcode = ::core::ffi::c_uint;
pub const EXMAP_ALLOC_PROBE: exmap_flags = 1;
pub type exmap_flags = ::core::ffi::c_uint;
pub const Fix753_EXMAP_IOCTL_ACTION: ::core::ffi::c_ulong = 1074817794;
pub const Fix753_EXMAP_IOCTL_SETUP: ::core::ffi::c_ulong = 1075342081;