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