Skip to content

Commit 72bdafd

Browse files
committed
Change last_error to a place
1 parent 049e089 commit 72bdafd

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
@@ -308,25 +308,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
308308
/// Sets the last error variable
309309
fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
310310
let this = self.eval_context_mut();
311-
let tcx = &{ this.tcx.tcx };
312-
let errno_ptr = this.machine.last_error.unwrap();
313-
this.memory_mut().get_mut(errno_ptr.alloc_id)?.write_scalar(
314-
tcx,
315-
errno_ptr,
316-
scalar.into(),
317-
Size::from_bits(32),
318-
)
311+
let errno_place = this.machine.last_error.unwrap();
312+
this.write_scalar(scalar, errno_place.into())
319313
}
320314

321315
/// Gets the last error variable
322316
fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
323317
let this = self.eval_context_mut();
324-
let tcx = &{ this.tcx.tcx };
325-
let errno_ptr = this.machine.last_error.unwrap();
326-
this.memory()
327-
.get(errno_ptr.alloc_id)?
328-
.read_scalar(tcx, errno_ptr, Size::from_bits(32))?
329-
.not_undef()
318+
let errno_place = this.machine.last_error.unwrap();
319+
this.read_scalar(errno_place.into())?.not_undef()
330320
}
331321

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