mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
e8ce9fac85
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
28 lines
630 B
Rust
28 lines
630 B
Rust
#![crate_type = "cdylib"]
|
|
#![crate_name = "foo"]
|
|
|
|
use std::arch::asm;
|
|
use std::ffi::{CStr, CString};
|
|
use std::os::raw::c_char;
|
|
|
|
extern "C" {
|
|
fn bar(ptr: *const c_char);
|
|
}
|
|
|
|
#[no_mangle]
|
|
pub extern "C" fn foo(ptr: *const c_char) {
|
|
assert_eq!((ptr as usize) >> 56, 0x1f);
|
|
|
|
let s = unsafe { CStr::from_ptr(ptr) };
|
|
assert_eq!(s.to_str().unwrap(), "ab");
|
|
|
|
let s = CString::from_vec_with_nul("cd\0".into()).unwrap();
|
|
let mut p = ((s.as_ptr() as usize) | (0x2f << 56)) as *const c_char;
|
|
unsafe {
|
|
#[cfg(target_feature = "mte")]
|
|
asm!("stg {p}, [{p}]", p = inout(reg) p);
|
|
|
|
bar(p);
|
|
}
|
|
}
|