Skip to content

Commit ed776f6

Browse files
committed
Change last_error to a place
1 parent 4232939 commit ed776f6

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

189188
Ok(ecx)
190189
}

src/helpers.rs

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

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

373363
/// 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
@@ -414,7 +414,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
414414
}
415415

416416
"__errno_location" | "__error" => {
417-
let errno_scalar: Scalar<Tag> = this.machine.last_error.unwrap().into();
417+
let errno_place = this.machine.last_error.unwrap();
418+
let errno_scalar: Scalar<Tag> = this.check_mplace_access(errno_place.into(), Some(Size::from_bits(32)))?.unwrap().into();
418419
this.write_scalar(errno_scalar, dest)?;
419420
}
420421

0 commit comments

Comments
 (0)