Skip to content

Commit 72268da

Browse files
committed
Change last_error to a place
1 parent 258a306 commit 72268da

File tree

4 files changed

+9
-19
lines changed

4 files changed

+9
-19
lines changed

src/eval.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
187187
let errno_layout = ecx.layout_of(ecx.tcx.types.u32)?;
188188
let errno_place = ecx.allocate(errno_layout, MiriMemoryKind::Static.into());
189189
ecx.write_scalar(Scalar::from_u32(0), errno_place.into())?;
190-
let errno_ptr = ecx.check_mplace_access(errno_place.into(), Some(Size::from_bits(32)))?;
191-
ecx.machine.last_error = errno_ptr;
190+
ecx.machine.last_error = Some(errno_place);
192191

193192
Ok(ecx)
194193
}

src/helpers.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -352,25 +352,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
352352
/// Sets the last error variable
353353
fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
354354
let this = self.eval_context_mut();
355-
let tcx = &{ this.tcx.tcx };
356-
let errno_ptr = this.machine.last_error.unwrap();
357-
this.memory.get_mut(errno_ptr.alloc_id)?.write_scalar(
358-
tcx,
359-
errno_ptr,
360-
scalar.into(),
361-
Size::from_bits(32),
362-
)
355+
let errno_place = this.machine.last_error.unwrap();
356+
this.write_scalar(scalar, errno_place.into())
363357
}
364358

365359
/// Gets the last error variable
366360
fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
367361
let this = self.eval_context_mut();
368-
let tcx = &{ this.tcx.tcx };
369-
let errno_ptr = this.machine.last_error.unwrap();
370-
this.memory
371-
.get(errno_ptr.alloc_id)?
372-
.read_scalar(tcx, errno_ptr, Size::from_bits(32))?
373-
.not_undef()
362+
let errno_place = this.machine.last_error.unwrap();
363+
this.read_scalar(errno_place.into())?.not_undef()
374364
}
375365

376366
/// Sets the last error variable using a `std::io::Error`. It fails if the error cannot be

src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ pub struct Evaluator<'tcx> {
9191
pub(crate) argv: Option<Pointer<Tag>>,
9292
pub(crate) cmd_line: Option<Pointer<Tag>>,
9393

94-
/// Last OS error.
95-
pub(crate) last_error: Option<Pointer<Tag>>,
94+
/// Last OS error location in memory. It is a 32 bits integer (unsigned for Windows)
95+
pub(crate) last_error: Option<MPlaceTy<'tcx, Tag>>,
9696

9797
/// TLS state.
9898
pub(crate) tls: TlsData<'tcx>,

src/shims/foreign_items.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
419419
}
420420

421421
"__errno_location" | "__error" => {
422-
let errno_scalar: Scalar<Tag> = this.machine.last_error.unwrap().into();
422+
let errno_place = this.machine.last_error.unwrap();
423+
let errno_scalar: Scalar<Tag> = this.check_mplace_access(errno_place.into(), Some(Size::from_bits(32)))?.unwrap().into();
423424
this.write_scalar(errno_scalar, dest)?;
424425
}
425426

0 commit comments

Comments
 (0)