// Writes several `ImmTy`s contiguosly into memory. This is useful when you have to pack
// different values into a struct.
- fn write_immediates(
+ fn write_packed_immediates(
&mut self,
- ptr: &Pointer<Tag>,
+ place: &MPlaceTy<'tcx, Tag>,
imms: &[ImmTy<'tcx, Tag>],
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let tcx = &{ this.tcx.tcx };
- let allocation = this.memory_mut().get_mut(ptr.alloc_id)?;
let mut offset = Size::from_bytes(0);
- for imm in imms {
- let size = imm.layout.size;
- allocation.write_scalar(
- tcx,
- ptr.offset(offset, tcx)?,
- imm.to_scalar()?.into(),
- size,
+ for &imm in imms {
+ this.write_immediate_to_mplace(
+ *imm,
+ place.offset(offset, None, imm.layout, tcx)?,
)?;
- offset += size;
+ offset += imm.layout.size;
}
Ok(())
fn get_time<'tcx>() -> InterpResult<'tcx, Duration> {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
- .map_err(|_| err_unsup_format!("Time went backwards").into())
+ .map_err(|_| err_unsup_format!("Times before the Unix epoch are not supported").into())
}
fn int_to_immty_checked<'tcx>(
return Ok(-1);
}
- let tp = this.force_ptr(this.read_scalar(tp_op)?.not_undef()?)?;
+ let tp = this.deref_operand(tp_op)?;
let duration = get_time()?;
let tv_sec = duration.as_secs() as i128;
int_to_immty_checked(tv_nsec, this.libc_ty_layout("c_long")?)?,
];
- this.write_immediates(&tp, &imms)?;
+ this.write_packed_immediates(&tp, &imms)?;
Ok(0)
}
- // Foreign function used by generic unix
+ // Foreign function used by generic unix (in particular macOS)
fn gettimeofday(
&mut self,
tv_op: OpTy<'tcx, Tag>,
return Ok(-1);
}
- let tv = this.force_ptr(this.read_scalar(tv_op)?.not_undef()?)?;
+ let tv = this.deref_operand(tv_op)?;
let duration = get_time()?;
let tv_sec = duration.as_secs() as i128;
int_to_immty_checked(tv_usec, this.libc_ty_layout("suseconds_t")?)?,
];
- this.write_immediates(&tv, &imms)?;
+ this.write_packed_immediates(&tv, &imms)?;
Ok(0)
}