]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/foreign_items.rs
Fix merge conflicts
[rust.git] / src / shims / foreign_items.rs
index cfbb02f608130deda2e6ecc30c078bc8ddc8f9ff..1933aee1151dc3b3b4cef7b8a5a610ca1ff55b90 100644 (file)
@@ -50,7 +50,7 @@ fn malloc(&mut self, size: u64, zero_init: bool, kind: MiriMemoryKind) -> Scalar
                 .memory
                 .allocate(Size::from_bytes(size), align, kind.into());
             if zero_init {
-                // We just allocated this, the access cannot fail
+                // We just allocated this, the access is definitely in-bounds.
                 this.memory
                     .get_mut(ptr.alloc_id)
                     .unwrap()
@@ -227,7 +227,7 @@ fn emulate_foreign_item(
                     Align::from_bytes(align).unwrap(),
                     MiriMemoryKind::Rust.into(),
                 );
-                // We just allocated this, the access cannot fail
+                // We just allocated this, the access is definitely in-bounds.
                 this.memory
                     .get_mut(ptr.alloc_id)
                     .unwrap()
@@ -349,10 +349,7 @@ fn emulate_foreign_item(
                 let arg_dest = this.local_place(arg_local)?;
                 this.write_scalar(data, arg_dest)?;
 
-                assert!(
-                    args.next().is_none(),
-                    "__rust_maybe_catch_panic argument has more arguments than expected"
-                );
+                args.next().expect_none("__rust_maybe_catch_panic argument has more arguments than expected");
 
                 // We ourselves will return `0`, eventually (because we will not return if we paniced).
                 this.write_null(dest)?;
@@ -417,8 +414,8 @@ fn emulate_foreign_item(
             }
 
             "__errno_location" | "__error" => {
-                let errno_scalar: Scalar<Tag> = this.machine.last_error.unwrap().into();
-                this.write_scalar(errno_scalar, dest)?;
+                let errno_place = this.machine.last_error.unwrap();
+                this.write_scalar(errno_place.to_ref().to_scalar()?, dest)?;
             }
 
             "getenv" => {
@@ -643,7 +640,7 @@ fn emulate_foreign_item(
 
             // Hook pthread calls that go to the thread-local storage memory subsystem.
             "pthread_key_create" => {
-                let key_ptr = this.read_scalar(args[0])?.not_undef()?;
+                let key_place = this.deref_operand(args[0])?;
 
                 // Extract the function type out of the signature (that seems easier than constructing it ourselves).
                 let dtor = match this.test_null(this.read_scalar(args[1])?.not_undef()?)? {
@@ -668,16 +665,7 @@ fn emulate_foreign_item(
                     throw_unsup!(OutOfTls);
                 }
 
-                let key_ptr = this
-                    .memory
-                    .check_ptr_access(key_ptr, key_layout.size, key_layout.align.abi)?
-                    .expect("cannot be a ZST");
-                this.memory.get_mut(key_ptr.alloc_id)?.write_scalar(
-                    tcx,
-                    key_ptr,
-                    Scalar::from_uint(key, key_layout.size).into(),
-                    key_layout.size,
-                )?;
+                this.write_scalar(Scalar::from_uint(key, key_layout.size), key_place.into())?;
 
                 // Return success (`0`).
                 this.write_null(dest)?;
@@ -856,6 +844,7 @@ fn emulate_foreign_item(
                 let system_info_ptr = this
                     .check_mplace_access(system_info, None)?
                     .expect("cannot be a ZST");
+                // We rely on `deref_operand` doing bounds checks for us.
                 // Initialize with `0`.
                 this.memory
                     .get_mut(system_info_ptr.alloc_id)?
@@ -988,33 +977,6 @@ fn eval_path_scalar(
         }
         return Ok(None);
     }
-
-    fn set_last_error(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx> {
-        let this = self.eval_context_mut();
-        let errno_ptr = this.machine.last_error.unwrap();
-        this.memory.get_mut(errno_ptr.alloc_id)?.write_scalar(
-            &*this.tcx,
-            errno_ptr,
-            scalar.into(),
-            Size::from_bits(32),
-        )
-    }
-
-    fn get_last_error(&mut self) -> InterpResult<'tcx, Scalar<Tag>> {
-        let this = self.eval_context_mut();
-        let errno_ptr = this.machine.last_error.unwrap();
-        this.memory
-            .get(errno_ptr.alloc_id)?
-            .read_scalar(&*this.tcx, errno_ptr, Size::from_bits(32))?
-            .not_undef()
-    }
-
-    fn consume_io_error(&mut self, e: std::io::Error) -> InterpResult<'tcx> {
-        self.eval_context_mut().set_last_error(Scalar::from_int(
-            e.raw_os_error().unwrap(),
-            Size::from_bits(32),
-        ))
-    }
 }
 
 // Shims the linux 'getrandom()' syscall.