-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that the GC consults the extra_fn_ptr map
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//@ignore-target-windows: No libc on Windows | ||
//@compile-flags: -Zmiri-permissive-provenance | ||
|
||
#[path = "../utils/mod.rs"] | ||
mod utils; | ||
|
||
type GetEntropyFn = unsafe extern "C" fn(*mut u8, libc::size_t) -> libc::c_int; | ||
|
||
fn main() { | ||
let name = "getentropy\0"; | ||
let addr = unsafe { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr() as *const _) as usize }; | ||
// If the GC does not account for the extra_fn_ptr entry that this dlsym just added, this GC | ||
// run will delete our entry for the base addr of the function pointer we will transmute to, | ||
// and the call through the function pointer will report UB. | ||
utils::run_provenance_gc(); | ||
|
||
let ptr = addr as *mut libc::c_void; | ||
let func: GetEntropyFn = unsafe { std::mem::transmute(ptr) }; | ||
let dest = &mut [0u8]; | ||
unsafe { func(dest.as_mut_ptr(), dest.len()) }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters