Skip to content

Commit 5d0c74d

Browse files
committed
Change last_error to a place
1 parent 4d2b913 commit 5d0c74d

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
@@ -186,8 +186,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
186186
let errno_layout = ecx.layout_of(ecx.tcx.types.u32)?;
187187
let errno_place = ecx.allocate(errno_layout, MiriMemoryKind::Static.into());
188188
ecx.write_scalar(Scalar::from_u32(0), errno_place.into())?;
189-
let errno_ptr = ecx.check_mplace_access(errno_place.into(), Some(Size::from_bits(32)))?;
190-
ecx.machine.last_error = errno_ptr;
189+
ecx.machine.last_error = Some(errno_place);
191190

192191
Ok(ecx)
193192
}

src/helpers.rs

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

361355
/// Gets the last error variable
362356
fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
363357
let this = self.eval_context_mut();
364-
let tcx = &{ this.tcx.tcx };
365-
let errno_ptr = this.machine.last_error.unwrap();
366-
this.memory
367-
.get(errno_ptr.alloc_id)?
368-
.read_scalar(tcx, errno_ptr, Size::from_bits(32))?
369-
.not_undef()
358+
let errno_place = this.machine.last_error.unwrap();
359+
this.read_scalar(errno_place.into())?.not_undef()
370360
}
371361

372362
/// 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
@@ -417,7 +417,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
417417
}
418418

419419
"__errno_location" | "__error" => {
420-
let errno_scalar: Scalar<Tag> = this.machine.last_error.unwrap().into();
420+
let errno_place = this.machine.last_error.unwrap();
421+
let errno_scalar: Scalar<Tag> = this.check_mplace_access(errno_place.into(), Some(Size::from_bits(32)))?.unwrap().into();
421422
this.write_scalar(errno_scalar, dest)?;
422423
}
423424

0 commit comments

Comments
 (0)