diff --git a/src/bindgen/parser.rs b/src/bindgen/parser.rs index af1b2023..26c25e42 100644 --- a/src/bindgen/parser.rs +++ b/src/bindgen/parser.rs @@ -728,7 +728,7 @@ impl Parse { items.join("::") }; - let is_extern_c = sig.abi.is_omitted() || sig.abi.is_c(); + let is_extern_c = sig.abi.is_omitted() || sig.abi.is_c() || sig.abi.is_cmse(); let exported_name = named_symbol.exported_name(); match (is_extern_c, exported_name) { diff --git a/src/bindgen/utilities.rs b/src/bindgen/utilities.rs index f4058313..b925ceb6 100644 --- a/src/bindgen/utilities.rs +++ b/src/bindgen/utilities.rs @@ -371,24 +371,19 @@ impl_syn_item_helper!(syn::ItemTraitAlias); /// Helper function for accessing Abi information pub trait SynAbiHelpers { fn is_c(&self) -> bool; + fn is_cmse(&self) -> bool; fn is_omitted(&self) -> bool; } impl SynAbiHelpers for Option { fn is_c(&self) -> bool { - if let Some(ref abi) = *self { - if let Some(ref lit_string) = abi.name { - return matches!(lit_string.value().as_str(), "C" | "C-unwind"); - } - } - false + self.as_ref().is_some_and(|abi| abi.is_c()) + } + fn is_cmse(&self) -> bool { + self.as_ref().is_some_and(|abi| abi.is_cmse()) } fn is_omitted(&self) -> bool { - if let Some(ref abi) = *self { - abi.name.is_none() - } else { - false - } + self.as_ref().is_some_and(|abi| abi.is_omitted()) } } @@ -400,6 +395,16 @@ impl SynAbiHelpers for syn::Abi { false } } + fn is_cmse(&self) -> bool { + if let Some(ref lit_string) = self.name { + matches!( + lit_string.value().as_str(), + "cmse-nonsecure-entry" | "cmse-nonsecure-call" + ) + } else { + false + } + } fn is_omitted(&self) -> bool { self.name.is_none() } diff --git a/tests/expectations-symbols/cmse.c.sym b/tests/expectations-symbols/cmse.c.sym new file mode 100644 index 00000000..5d8dd399 --- /dev/null +++ b/tests/expectations-symbols/cmse.c.sym @@ -0,0 +1,4 @@ +{ +foo; +bar; +}; \ No newline at end of file diff --git a/tests/expectations/cmse.c b/tests/expectations/cmse.c new file mode 100644 index 00000000..12d24d87 --- /dev/null +++ b/tests/expectations/cmse.c @@ -0,0 +1,8 @@ +#include +#include +#include +#include + +void foo(void); + +void bar(void); diff --git a/tests/expectations/cmse.compat.c b/tests/expectations/cmse.compat.c new file mode 100644 index 00000000..f9da6372 --- /dev/null +++ b/tests/expectations/cmse.compat.c @@ -0,0 +1,16 @@ +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +void foo(void); + +void bar(void); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/tests/expectations/cmse.cpp b/tests/expectations/cmse.cpp new file mode 100644 index 00000000..f3025954 --- /dev/null +++ b/tests/expectations/cmse.cpp @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include + +extern "C" { + +void foo(); + +void bar(); + +} // extern "C" diff --git a/tests/expectations/cmse.pyx b/tests/expectations/cmse.pyx new file mode 100644 index 00000000..51d33db6 --- /dev/null +++ b/tests/expectations/cmse.pyx @@ -0,0 +1,11 @@ +from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t +from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t +cdef extern from *: + ctypedef bint bool + ctypedef struct va_list + +cdef extern from *: + + void foo(); + + void bar(); diff --git a/tests/rust/cmse.rs b/tests/rust/cmse.rs new file mode 100644 index 00000000..e5878f33 --- /dev/null +++ b/tests/rust/cmse.rs @@ -0,0 +1,5 @@ +#[no_mangle] +pub extern "cmse-nonsecure-entry" fn foo() {} + +#[no_mangle] +pub extern "cmse-nonsecure-call" fn bar() {}