Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bindgen/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 16 additions & 11 deletions src/bindgen/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<syn::Abi> {
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())
}
}

Expand All @@ -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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure why these function shouldn't be tagged with __attribute__((cmse_nonsecure_call)) and __attribute__((cmse_nonsecure_entry)), respectively. Mind elaborating on that?

Copy link
Author

@defermelowie defermelowie Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off the top of my head, that's because these annotations instruct the compiler to create veneers for these functions which is only important at their definition (in rust), call sites shouldn't care about this.

)
} else {
false
}
}
fn is_omitted(&self) -> bool {
self.name.is_none()
}
Expand Down
4 changes: 4 additions & 0 deletions tests/expectations-symbols/cmse.c.sym
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
foo;
bar;
};
8 changes: 8 additions & 0 deletions tests/expectations/cmse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

void foo(void);

void bar(void);
16 changes: 16 additions & 0 deletions tests/expectations/cmse.compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void foo(void);

void bar(void);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
13 changes: 13 additions & 0 deletions tests/expectations/cmse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <cstdarg>
#include <cstdint>
#include <cstdlib>
#include <ostream>
#include <new>

extern "C" {

void foo();

void bar();

} // extern "C"
11 changes: 11 additions & 0 deletions tests/expectations/cmse.pyx
Original file line number Diff line number Diff line change
@@ -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();
5 changes: 5 additions & 0 deletions tests/rust/cmse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[no_mangle]
pub extern "cmse-nonsecure-entry" fn foo() {}

#[no_mangle]
pub extern "cmse-nonsecure-call" fn bar() {}