miri/shims/wasi/
foreign_items.rs

1use rustc_middle::ty::Ty;
2use rustc_span::Symbol;
3use rustc_target::callconv::{Conv, FnAbi};
4
5use crate::shims::alloc::EvalContextExt as _;
6use crate::*;
7
8pub fn is_dyn_sym(_name: &str) -> bool {
9    false
10}
11
12impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
13pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
14    fn emulate_foreign_item_inner(
15        &mut self,
16        link_name: Symbol,
17        abi: &FnAbi<'tcx, Ty<'tcx>>,
18        args: &[OpTy<'tcx>],
19        dest: &MPlaceTy<'tcx>,
20    ) -> InterpResult<'tcx, EmulateItemResult> {
21        let this = self.eval_context_mut();
22        match link_name.as_str() {
23            // Allocation
24            "posix_memalign" => {
25                let [memptr, align, size] = this.check_shim(abi, Conv::C, link_name, args)?;
26                let result = this.posix_memalign(memptr, align, size)?;
27                this.write_scalar(result, dest)?;
28            }
29            "aligned_alloc" => {
30                let [align, size] = this.check_shim(abi, Conv::C, link_name, args)?;
31                let res = this.aligned_alloc(align, size)?;
32                this.write_pointer(res, dest)?;
33            }
34
35            _ => return interp_ok(EmulateItemResult::NotSupported),
36        }
37        interp_ok(EmulateItemResult::NeedsReturn)
38    }
39}