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_PAGEFAULT_FLAG_WP 9 | UFFD_FEATURE_EVENT_FORK 10 | UFFD_FEATURE_EVENT_REMAP 11 | UFFD_FEATURE_EVENT_REMOVE 12 | UFFD_FEATURE_EVENT_UNMAP 13 | UFFD_FEATURE_MISSING_HUGETLBFS 14 | UFFD_FEATURE_MISSING_SHMEM 15 | UFFD_FEATURE_SIGBUS 16 | UFFD_FEATURE_THREAD_ID; 17 pub const UFFD_API_IOCTLS: u64 = 1 << _UFFDIO_REGISTER | 1 << _UFFDIO_UNREGISTER | 1 << _UFFDIO_API; 18 19 pub const UFFD_API_RANGE_IOCTLS: u64 = 20 1 << _UFFDIO_WAKE | 1 << _UFFDIO_COPY | 1 << _UFFDIO_ZEROPAGE | 1 << _UFFDIO_WRITEPROTECT; 21 22 pub const UFFD_API_RANGE_IOCTLS_BASIC: u64 = 1 << _UFFDIO_WAKE | 1 << _UFFDIO_COPY; 23 24 pub const UFFDIO_REGISTER_MODE_MISSING: u64 = 1 << 0; 25 pub const UFFDIO_REGISTER_MODE_WP: u64 = 1 << 1; 26 pub const UFFDIO_COPY_MODE_DONTWAKE: u64 = 1 << 0; 27 pub const UFFDIO_COPY_MODE_WP: u64 = 1 << 1; 28 pub const UFFDIO_ZEROPAGE_MODE_DONTWAKE: u64 = 1 << 0; 29 pub const UFFDIO_WRITEPROTECT_MODE_WP: u64 = 1 << 0; 30 pub const UFFDIO_WRITEPROTECT_MODE_DONTWAKE: u64 = 1 << 1; 31 32 pub const UFFDIO_API: u32 = 0xc018aa3f; 33 pub const UFFDIO_REGISTER: u32 = 0xc020aa00; 34 pub const UFFDIO_UNREGISTER: u32 = 0x8010aa01; 35 pub const UFFDIO_WAKE: u32 = 0x8010aa02; 36 pub const UFFDIO_COPY: u32 = 0xc028aa03; 37 pub const UFFDIO_ZEROPAGE: u32 = 0xc020aa04; 38 pub const UFFDIO_WRITEPROTECT: u32 = 0xc018aa06; 39 40 #[cfg(test)] 41 mod const_tests { 42 use super::*; 43 44 extern "C" { 45 static _const_UFFD_API: u64; 46 static _const_UFFD_API_FEATURES: u64; 47 static _const_UFFD_API_IOCTLS: u64; 48 static _const_UFFD_API_RANGE_IOCTLS: u64; 49 static _const_UFFD_API_RANGE_IOCTLS_BASIC: u64; 50 static _const_UFFDIO_REGISTER_MODE_MISSING: u64; 51 static _const_UFFDIO_REGISTER_MODE_WP: u64; 52 static _const_UFFDIO_COPY_MODE_DONTWAKE: u64; 53 static _const_UFFDIO_COPY_MODE_WP: u64; 54 static _const_UFFDIO_ZEROPAGE_MODE_DONTWAKE: u64; 55 static _const_UFFDIO_API: u32; 56 static _const_UFFDIO_REGISTER: u32; 57 static _const_UFFDIO_UNREGISTER: u32; 58 static _const_UFFDIO_WAKE: u32; 59 static _const_UFFDIO_COPY: u32; 60 static _const_UFFDIO_ZEROPAGE: u32; 61 static _const_UFFDIO_WRITEPROTECT: u32; 62 } 63 64 #[test] consts_correct()65 fn consts_correct() { 66 unsafe { 67 assert_eq!(UFFD_API, _const_UFFD_API, "UFFD_API"); 68 assert_eq!( 69 UFFD_API_FEATURES, _const_UFFD_API_FEATURES, 70 "UFFD_API_FEATURES" 71 ); 72 assert_eq!(UFFD_API_IOCTLS, _const_UFFD_API_IOCTLS, "UFFD_API_IOCTLS"); 73 assert_eq!( 74 UFFD_API_RANGE_IOCTLS, _const_UFFD_API_RANGE_IOCTLS, 75 "UFFD_API_RANGE_IOCTLS" 76 ); 77 assert_eq!( 78 UFFD_API_RANGE_IOCTLS_BASIC, _const_UFFD_API_RANGE_IOCTLS_BASIC, 79 "UFFD_API_RANGE_IOCTLS_BASIC" 80 ); 81 assert_eq!( 82 UFFDIO_REGISTER_MODE_MISSING, _const_UFFDIO_REGISTER_MODE_MISSING, 83 "UFFDIO_REGISTER_MODE_MISSING" 84 ); 85 assert_eq!( 86 UFFDIO_REGISTER_MODE_WP, _const_UFFDIO_REGISTER_MODE_WP, 87 "UFFDIO_REGISTER_MODE_WP" 88 ); 89 assert_eq!( 90 UFFDIO_COPY_MODE_DONTWAKE, _const_UFFDIO_COPY_MODE_DONTWAKE, 91 "UFFDIO_COPY_MODE_DONTWAKE" 92 ); 93 assert_eq!( 94 UFFDIO_COPY_MODE_WP, _const_UFFDIO_COPY_MODE_WP, 95 "UFFDIO_COPY_MODE_WP" 96 ); 97 assert_eq!( 98 UFFDIO_ZEROPAGE_MODE_DONTWAKE, _const_UFFDIO_ZEROPAGE_MODE_DONTWAKE, 99 "UFFDIO_ZEROPAGE_MODE_DONTWAKE" 100 ); 101 assert_eq!(UFFDIO_API, _const_UFFDIO_API, "UFFDIO_API"); 102 assert_eq!(UFFDIO_REGISTER, _const_UFFDIO_REGISTER, "UFFDIO_REGISTER"); 103 assert_eq!( 104 UFFDIO_UNREGISTER, _const_UFFDIO_UNREGISTER, 105 "UFFDIO_UNREGISTER" 106 ); 107 assert_eq!(UFFDIO_WAKE, _const_UFFDIO_WAKE, "UFFDIO_WAKE"); 108 assert_eq!(UFFDIO_COPY, _const_UFFDIO_COPY, "UFFDIO_COPY"); 109 assert_eq!(UFFDIO_ZEROPAGE, _const_UFFDIO_ZEROPAGE, "UFFDIO_ZEROPAGE"); 110 assert_eq!( 111 UFFDIO_WRITEPROTECT, _const_UFFDIO_WRITEPROTECT, 112 "UFFDIO_WRITEPROTECT" 113 ); 114 } 115 } 116 } 117