Skip to content

Commit 857f568

Browse files
committed
Change last_error to a place
1 parent a3e14c6 commit 857f568

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
@@ -343,25 +343,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
343343
/// Sets the last error variable
344344
fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
345345
let this = self.eval_context_mut();
346-
let tcx = &{ this.tcx.tcx };
347-
let errno_ptr = this.machine.last_error.unwrap();
348-
this.memory_mut().get_mut(errno_ptr.alloc_id)?.write_scalar(
349-
tcx,
350-
errno_ptr,
351-
scalar.into(),
352-
Size::from_bits(32),
353-
)
346+
let errno_place = this.machine.last_error.unwrap();
347+
this.write_scalar(scalar, errno_place.into())
354348
}
355349

356350
/// Gets the last error variable
357351
fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
358352
let this = self.eval_context_mut();
359-
let tcx = &{ this.tcx.tcx };
360-
let errno_ptr = this.machine.last_error.unwrap();
361-
this.memory()
362-
.get(errno_ptr.alloc_id)?
363-
.read_scalar(tcx, errno_ptr, Size::from_bits(32))?
364-
.not_undef()
353+
let errno_place = this.machine.last_error.unwrap();
354+
this.read_scalar(errno_place.into())?.not_undef()
365355
}
366356

367357
/// 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)