1
Fork 0

add more tests for cmse-nonsecure-call stack spills

This commit is contained in:
Folkert 2024-07-16 16:35:23 +02:00
parent 50ba821e12
commit 1e8606408d
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
8 changed files with 280 additions and 62 deletions

View file

@ -1,24 +0,0 @@
//@ build-pass
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
//@ needs-llvm-components: arm
#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
#![no_core]
#[lang="sized"]
pub trait Sized { }
#[lang="copy"]
pub trait Copy { }
impl Copy for u32 {}
extern "rust-intrinsic" {
pub fn transmute<T, U>(e: T) -> U;
}
#[no_mangle]
pub fn test(a: u32, b: u32, c: u32, d: u32) -> u32 {
let non_secure_function = unsafe {
transmute::<usize, extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32) -> u32>(
0x10000004,
)
};
non_secure_function(a, b, c, d)
}

View file

@ -1,24 +0,0 @@
//@ build-fail
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
//@ needs-llvm-components: arm
#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
#![no_core]
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}
impl Copy for u32 {}
extern "rust-intrinsic" {
pub fn transmute<T, U>(e: T) -> U;
}
#[no_mangle]
pub fn test(a: u32, b: u32, c: u32, d: u32, e: u32) -> u32 {
let non_secure_function = unsafe {
transmute::<usize, extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32>(
0x10000004,
)
};
non_secure_function(a, b, c, d, e) //~ ERROR [E0798]
}

View file

@ -1,14 +0,0 @@
error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/params-on-stack.rs:23:5
|
LL | let non_secure_function = unsafe {
| ------------------- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | non_secure_function(a, b, c, d, e)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ but its arguments don't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0798`.

View file

@ -0,0 +1,29 @@
//@ build-fail
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
//@ needs-llvm-components: arm
#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
#![no_core]
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}
impl Copy for u32 {}
#[repr(C, align(16))]
#[allow(unused)]
pub struct AlignRelevant(u32);
#[no_mangle]
pub fn test(
f1: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32,
f2: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u16, u16) -> u32,
f3: extern "C-cmse-nonsecure-call" fn(u32, u64, u32) -> u32,
f4: extern "C-cmse-nonsecure-call" fn(AlignRelevant, u32) -> u32,
f5: extern "C-cmse-nonsecure-call" fn([u32; 5]) -> u32,
) {
f1(1, 2, 3, 4, 5); //~ ERROR [E0798]
f2(1, 2, 3, 4, 5); //~ ERROR [E0798]
f3(1, 2, 3); //~ ERROR [E0798]
f4(AlignRelevant(1), 2); //~ ERROR [E0798]
f5([0xAA; 5]); //~ ERROR [E0798]
}

View file

@ -0,0 +1,58 @@
error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/params-via-stack.rs:24:5
|
LL | f1: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32, u32) -> u32,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f1(1, 2, 3, 4, 5);
| ^^^^^^^^^^^^^^^^^ but its arguments don't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/params-via-stack.rs:25:5
|
LL | f2: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u16, u16) -> u32,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f2(1, 2, 3, 4, 5);
| ^^^^^^^^^^^^^^^^^ but its arguments don't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/params-via-stack.rs:26:5
|
LL | f3: extern "C-cmse-nonsecure-call" fn(u32, u64, u32) -> u32,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f3(1, 2, 3);
| ^^^^^^^^^^^ but its arguments don't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/params-via-stack.rs:27:5
|
LL | f4: extern "C-cmse-nonsecure-call" fn(AlignRelevant, u32) -> u32,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f4(AlignRelevant(1), 2);
| ^^^^^^^^^^^^^^^^^^^^^^^ but its arguments don't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
error[E0798]: arguments for `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/params-via-stack.rs:28:5
|
LL | f5: extern "C-cmse-nonsecure-call" fn([u32; 5]) -> u32,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f5([0xAA; 5]);
| ^^^^^^^^^^^^^ but its arguments don't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass all their arguments via the 4 32-bit available argument registers
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0798`.

View file

@ -0,0 +1,41 @@
//@ build-fail
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
//@ needs-llvm-components: arm
#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
#![no_core]
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}
impl Copy for u32 {}
#[repr(C)]
pub struct ReprCU64(u64);
#[repr(C)]
pub struct ReprCBytes(u8, u8, u8, u8, u8);
#[repr(C)]
pub struct U64Compound(u32, u32);
#[repr(C, align(16))]
pub struct ReprCAlign16(u16);
#[no_mangle]
pub fn test(
f1: extern "C-cmse-nonsecure-call" fn() -> ReprCU64,
f2: extern "C-cmse-nonsecure-call" fn() -> ReprCBytes,
f3: extern "C-cmse-nonsecure-call" fn() -> U64Compound,
f4: extern "C-cmse-nonsecure-call" fn() -> ReprCAlign16,
f5: extern "C-cmse-nonsecure-call" fn() -> [u8; 5],
f6: extern "C-cmse-nonsecure-call" fn() -> u128, //~ WARNING [improper_ctypes_definitions]
f7: extern "C-cmse-nonsecure-call" fn() -> i128, //~ WARNING [improper_ctypes_definitions]
) {
f1(); //~ ERROR [E0798]
f2(); //~ ERROR [E0798]
f3(); //~ ERROR [E0798]
f4(); //~ ERROR [E0798]
f5(); //~ ERROR [E0798]
f6(); //~ ERROR [E0798]
f7(); //~ ERROR [E0798]
}

