1 macro_rules! prefixed_extern { 2 // Functions. 3 { 4 $( 5 $( #[$meta:meta] )* 6 $vis:vis fn $name:ident ( $( $arg_pat:ident : $arg_ty:ty ),* $(,)? ) 7 $( -> $ret_ty:ty )?; 8 )+ 9 } => { 10 extern "C" { 11 $( 12 prefixed_item! { 13 link_name 14 $name 15 { 16 $( #[$meta] )* 17 $vis fn $name ( $( $arg_pat : $arg_ty ),* ) $( -> $ret_ty )?; 18 } 19 20 } 21 )+ 22 } 23 }; 24 25 // A global variable. 26 { 27 $( #[$meta:meta] )* 28 $vis:vis static mut $name:ident: $typ:ty; 29 } => { 30 extern "C" { 31 prefixed_item! { 32 link_name 33 $name 34 { 35 $( #[$meta] )* 36 $vis static mut $name: $typ; 37 } 38 } 39 } 40 }; 41 } 42 43 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] 44 macro_rules! prefixed_export { 45 // A function. 46 { 47 $( #[$meta:meta] )* 48 $vis:vis unsafe fn $name:ident ( $( $arg_pat:ident : $arg_ty:ty ),* $(,)? ) $body:block 49 } => { 50 prefixed_item! { 51 export_name 52 $name 53 { 54 $( #[$meta] )* 55 $vis unsafe fn $name ( $( $arg_pat : $arg_ty ),* ) $body 56 } 57 } 58 }; 59 60 // A global variable. 61 { 62 $( #[$meta:meta] )* 63 $vis:vis static mut $name:ident: $typ:ty = $initial_value:expr; 64 } => { 65 prefixed_item! { 66 export_name 67 $name 68 { 69 $( #[$meta] )* 70 $vis static mut $name: $typ = $initial_value; 71 } 72 } 73 }; 74 } 75 76 #[cfg(not(soong))] 77 macro_rules! prefixed_item { 78 // Calculate the prefixed name in a separate layer of macro expansion 79 // because rustc won't currently accept a non-literal expression as 80 // the value for `#[link_name = value]`. 81 { 82 $attr:ident 83 $name:ident 84 { $( $item:tt )+ } 85 } => { 86 prefixed_item! { 87 $attr 88 { concat!(env!("RING_CORE_PREFIX"), stringify!($name)) } 89 { $( $item )+ } 90 } 91 }; 92 93 // Output the item. 94 { 95 $attr:ident 96 { $prefixed_name:expr } 97 { $( $item:tt )+ } 98 } => { 99 #[$attr = $prefixed_name] 100 $( $item )+ 101 }; 102 } 103 104 #[cfg(soong)] 105 macro_rules! prefixed_item { 106 // Calculate the prefixed name in a separate layer of macro expansion 107 // because rustc won't currently accept a non-literal expression as 108 // the value for `#[link_name = value]`. 109 { 110 $attr:ident 111 $name:ident 112 { $( $item:tt )+ } 113 } => { 114 prefixed_item! { 115 $attr 116 { concat!("ring_core_android_platform_", stringify!($name)) } 117 { $( $item )+ } 118 } 119 }; 120 121 // Output the item. 122 { 123 $attr:ident 124 { $prefixed_name:expr } 125 { $( $item:tt )+ } 126 } => { 127 #[$attr = $prefixed_name] 128 $( $item )+ 129 }; 130 } 131