rust/tests/run-make/mte-ffi/foo_function.rs
Damian Heaton e8ce9fac85 Add tests to ensure MTE tags are preserved across FFI boundaries
Added run-make tests to verify that, between a Rust-C FFI boundary in both directions,
any MTE tags included in a pointer are preserved for the following pointer types, as
well as any information stored using TBI:
- int
- float
- string
- function
2024-07-30 10:12:51 +01:00

18 lines
466 B
Rust

#![crate_type = "cdylib"]
#![crate_name = "foo"]
extern "C" fn ret32() -> i32 {
32
}
#[no_mangle]
pub extern "C" fn foo(ptr: extern "C" fn(extern "C" fn() -> i32)) {
assert_eq!((ptr as usize) >> 56, 0x1f);
// Store an arbitrary tag in the tag bits, and convert back to the correct pointer type.
let p = ((ret32 as usize) | (0x2f << 56)) as *const ();
let p: extern "C" fn() -> i32 = unsafe { std::mem::transmute(p) };
unsafe { ptr(p) }
}