]> git.lizzy.rs Git - rust.git/commitdiff
Change last_error to a place
authorChristian Poveda <christianpoveda@protonmail.com>
Sun, 13 Oct 2019 01:58:02 +0000 (20:58 -0500)
committerChristian Poveda <christianpoveda@protonmail.com>
Sun, 20 Oct 2019 12:42:59 +0000 (07:42 -0500)
src/eval.rs
src/helpers.rs
src/machine.rs
src/shims/foreign_items.rs

index 6fb1cd25b159f4944e40bb6811b6518c3b70c47f..f4a8d176172d47908e0734a98c310e937a93c422 100644 (file)
@@ -183,8 +183,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
     let errno_layout = ecx.layout_of(ecx.tcx.types.u32)?;
     let errno_place = ecx.allocate(errno_layout, MiriMemoryKind::Static.into());
     ecx.write_scalar(Scalar::from_u32(0), errno_place.into())?;
-    let errno_ptr = ecx.check_mplace_access(errno_place.into(), Some(Size::from_bits(32)))?;
-    ecx.machine.last_error = errno_ptr;
+    ecx.machine.last_error = Some(errno_place);
 
     Ok(ecx)
 }
index 36091d9235550ed207d23017f4dd9073277b1815..1b80166b2fe72e0d08ead65b0b80e3a99f0eccba 100644 (file)
@@ -349,25 +349,15 @@ fn check_no_isolation(&mut self, name: &str) -> InterpResult<'tcx> {
     /// Sets the last error variable
     fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
         let this = self.eval_context_mut();
-        let tcx = &{ this.tcx.tcx };
-        let errno_ptr = this.machine.last_error.unwrap();
-        this.memory.get_mut(errno_ptr.alloc_id)?.write_scalar(
-            tcx,
-            errno_ptr,
-            scalar.into(),
-            Size::from_bits(32),
-        )
+        let errno_place = this.machine.last_error.unwrap();
+        this.write_scalar(scalar, errno_place.into())
     }
 
     /// Gets the last error variable
     fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
         let this = self.eval_context_mut();
-        let tcx = &{ this.tcx.tcx };
-        let errno_ptr = this.machine.last_error.unwrap();
-        this.memory
-            .get(errno_ptr.alloc_id)?
-            .read_scalar(tcx, errno_ptr, Size::from_bits(32))?
-            .not_undef()
+        let errno_place = this.machine.last_error.unwrap();
+        this.read_scalar(errno_place.into())?.not_undef()
     }
 
     /// Sets the last error variable using a `std::io::Error`. It fails if the error cannot be
index 3878a0860538f7f18de97ebb5be56706f40b1421..3714aa2d799e3a55677a8c745eed23337c6e4a58 100644 (file)
@@ -91,8 +91,8 @@ pub struct Evaluator<'tcx> {
     pub(crate) argv: Option<Pointer<Tag>>,
     pub(crate) cmd_line: Option<Pointer<Tag>>,
 
-    /// Last OS error.
-    pub(crate) last_error: Option<Pointer<Tag>>,
+    /// Last OS error location in memory. It is a 32 bits integer (unsigned for Windows)
+    pub(crate) last_error: Option<MPlaceTy<'tcx, Tag>>,
 
     /// TLS state.
     pub(crate) tls: TlsData<'tcx>,
index 5d2c3648b43a5e61c8d1634471f9858860e9ab04..51be7ea5bcd392a0a9345b3f2e41b404a727e6e5 100644 (file)
@@ -414,7 +414,8 @@ fn emulate_foreign_item(
             }
 
             "__errno_location" | "__error" => {
-                let errno_scalar: Scalar<Tag> = this.machine.last_error.unwrap().into();
+                let errno_place = this.machine.last_error.unwrap();
+                let errno_scalar: Scalar<Tag> = this.check_mplace_access(errno_place.into(), Some(Size::from_bits(32)))?.unwrap().into();
                 this.write_scalar(errno_scalar, dest)?;
             }