Skip to content

Commit

Permalink
Auto merge of #1470 - RalfJung:machine-tracking, r=RalfJung
Browse files Browse the repository at this point in the history
we cannot track all machine memory any more due to int-ptr-casts

Fixes a regression introduced by rust-lang/rust#74006
  • Loading branch information
bors committed Jul 8, 2020
2 parents 5e94f57 + dcb0f63 commit 578aebf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e1beee4992ad4b235fc700bf7af1ee86f894ea53
8ac1525e091d3db28e67adcbbd6db1e1deaa37fb
12 changes: 8 additions & 4 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,17 @@ 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.
Env,
/// Globals copied from `tcx`.
/// This memory may leak.
Global,
/// Memory for extern statics.
/// This memory may leak.
ExternGlobal,
}

impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind {
Expand All @@ -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,
}
}
}
Expand All @@ -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"),
}
}
}
Expand Down Expand Up @@ -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"
Expand All @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/stacked_borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 578aebf

Please sign in to comment.