rust/compiler/rustc_const_eval/src/const_eval
Matthias Krüger 576176d8b7
Rollup merge of #133211 - Strophox:miri-correct-state-update-ffi, r=RalfJung
Extend Miri to correctly pass mutable pointers through FFI

Based off of https://github.com/rust-lang/rust/pull/129684, this PR further extends Miri to execute native calls that make use of pointers to *mutable* memory.
We adapt Miri's bookkeeping of internal state upon any FFI call that gives external code permission to mutate memory.

Native code may now possibly write and therefore initialize and change the pointer provenance of bytes it has access to: Such memory is assumed to be *initialized* afterwards and bytes are given *arbitrary (wildcard) provenance*. This enables programs that correctly use mutating FFI calls to run Miri without errors, at the cost of possibly missing Undefined Behaviour caused by incorrect usage of mutating FFI.

> <details>
>
> <summary> Simple example </summary>
>
> ```rust
> extern "C" {
>   fn init_int(ptr: *mut i32);
> }
>
> fn main() {
>   let mut x = std::mem::MaybeUninit::<i32>::uninit();
>   let x = unsafe {
>     init_int(x.as_mut_ptr());
>     x.assume_init()
>   };
>
>   println!("C initialized my memory to: {x}");
> }
> ```
> ```c
> void init_int(int *ptr) {
>   *ptr = 42;
> }
> ```
> should now show `C initialized my memory to: 42`.
>
> </details>

r? ``@RalfJung``
2024-12-06 09:27:39 +01:00
..
dummy_machine.rs extend Miri to correctly pass mutable pointers through FFI 2024-12-05 22:41:07 +01:00
error.rs fix ICE when promoted has layout size overflow 2024-12-01 19:52:27 +01:00
eval_queries.rs interpret: make typing_env field private 2024-11-20 11:05:53 +01:00
fn_queries.rs remove support for extern-block const intrinsics 2024-11-04 23:27:45 +01:00
machine.rs Rollup merge of #133211 - Strophox:miri-correct-state-update-ffi, r=RalfJung 2024-12-06 09:27:39 +01:00
mod.rs report UB when the niche value refers to the untagged variant 2024-11-30 18:26:30 +01:00
valtrees.rs InterpCx store TypingEnv instead of a ParamEnv 2024-11-19 21:36:23 +01:00