View file

@ -0,0 +1,97 @@
warning: `extern` fn uses type `u128`, which is not FFI-safe
--> $DIR/return-via-stack.rs:31:9
|
LL | f6: extern "C-cmse-nonsecure-call" fn() -> u128,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
= note: `#[warn(improper_ctypes_definitions)]` on by default
warning: `extern` fn uses type `i128`, which is not FFI-safe
--> $DIR/return-via-stack.rs:32:9
|
LL | f7: extern "C-cmse-nonsecure-call" fn() -> i128,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
|
= note: 128-bit integers don't currently have a known stable ABI
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/return-via-stack.rs:34:5
|
LL | f1: extern "C-cmse-nonsecure-call" fn() -> ReprCU64,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f1();
| ^^^^ but its return value doesn't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/return-via-stack.rs:35:5
|
LL | f2: extern "C-cmse-nonsecure-call" fn() -> ReprCBytes,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f2();
| ^^^^ but its return value doesn't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/return-via-stack.rs:36:5
|
LL | f3: extern "C-cmse-nonsecure-call" fn() -> U64Compound,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f3();
| ^^^^ but its return value doesn't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/return-via-stack.rs:37:5
|
LL | f4: extern "C-cmse-nonsecure-call" fn() -> ReprCAlign16,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f4();
| ^^^^ but its return value doesn't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/return-via-stack.rs:38:5
|
LL | f5: extern "C-cmse-nonsecure-call" fn() -> [u8; 5],
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f5();
| ^^^^ but its return value doesn't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/return-via-stack.rs:39:5
|
LL | f6: extern "C-cmse-nonsecure-call" fn() -> u128,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f6();
| ^^^^ but its return value doesn't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
error[E0798]: return value of `C-cmse-nonsecure-call` function too large to pass via registers
--> $DIR/return-via-stack.rs:40:5
|
LL | f7: extern "C-cmse-nonsecure-call" fn() -> i128,
| -- this function uses the `C-cmse-nonsecure-call` ABI
...
LL | f7();
| ^^^^ but its return value doesn't fit in the available registers
|
= note: functions with the `C-cmse-nonsecure-call` ABI must pass their result via the available return registers
error: aborting due to 7 previous errors; 2 warnings emitted
For more information about this error, try `rustc --explain E0798`.

View file

@ -0,0 +1,55 @@
//@ build-pass
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
//@ needs-llvm-components: arm
#![feature(abi_c_cmse_nonsecure_call, no_core, lang_items, intrinsics)]
#![no_core]
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}
impl Copy for u32 {}
#[repr(transparent)]
pub struct ReprTransparentU64(u64);
#[repr(C)]
pub struct U32Compound(u16, u16);
#[no_mangle]
#[allow(improper_ctypes_definitions)]
pub fn params(
f1: extern "C-cmse-nonsecure-call" fn(),
f2: extern "C-cmse-nonsecure-call" fn(u32, u32, u32, u32),
f3: extern "C-cmse-nonsecure-call" fn(u64, u64),
f4: extern "C-cmse-nonsecure-call" fn(u128),
f5: extern "C-cmse-nonsecure-call" fn(f64, f32, f32),
f6: extern "C-cmse-nonsecure-call" fn(ReprTransparentU64, U32Compound),
f7: extern "C-cmse-nonsecure-call" fn([u32; 4]),
) {
f1();
f2(1, 2, 3, 4);
f3(1, 2);
f4(1);
f5(1.0, 2.0, 3.0);
f6(ReprTransparentU64(1), U32Compound(2, 3));
f7([0xDEADBEEF; 4]);
}
#[no_mangle]
pub fn returns(
f1: extern "C-cmse-nonsecure-call" fn() -> u32,
f2: extern "C-cmse-nonsecure-call" fn() -> u64,
f3: extern "C-cmse-nonsecure-call" fn() -> i64,
f4: extern "C-cmse-nonsecure-call" fn() -> f64,
f5: extern "C-cmse-nonsecure-call" fn() -> [u8; 4],
f6: extern "C-cmse-nonsecure-call" fn() -> ReprTransparentU64,
f7: extern "C-cmse-nonsecure-call" fn() -> U32Compound,
) {
f1();
f2();
f3();
f4();
f5();
f6();
f7();
}