1 use super::*; 2 3 // The following are preprocessor constants that bindgen can't figure out, so we enter them manually 4 // from <linux/userfaultfd.h>, and have tests to make sure they're accurate. 5 6 pub const UFFD_API: u64 = 0xAA; 7 8 pub const UFFD_API_FEATURES: u64 = UFFD_FEATURE_EVENT_FORK 9 | UFFD_FEATURE_EVENT_REMAP 10 | UFFD_FEATURE_EVENT_REMOVE 11 | UFFD_FEATURE_EVENT_UNMAP 12 | UFFD_FEATURE_MISSING_HUGETLBFS 13 | UFFD_FEATURE_MISSING_SHMEM 14 | UFFD_FEATURE_SIGBUS 15 | UFFD_FEATURE_THREAD_ID; 16 pub const UFFD_API_IOCTLS: u64 = 1 << _UFFDIO_REGISTER | 1 << _UFFDIO_UNREGISTER | 1 << _UFFDIO_API; 17 pub const UFFD_API_RANGE_IOCTLS: u64 = 18 1 << _UFFDIO_WAKE | 1 << _UFFDIO_COPY | 1 << _UFFDIO_ZEROPAGE; 19 pub const UFFD_API_RANGE_IOCTLS_BASIC: u64 = 1 << _UFFDIO_WAKE | 1 << _UFFDIO_COPY; 20 21 pub const UFFDIO_REGISTER_MODE_MISSING: u64 = 1 << 0; 22 pub const UFFDIO_REGISTER_MODE_WP: u64 = 1 << 1; 23 24 pub const UFFDIO_COPY_MODE_DONTWAKE: u64 = 1 << 0; 25 pub const UFFDIO_COPY_MODE_WP: u64 = 1 << 1; 26 27 pub const UFFDIO_ZEROPAGE_MODE_DONTWAKE: u64 = 1 << 0; 28 29 pub const UFFDIO_API: u32 = 0xc018aa3f; 30 pub const UFFDIO_REGISTER: u32 = 0xc020aa00; 31 pub const UFFDIO_UNREGISTER: u32 = 0x8010aa01; 32 pub const UFFDIO_WAKE: u32 = 0x8010aa02; 33 pub const UFFDIO_COPY: u32 = 0xc028aa03; 34 pub const UFFDIO_ZEROPAGE: u32 = 0xc020aa04; 35 pub const UFFDIO_WRITEPROTECT: u32 = 0xc018aa06; 36 37 #[cfg(test)] 38 mod const_tests { 39 use super::*; 40 41 extern "C" { 42 static _const_UFFD_API: u64; 43 static _const_UFFD_API_FEATURES: u64; 44 static _const_UFFD_API_IOCTLS: u64; 45 static _const_UFFD_API_RANGE_IOCTLS: u64; 46 static _const_UFFD_API_RANGE_IOCTLS_BASIC: u64; 47 static _const_UFFDIO_REGISTER_MODE_MISSING: u64; 48 static _const_UFFDIO_REGISTER_MODE_WP: u64; 49 static _const_UFFDIO_COPY_MODE_DONTWAKE: u64; 50 static _const_UFFDIO_COPY_MODE_WP: u64; 51 static _const_UFFDIO_ZEROPAGE_MODE_DONTWAKE: u64; 52 static _const_UFFDIO_API: u32; 53 static _const_UFFDIO_REGISTER: u32; 54 static _const_UFFDIO_UNREGISTER: u32; 55 static _const_UFFDIO_WAKE: u32; 56 static _const_UFFDIO_COPY: u32; 57 static _const_UFFDIO_ZEROPAGE: u32; 58 static _const_UFFDIO_WRITEPROTECT: u32; 59 } 60 61 #[test] consts_correct()62 fn consts_correct() { 63 unsafe { 64 assert_eq!(UFFD_API, _const_UFFD_API, "UFFD_API"); 65 assert_eq!( 66 UFFD_API_FEATURES, _const_UFFD_API_FEATURES, 67 "UFFD_API_FEATURES" 68 ); 69 assert_eq!(UFFD_API_IOCTLS, _const_UFFD_API_IOCTLS, "UFFD_API_IOCTLS"); 70 assert_eq!( 71 UFFD_API_RANGE_IOCTLS, _const_UFFD_API_RANGE_IOCTLS, 72 "UFFD_API_RANGE_IOCTLS" 73 ); 74 assert_eq!( 75 UFFD_API_RANGE_IOCTLS_BASIC, _const_UFFD_API_RANGE_IOCTLS_BASIC, 76 "UFFD_API_RANGE_IOCTLS_BASIC" 77 ); 78 assert_eq!( 79 UFFDIO_REGISTER_MODE_MISSING, _const_UFFDIO_REGISTER_MODE_MISSING, 80 "UFFDIO_REGISTER_MODE_MISSING" 81 ); 82 assert_eq!( 83 UFFDIO_REGISTER_MODE_WP, _const_UFFDIO_REGISTER_MODE_WP, 84 "UFFDIO_REGISTER_MODE_WP" 85 ); 86 assert_eq!( 87 UFFDIO_COPY_MODE_DONTWAKE, _const_UFFDIO_COPY_MODE_DONTWAKE, 88 "UFFDIO_COPY_MODE_DONTWAKE" 89 ); 90 assert_eq!( 91 UFFDIO_COPY_MODE_WP, _const_UFFDIO_COPY_MODE_WP, 92 "UFFDIO_COPY_MODE_WP" 93 ); 94 assert_eq!( 95 UFFDIO_ZEROPAGE_MODE_DONTWAKE, _const_UFFDIO_ZEROPAGE_MODE_DONTWAKE, 96 "UFFDIO_ZEROPAGE_MODE_DONTWAKE" 97 ); 98 assert_eq!(UFFDIO_API, _const_UFFDIO_API, "UFFDIO_API"); 99 assert_eq!(UFFDIO_REGISTER, _const_UFFDIO_REGISTER, "UFFDIO_REGISTER"); 100 assert_eq!( 101 UFFDIO_UNREGISTER, _const_UFFDIO_UNREGISTER, 102 "UFFDIO_UNREGISTER" 103 ); 104 assert_eq!(UFFDIO_WAKE, _const_UFFDIO_WAKE, "UFFDIO_WAKE"); 105 assert_eq!(UFFDIO_COPY, _const_UFFDIO_COPY, "UFFDIO_COPY"); 106 assert_eq!(UFFDIO_ZEROPAGE, _const_UFFDIO_ZEROPAGE, "UFFDIO_ZEROPAGE"); 107 assert_eq!( 108 UFFDIO_WRITEPROTECT, _const_UFFDIO_WRITEPROTECT, 109 "UFFDIO_WRITEPROTECT" 110 ); 111 } 112 } 113 } 114