1 #[macro_export] 2 macro_rules! EXTERN { 3 (extern $c:tt {$( 4 fn $n:ident ($( $p:tt $(: $t:ty)?),* $(,)?) $(-> $r:ty)?; 5 )+}) => { 6 #[cfg_attr(all(target_env = "msvc", feature = "user"), link(name = "ntdll"))] 7 #[cfg_attr(all(target_env = "msvc", feature = "kernel"), link(name = "ntoskrnl"))] 8 extern $c {$( 9 pub fn $n( 10 $($p $(: $t)?),* 11 ) $(-> $r)?; 12 )+} 13 $( 14 #[cfg(feature = "func-types")] 15 pub type $n = unsafe extern $c fn($($p $(: $t)?),*) $(-> $r)?; 16 )+ 17 }; 18 (extern $c:tt {$( 19 static mut $n:ident : $t:ty; 20 )+}) => { 21 #[cfg_attr(all(target_env = "msvc", feature = "user"), link(name = "ntdll"))] 22 extern $c {$( 23 pub static mut $n: $t; 24 )+} 25 }; 26 } 27 #[macro_export] 28 macro_rules! FIELD_OFFSET { 29 ($_type:ty, $field:ident$(.$cfields:ident)*) => { 30 unsafe { 31 union Transmuter<T: 'static> { 32 p: *const T, 33 r: &'static T, 34 i: usize, 35 } 36 Transmuter { 37 r: &(&Transmuter { 38 p: $crate::_core::ptr::null::<$_type>() 39 }.r).$field$(.$cfields)* 40 }.i 41 } 42 }; 43 } 44 macro_rules! BITFIELD { 45 ($base:ident $field:ident: $fieldtype:ty [ 46 $($thing:ident $set_thing:ident[$r:expr],)+ 47 ]) => { 48 impl $base {$( 49 #[inline] 50 pub const fn $thing(&self) -> $fieldtype { 51 const SIZE: usize = $crate::_core::mem::size_of::<$fieldtype>() * 8; 52 self.$field << (SIZE - $r.end) >> (SIZE - $r.end + $r.start) 53 } 54 #[inline] 55 pub fn $set_thing(&mut self, val: $fieldtype) { 56 const MASK: $fieldtype = ((1 << ($r.end - $r.start)) - 1) << $r.start; 57 self.$field &= !MASK; 58 self.$field |= (val << $r.start) & MASK; 59 } 60 )+} 61 }; 62 (unsafe $base:ident $field:ident: $fieldtype:ty [ 63 $($thing:ident $set_thing:ident[$r:expr],)+ 64 ]) => { 65 impl $base {$( 66 #[inline] 67 pub unsafe fn $thing(&self) -> $fieldtype { 68 const SIZE: usize = $crate::_core::mem::size_of::<$fieldtype>() * 8; 69 self.$field << (SIZE - $r.end) >> (SIZE - $r.end + $r.start) 70 } 71 #[inline] 72 pub unsafe fn $set_thing(&mut self, val: $fieldtype) { 73 const MASK: $fieldtype = ((1 << ($r.end - $r.start)) - 1) << $r.start; 74 self.$field &= !MASK; 75 self.$field |= (val << $r.start) & MASK; 76 } 77 )+} 78 }; 79 } 80 macro_rules! UNION { 81 ($(#[$attrs:meta])* union $name:ident { 82 $($variant:ident: $ftype:ty,)+ 83 }) => ( 84 #[repr(C)] $(#[$attrs])* 85 pub union $name { 86 $(pub $variant: $ftype,)+ 87 } 88 impl Copy for $name {} 89 impl Clone for $name { 90 #[inline] 91 fn clone(&self) -> $name { *self } 92 } 93 #[cfg(feature = "impl-default")] 94 impl Default for $name { 95 #[inline] 96 fn default() -> $name { unsafe { $crate::_core::mem::zeroed() } } 97 } 98 ); 99 } 100 macro_rules! FN { 101 (stdcall $func:ident($($p:ident: $t:ty,)*) -> $ret:ty) => ( 102 pub type $func = Option<unsafe extern "system" fn($($p: $t,)*) -> $ret>; 103 ); 104 (cdecl $func:ident($($p:ident: $t:ty,)*) -> $ret:ty) => ( 105 pub type $func = Option<unsafe extern "C" fn($($p: $t,)*) -> $ret>; 106 ); 107 } 108 macro_rules! IFDEF { 109 ($($thing:item)*) => ($($thing)*) 110 } 111