Skip to content

Commit 578aebf

Browse files
committed
Auto merge of #1470 - RalfJung:machine-tracking, r=RalfJung
we cannot track all machine memory any more due to int-ptr-casts Fixes a regression introduced by #74006
2 parents 5e94f57 + dcb0f63 commit 578aebf

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e1beee4992ad4b235fc700bf7af1ee86f894ea53
1+
8ac1525e091d3db28e67adcbbd6db1e1deaa37fb

src/machine.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ pub enum MiriMemoryKind {
5454
C,
5555
/// Windows `HeapAlloc` memory.
5656
WinHeap,
57-
/// Memory for args, errno, extern statics and other parts of the machine-managed environment.
57+
/// Memory for args, errno, and other parts of the machine-managed environment.
5858
/// This memory may leak.
5959
Machine,
6060
/// Memory for env vars. Separate from `Machine` because we clean it up and leak-check it.
6161
Env,
6262
/// Globals copied from `tcx`.
6363
/// This memory may leak.
6464
Global,
65+
/// Memory for extern statics.
66+
/// This memory may leak.
67+
ExternGlobal,
6568
}
6669

6770
impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind {
@@ -77,7 +80,7 @@ impl MayLeak for MiriMemoryKind {
7780
use self::MiriMemoryKind::*;
7881
match self {
7982
Rust | C | WinHeap | Env => false,
80-
Machine | Global => true,
83+
Machine | Global | ExternGlobal => true,
8184
}
8285
}
8386
}
@@ -92,6 +95,7 @@ impl fmt::Display for MiriMemoryKind {
9295
Machine => write!(f, "machine-managed memory"),
9396
Env => write!(f, "environment variable"),
9497
Global => write!(f, "global"),
98+
ExternGlobal => write!(f, "extern global"),
9599
}
96100
}
97101
}
@@ -171,7 +175,7 @@ impl MemoryExtra {
171175
// "__cxa_thread_atexit_impl"
172176
// This should be all-zero, pointer-sized.
173177
let layout = this.machine.layouts.usize;
174-
let place = this.allocate(layout, MiriMemoryKind::Machine.into());
178+
let place = this.allocate(layout, MiriMemoryKind::ExternGlobal.into());
175179
this.write_scalar(Scalar::from_machine_usize(0, this), place.into())?;
176180
Self::add_extern_static(this, "__cxa_thread_atexit_impl", place.ptr);
177181
// "environ"
@@ -181,7 +185,7 @@ impl MemoryExtra {
181185
// "_tls_used"
182186
// This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
183187
let layout = this.machine.layouts.u8;
184-
let place = this.allocate(layout, MiriMemoryKind::Machine.into());
188+
let place = this.allocate(layout, MiriMemoryKind::ExternGlobal.into());
185189
this.write_scalar(Scalar::from_u8(0), place.into())?;
186190
Self::add_extern_static(this, "_tls_used", place.ptr);
187191
}

src/shims/env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
383383
this.memory.deallocate(this.force_ptr(old_vars_ptr)?, None, MiriMemoryKind::Env.into())?;
384384
} else {
385385
// No `environ` allocated yet, let's do that.
386-
// This is memory backing an extern static, hence `Machine`, not `Env`.
386+
// This is memory backing an extern static, hence `ExternGlobal`, not `Env`.
387387
let layout = this.machine.layouts.usize;
388-
let place = this.allocate(layout, MiriMemoryKind::Machine.into());
388+
let place = this.allocate(layout, MiriMemoryKind::ExternGlobal.into());
389389
this.machine.env_vars.environ = Some(place);
390390
}
391391

src/stacked_borrows.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,13 @@ impl Stacks {
466466
// everything else off the stack, invalidating all previous pointers,
467467
// and in particular, *all* raw pointers.
468468
MemoryKind::Stack => (Tag::Tagged(extra.borrow_mut().new_ptr()), Permission::Unique),
469-
// Global memory can be referenced by global pointers from `tcx`.
469+
// `Global` memory can be referenced by global pointers from `tcx`.
470470
// Thus we call `global_base_ptr` such that the global pointers get the same tag
471471
// as what we use here.
472-
// `Machine` is used for extern statics, and thus must also be listed here.
472+
// `ExternGlobal` is used for extern statics, and thus must also be listed here.
473473
// `Env` we list because we can get away with precise tracking there.
474474
// The base pointer is not unique, so the base permission is `SharedReadWrite`.
475-
MemoryKind::Machine(MiriMemoryKind::Global | MiriMemoryKind::Machine | MiriMemoryKind::Env) =>
475+
MemoryKind::Machine(MiriMemoryKind::Global | MiriMemoryKind::ExternGlobal | MiriMemoryKind::Env) =>
476476
(extra.borrow_mut().global_base_ptr(id), Permission::SharedReadWrite),
477477
// Everything else we handle entirely untagged for now.
478478
// FIXME: experiment with more precise tracking.

0 commit comments

Comments
 (0)