diff options
author | 2019-12-29 13:53:28 +0100 | |
---|---|---|
committer | 2019-12-29 13:53:28 +0100 | |
commit | 1b5da39d9d1c3bc6558585a6ecf8ce2448ff82fd (patch) | |
tree | 18d53d7abb6c891b0baaae6de9fc5a4697534b36 /cortex-m-rt/macros/src | |
parent | ec7a1a7fdaa26f686b22fe01b1c0f6387ab260b9 (diff) | |
download | cortex-m-1b5da39d9d1c3bc6558585a6ecf8ce2448ff82fd.tar.gz cortex-m-1b5da39d9d1c3bc6558585a6ecf8ce2448ff82fd.tar.zst cortex-m-1b5da39d9d1c3bc6558585a6ecf8ce2448ff82fd.zip |
Added blacklisted attributes
Diffstat (limited to 'cortex-m-rt/macros/src')
-rw-r--r-- | cortex-m-rt/macros/src/lib.rs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/cortex-m-rt/macros/src/lib.rs b/cortex-m-rt/macros/src/lib.rs index 763b721..9755153 100644 --- a/cortex-m-rt/macros/src/lib.rs +++ b/cortex-m-rt/macros/src/lib.rs @@ -150,7 +150,15 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { }) .collect::<Vec<_>>(); + if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + return error; + } + + let (ref cfgs, ref attrs) = extract_cfgs(f.attrs.clone()); + quote!( + #(#cfgs)* + #(#attrs)* #[doc(hidden)] #[export_name = "main"] pub unsafe extern "C" fn #tramp_ident() { @@ -343,7 +351,15 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { let tramp_ident = Ident::new(&format!("{}_trampoline", f.sig.ident), Span::call_site()); let ident = &f.sig.ident; + if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + return error; + } + + let (ref cfgs, ref attrs) = extract_cfgs(f.attrs.clone()); + quote!( + #(#cfgs)* + #(#attrs)* #[doc(hidden)] #[export_name = #ident_s] pub unsafe extern "C" fn #tramp_ident() { @@ -396,7 +412,15 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { let tramp_ident = Ident::new(&format!("{}_trampoline", f.sig.ident), Span::call_site()); let ident = &f.sig.ident; + if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + return error; + } + + let (ref cfgs, ref attrs) = extract_cfgs(f.attrs.clone()); + quote!( + #(#cfgs)* + #(#attrs)* #[doc(hidden)] #[export_name = "HardFault"] #[link_section = ".HardFault.user"] @@ -481,7 +505,15 @@ pub fn exception(args: TokenStream, input: TokenStream) -> TokenStream { }) .collect::<Vec<_>>(); + if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + return error; + } + + let (ref cfgs, ref attrs) = extract_cfgs(f.attrs.clone()); + quote!( + #(#cfgs)* + #(#attrs)* #[doc(hidden)] #[export_name = #ident_s] pub unsafe extern "C" fn #tramp_ident() { @@ -650,7 +682,15 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { }) .collect::<Vec<_>>(); + if let Some(error) = check_for_blacklisted_attrs(&f.attrs) { + return error; + } + + let (ref cfgs, ref attrs) = extract_cfgs(f.attrs.clone()); + quote!( + #(#cfgs)* + #(#attrs)* #[doc(hidden)] #[export_name = #ident_s] pub unsafe extern "C" fn #tramp_ident() { @@ -790,6 +830,30 @@ fn extract_cfgs(attrs: Vec<Attribute>) -> (Vec<Attribute>, Vec<Attribute>) { (cfgs, not_cfgs) } +fn check_for_blacklisted_attrs(attrs: &[Attribute]) -> Option<TokenStream> { + if let Some(val) = containts_blacklist_attrs(attrs) { + return Some(parse::Error::new(val.span(), "This attribute is not allowed [blacklisted]") + .to_compile_error() + .into()); + } + + None +} + +fn containts_blacklist_attrs(attrs: &[Attribute]) -> Option<Attribute> { + let blacklist = &["inline", "export_name", "no_mangle", "must_use"]; + + for attr in attrs { + for val in blacklist { + if eq(&attr, &val) { + return Some(attr.clone()); + } + } + } + + None +} + /// Returns `true` if `attr.path` matches `name` fn eq(attr: &Attribute, name: &str) -> bool { attr.style == AttrStyle::Outer && attr.path.is_ident(name) |