Skip to content

Commit 77d17a0

Browse files
defermelowieemilio
authored andcommitted
Check for CMSE ABI's as well
1 parent 3620e88 commit 77d17a0

8 files changed

Lines changed: 74 additions & 12 deletions

File tree

src/bindgen/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ impl Parse {
728728
items.join("::")
729729
};
730730

731-
let is_extern_c = sig.abi.is_omitted() || sig.abi.is_c();
731+
let is_extern_c = sig.abi.is_omitted() || sig.abi.is_c() || sig.abi.is_cmse();
732732
let exported_name = named_symbol.exported_name();
733733

734734
match (is_extern_c, exported_name) {

src/bindgen/utilities.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -384,24 +384,19 @@ impl_syn_item_helper!(syn::ItemTraitAlias);
384384
/// Helper function for accessing Abi information
385385
pub trait SynAbiHelpers {
386386
fn is_c(&self) -> bool;
387+
fn is_cmse(&self) -> bool;
387388
fn is_omitted(&self) -> bool;
388389
}
389390

390391
impl SynAbiHelpers for Option<syn::Abi> {
391392
fn is_c(&self) -> bool {
392-
if let Some(ref abi) = *self {
393-
if let Some(ref lit_string) = abi.name {
394-
return matches!(lit_string.value().as_str(), "C" | "C-unwind");
395-
}
396-
}
397-
false
393+
self.as_ref().is_some_and(|abi| abi.is_c())
394+
}
395+
fn is_cmse(&self) -> bool {
396+
self.as_ref().is_some_and(|abi| abi.is_cmse())
398397
}
399398
fn is_omitted(&self) -> bool {
400-
if let Some(ref abi) = *self {
401-
abi.name.is_none()
402-
} else {
403-
false
404-
}
399+
self.as_ref().is_some_and(|abi| abi.is_omitted())
405400
}
406401
}
407402

@@ -413,6 +408,16 @@ impl SynAbiHelpers for syn::Abi {
413408
false
414409
}
415410
}
411+
fn is_cmse(&self) -> bool {
412+
if let Some(ref lit_string) = self.name {
413+
matches!(
414+
lit_string.value().as_str(),
415+
"cmse-nonsecure-entry" | "cmse-nonsecure-call"
416+
)
417+
} else {
418+
false
419+
}
420+
}
416421
fn is_omitted(&self) -> bool {
417422
self.name.is_none()
418423
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
foo;
3+
bar;
4+
};

tests/expectations/cmse.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
void foo(void);
7+
8+
void bar(void);

tests/expectations/cmse.compat.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif // __cplusplus
9+
10+
void foo(void);
11+
12+
void bar(void);
13+
14+
#ifdef __cplusplus
15+
} // extern "C"
16+
#endif // __cplusplus

tests/expectations/cmse.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <cstdarg>
2+
#include <cstdint>
3+
#include <cstdlib>
4+
#include <ostream>
5+
#include <new>
6+
7+
extern "C" {
8+
9+
void foo();
10+
11+
void bar();
12+
13+
} // extern "C"

tests/expectations/cmse.pyx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from libc.stdint cimport int8_t, int16_t, int32_t, int64_t, intptr_t
2+
from libc.stdint cimport uint8_t, uint16_t, uint32_t, uint64_t, uintptr_t
3+
cdef extern from *:
4+
ctypedef bint bool
5+
ctypedef struct va_list
6+
7+
cdef extern from *:
8+
9+
void foo();
10+
11+
void bar();

tests/rust/cmse.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[no_mangle]
2+
pub extern "cmse-nonsecure-entry" fn foo() {}
3+
4+
#[no_mangle]
5+
pub extern "cmse-nonsecure-call" fn bar() {}

0 commit comments

Comments
 (0)