File tree 3 files changed +33
-0
lines changed
3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ //@ignore-target-windows: No libc on Windows
2
+ //@compile-flags: -Zmiri-permissive-provenance
3
+
4
+ #[ path = "../utils/mod.rs" ]
5
+ mod utils;
6
+
7
+ type GetEntropyFn = unsafe extern "C" fn ( * mut u8 , libc:: size_t ) -> libc:: c_int ;
8
+
9
+ fn main ( ) {
10
+ let name = "getentropy\0 " ;
11
+ let addr = unsafe { libc:: dlsym ( libc:: RTLD_DEFAULT , name. as_ptr ( ) as * const _ ) as usize } ;
12
+ // If the GC does not account for the extra_fn_ptr entry that this dlsym just added, this GC
13
+ // run will delete our entry for the base addr of the function pointer we will transmute to,
14
+ // and the call through the function pointer will report UB.
15
+ utils:: run_provenance_gc ( ) ;
16
+
17
+ let ptr = addr as * mut libc:: c_void ;
18
+ let func: GetEntropyFn = unsafe { std:: mem:: transmute ( ptr) } ;
19
+ let dest = & mut [ 0u8 ] ;
20
+ unsafe { func ( dest. as_mut_ptr ( ) , dest. len ( ) ) } ;
21
+ }
Original file line number Diff line number Diff line change @@ -137,4 +137,9 @@ extern "Rust" {
137
137
out : * mut std:: ffi:: c_char ,
138
138
out_size : usize ,
139
139
) -> usize ;
140
+
141
+ /// Run the provenance GC. The GC will run automatically at some cadence,
142
+ /// but in tests we want to for sure run it at certain points to check
143
+ /// that it doesn't break anything.
144
+ pub fn miri_run_provenance_gc ( ) ;
140
145
}
Original file line number Diff line number Diff line change @@ -9,3 +9,10 @@ mod miri_extern;
9
9
10
10
pub use fs:: * ;
11
11
pub use miri_extern:: * ;
12
+
13
+ pub fn run_provenance_gc ( ) {
14
+ // SAFETY: No preconditions. The GC is fine to run at any time.
15
+ unsafe {
16
+ miri_run_provenance_gc ( )
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments