Skip to content

Commit 636961c

Browse files
committed
fix init_allocation_extra
1 parent 07566dc commit 636961c

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

src/eval.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
8787
arg.push(0);
8888
argvs.push(
8989
ecx.memory
90-
.allocate_static_bytes(arg.as_slice(), MiriMemoryKind::Static.into()),
90+
.allocate_static_bytes(arg.as_slice(), MiriMemoryKind::Env.into()),
9191
);
9292
}
9393
// Make an array with all these pointers, in the Miri memory.
@@ -138,7 +138,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
138138
// Return place (in static memory so that it does not count as leak).
139139
let ret_place = ecx.allocate(
140140
ecx.layout_of(tcx.types.isize)?,
141-
MiriMemoryKind::Static.into(),
141+
MiriMemoryKind::Env.into(),
142142
);
143143
// Call start function.
144144
ecx.call_function(
@@ -150,7 +150,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
150150

151151
// Set the last_error to 0
152152
let errno_layout = ecx.layout_of(tcx.types.u32)?;
153-
let errno_place = ecx.allocate(errno_layout, MiriMemoryKind::Static.into());
153+
let errno_place = ecx.allocate(errno_layout, MiriMemoryKind::Env.into());
154154
ecx.write_scalar(Scalar::from_u32(0), errno_place.into())?;
155155
ecx.machine.last_error = Some(errno_place);
156156

src/machine.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ pub enum MiriMemoryKind {
4343
C,
4444
/// Windows `HeapAlloc` memory.
4545
WinHeap,
46-
/// Part of env var emulation.
46+
/// Memory for env vars and args, errno and other parts of the machine-managed environment.
4747
Env,
48-
/// Statics.
48+
/// Rust statics.
4949
Static,
5050
}
5151

@@ -296,19 +296,20 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
296296
id: AllocId,
297297
alloc: Cow<'b, Allocation>,
298298
kind: Option<MemoryKind<Self::MemoryKinds>>,
299-
) -> Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>> {
299+
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag) {
300300
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
301301
let alloc = alloc.into_owned();
302-
let stacks = if memory_extra.validate {
303-
Some(Stacks::new_allocation(
302+
let (stacks, base_tag) = if memory_extra.validate {
303+
let (stacks, base_tag) = Stacks::new_allocation(
304304
id,
305305
alloc.size,
306306
Rc::clone(&memory_extra.stacked_borrows),
307307
kind,
308-
))
308+
);
309+
(Some(stacks), base_tag)
309310
} else {
310-
// No stacks.
311-
None
311+
// No stacks, no tag.
312+
(None, Tag::Untagged)
312313
};
313314
let mut stacked_borrows = memory_extra.stacked_borrows.borrow_mut();
314315
let alloc: Allocation<Tag, Self::AllocExtra> = alloc.with_tags_and_extra(
@@ -325,7 +326,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
325326
stacked_borrows: stacks,
326327
},
327328
);
328-
Cow::Owned(alloc)
329+
(Cow::Owned(alloc), base_tag)
329330
}
330331

331332
#[inline(always)]

src/shims/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
187187

188188
// First arg: Message.
189189
let msg = msg.description();
190-
let msg = this.allocate_str(msg, MiriMemoryKind::Static.into());
190+
let msg = this.allocate_str(msg, MiriMemoryKind::Env.into());
191191

192192
// Second arg: Caller location.
193193
let location = this.alloc_caller_location_for_span(span);

src/stacked_borrows.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl Stacks {
462462
size: Size,
463463
extra: MemoryExtra,
464464
kind: MemoryKind<MiriMemoryKind>,
465-
) -> Self {
465+
) -> (Self, Tag) {
466466
let (tag, perm) = match kind {
467467
MemoryKind::Stack =>
468468
// New unique borrow. This tag is not accessible by the program,
@@ -472,15 +472,17 @@ impl Stacks {
472472
// and in particular, *all* raw pointers.
473473
(Tag::Tagged(extra.borrow_mut().new_ptr()), Permission::Unique),
474474
MemoryKind::Machine(MiriMemoryKind::Static) =>
475-
// Statics are inherently shared, so we do not derive any uniqueness assumptions
476-
// from direct accesses to a static. Thus, the base permission is `SharedReadWrite`.
475+
// Static memory can be referenced by "global" pointers from `tcx`.
476+
// Thus we call `static_base_ptr` such that the global pointers get the same tag
477+
// as what we use here.
478+
// The base pointer is not unique, so the base permission is `SharedReadWrite`.
477479
(extra.borrow_mut().static_base_ptr(id), Permission::SharedReadWrite),
478480
_ =>
479481
// Everything else we handle entirely untagged for now.
480482
// FIXME: experiment with more precise tracking.
481483
(Tag::Untagged, Permission::SharedReadWrite),
482484
};
483-
Stacks::new(size, perm, tag, extra)
485+
(Stacks::new(size, perm, tag, extra), tag)
484486
}
485487

486488
#[inline(always)]

0 commit comments

Comments
 (0)