miri/shims/unix/linux/
mem.rs1use rustc_abi::Size;
5
6use crate::*;
7
8impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
9pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10 fn mremap(
11 &mut self,
12 old_address: &OpTy<'tcx>,
13 old_size: &OpTy<'tcx>,
14 new_size: &OpTy<'tcx>,
15 flags: &OpTy<'tcx>,
16 ) -> InterpResult<'tcx, Scalar> {
17 let this = self.eval_context_mut();
18
19 let old_address = this.read_pointer(old_address)?;
20 let old_size = this.read_target_usize(old_size)?;
21 let new_size = this.read_target_usize(new_size)?;
22 let flags = this.read_scalar(flags)?.to_i32()?;
23
24 if !old_address.addr().bytes().is_multiple_of(this.machine.page_size) || new_size == 0 {
26 this.set_last_error(LibcError("EINVAL"))?;
27 return interp_ok(this.eval_libc("MAP_FAILED"));
28 }
29
30 if flags & this.eval_libc_i32("MREMAP_FIXED") != 0 {
31 throw_unsup_format!("Miri does not support mremap wth MREMAP_FIXED");
32 }
33
34 if flags & this.eval_libc_i32("MREMAP_DONTUNMAP") != 0 {
35 throw_unsup_format!("Miri does not support mremap wth MREMAP_DONTUNMAP");
36 }
37
38 if flags & this.eval_libc_i32("MREMAP_MAYMOVE") == 0 {
39 this.set_last_error(LibcError("EINVAL"))?;
41 return interp_ok(this.eval_libc("MAP_FAILED"));
42 }
43
44 let align = this.machine.page_align();
45 let ptr = this.reallocate_ptr(
46 old_address,
47 Some((Size::from_bytes(old_size), align)),
48 Size::from_bytes(new_size),
49 align,
50 MiriMemoryKind::Mmap.into(),
51 AllocInit::Zero,
52 )?;
53
54 interp_ok(Scalar::from_pointer(ptr, this))
55 }
56}