Skip to main content

miri/shims/
mod.rs

1#![warn(clippy::arithmetic_side_effects)]
2
3mod alloc;
4mod backtrace;
5mod files;
6mod math;
7#[cfg(all(feature = "native-lib", unix))]
8pub mod native_lib;
9mod unix;
10mod windows;
11
12pub mod cpu_affinity;
13pub mod env;
14pub mod extern_static;
15pub mod foreign_items;
16pub mod global_ctor;
17pub mod io_error;
18pub mod os_str;
19pub mod panic;
20pub mod readiness;
21pub mod sig;
22pub mod time;
23pub mod tls;
24pub mod unwind;
25
26pub use self::cpu_affinity::CpuAffinityMask;
27pub use self::files::{FdId, FdTable, FileDescription, FileDescriptionRef, WeakFileDescriptionRef};
28#[cfg(all(feature = "native-lib", unix))]
29pub use self::native_lib::trace::{init_sv, register_retcode_sv};
30pub use self::readiness::DelayedReadinessUpdates;
31pub use self::unix::DirTable;
32
33/// What needs to be done after emulating an item (a shim or an intrinsic) is done.
34pub enum EmulateItemResult {
35    /// The caller is expected to jump to the return block.
36    NeedsReturn,
37    /// The caller is expected to jump to the unwind block.
38    NeedsUnwind,
39    /// Jumping to the next block has already been taken care of.
40    AlreadyJumped,
41    /// The item is not supported.
42    NotSupported,
43}
44
45impl EmulateItemResult {
46    pub fn jump_to_next_block<'tcx, T: Default>(
47        self,
48        ecx: &mut crate::MiriInterpCx<'tcx>,
49        dest: &crate::PlaceTy<'tcx>,
50        ret: Option<rustc_middle::mir::BasicBlock>,
51        unwind: Option<rustc_middle::mir::UnwindAction>,
52        not_supported: impl FnOnce(&mut crate::MiriInterpCx<'tcx>) -> crate::InterpResult<'tcx, T>,
53    ) -> crate::InterpResult<'tcx, T> {
54        use crate::*;
55
56        match self {
57            EmulateItemResult::NeedsReturn => {
58                trace!("{:?}", ecx.dump_place(dest));
59                ecx.return_to_block(ret)?;
60                interp_ok(T::default())
61            }
62            EmulateItemResult::NeedsUnwind => {
63                // Jump to the unwind block to begin unwinding.
64                ecx.unwind_to_block(unwind.unwrap())?;
65                interp_ok(T::default())
66            }
67            EmulateItemResult::AlreadyJumped => interp_ok(T::default()),
68            EmulateItemResult::NotSupported => not_supported(ecx),
69        }
70    }
71}