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 | #[deprecated = "`#[export_name]` creates problems and we will stop doing it." ] |
44 | #[cfg (not(any( |
45 | target_arch = "aarch64" , |
46 | target_arch = "arm" , |
47 | target_arch = "x86" , |
48 | target_arch = "x86_64" |
49 | )))] |
50 | macro_rules! prefixed_export { |
51 | // A function. |
52 | { |
53 | $( #[$meta:meta] )* |
54 | $vis:vis unsafe fn $name:ident ( $( $arg_pat:ident : $arg_ty:ty ),* $(,)? ) $body:block |
55 | } => { |
56 | prefixed_item! { |
57 | export_name |
58 | $name |
59 | { |
60 | $( #[$meta] )* |
61 | $vis unsafe fn $name ( $( $arg_pat : $arg_ty ),* ) $body |
62 | } |
63 | } |
64 | }; |
65 | } |
66 | |
67 | macro_rules! prefixed_item { |
68 | // Calculate the prefixed name in a separate layer of macro expansion |
69 | // because rustc won't currently accept a non-literal expression as |
70 | // the value for `#[link_name = value]`. |
71 | { |
72 | $attr:ident |
73 | $name:ident |
74 | { $( $item:tt )+ } |
75 | } => { |
76 | prefixed_item! { |
77 | $attr |
78 | { concat!(env!("RING_CORE_PREFIX" ), stringify!($name)) } |
79 | { $( $item )+ } |
80 | } |
81 | }; |
82 | |
83 | // Output the item. |
84 | { |
85 | $attr:ident |
86 | { $prefixed_name:expr } |
87 | { $( $item:tt )+ } |
88 | } => { |
89 | #[$attr = $prefixed_name] |
90 | $( $item )+ |
91 | }; |
92 | } |
93 | |