From dcb0f6309e93fd302952c1e8a7fb890fd32a5548 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 8 Jul 2020 11:05:22 +0200 Subject: [PATCH] we cannot track all machine memory any more due to int-ptr-casts --- rust-version | 2 +- src/machine.rs | 12 ++++++++---- src/shims/env.rs | 4 ++-- src/stacked_borrows.rs | 6 +++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/rust-version b/rust-version index e339c77f1a..f1a465c7d6 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -e1beee4992ad4b235fc700bf7af1ee86f894ea53 +8ac1525e091d3db28e67adcbbd6db1e1deaa37fb diff --git a/src/machine.rs b/src/machine.rs index f23d8833bd..49d647838c 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -54,7 +54,7 @@ pub enum MiriMemoryKind { C, /// Windows `HeapAlloc` memory. WinHeap, - /// Memory for args, errno, extern statics and other parts of the machine-managed environment. + /// Memory for args, errno, and other parts of the machine-managed environment. /// This memory may leak. Machine, /// Memory for env vars. Separate from `Machine` because we clean it up and leak-check it. @@ -62,6 +62,9 @@ pub enum MiriMemoryKind { /// Globals copied from `tcx`. /// This memory may leak. Global, + /// Memory for extern statics. + /// This memory may leak. + ExternGlobal, } impl Into> for MiriMemoryKind { @@ -77,7 +80,7 @@ impl MayLeak for MiriMemoryKind { use self::MiriMemoryKind::*; match self { Rust | C | WinHeap | Env => false, - Machine | Global => true, + Machine | Global | ExternGlobal => true, } } } @@ -92,6 +95,7 @@ impl fmt::Display for MiriMemoryKind { Machine => write!(f, "machine-managed memory"), Env => write!(f, "environment variable"), Global => write!(f, "global"), + ExternGlobal => write!(f, "extern global"), } } } @@ -171,7 +175,7 @@ impl MemoryExtra { // "__cxa_thread_atexit_impl" // This should be all-zero, pointer-sized. let layout = this.machine.layouts.usize; - let place = this.allocate(layout, MiriMemoryKind::Machine.into()); + let place = this.allocate(layout, MiriMemoryKind::ExternGlobal.into()); this.write_scalar(Scalar::from_machine_usize(0, this), place.into())?; Self::add_extern_static(this, "__cxa_thread_atexit_impl", place.ptr); // "environ" @@ -181,7 +185,7 @@ impl MemoryExtra { // "_tls_used" // This is some obscure hack that is part of the Windows TLS story. It's a `u8`. let layout = this.machine.layouts.u8; - let place = this.allocate(layout, MiriMemoryKind::Machine.into()); + let place = this.allocate(layout, MiriMemoryKind::ExternGlobal.into()); this.write_scalar(Scalar::from_u8(0), place.into())?; Self::add_extern_static(this, "_tls_used", place.ptr); } diff --git a/src/shims/env.rs b/src/shims/env.rs index 8459aa3241..4a2bec28bd 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -383,9 +383,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.memory.deallocate(this.force_ptr(old_vars_ptr)?, None, MiriMemoryKind::Env.into())?; } else { // No `environ` allocated yet, let's do that. - // This is memory backing an extern static, hence `Machine`, not `Env`. + // This is memory backing an extern static, hence `ExternGlobal`, not `Env`. let layout = this.machine.layouts.usize; - let place = this.allocate(layout, MiriMemoryKind::Machine.into()); + let place = this.allocate(layout, MiriMemoryKind::ExternGlobal.into()); this.machine.env_vars.environ = Some(place); } diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index 3c263670bc..6942acc5e2 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -466,13 +466,13 @@ impl Stacks { // everything else off the stack, invalidating all previous pointers, // and in particular, *all* raw pointers. MemoryKind::Stack => (Tag::Tagged(extra.borrow_mut().new_ptr()), Permission::Unique), - // Global memory can be referenced by global pointers from `tcx`. + // `Global` memory can be referenced by global pointers from `tcx`. // Thus we call `global_base_ptr` such that the global pointers get the same tag // as what we use here. - // `Machine` is used for extern statics, and thus must also be listed here. + // `ExternGlobal` is used for extern statics, and thus must also be listed here. // `Env` we list because we can get away with precise tracking there. // The base pointer is not unique, so the base permission is `SharedReadWrite`. - MemoryKind::Machine(MiriMemoryKind::Global | MiriMemoryKind::Machine | MiriMemoryKind::Env) => + MemoryKind::Machine(MiriMemoryKind::Global | MiriMemoryKind::ExternGlobal | MiriMemoryKind::Env) => (extra.borrow_mut().global_base_ptr(id), Permission::SharedReadWrite), // Everything else we handle entirely untagged for now. // FIXME: experiment with more precise tracking.