- MemoryKind::Stack =>
- // New unique borrow. This tag is not accessible by the program,
- // so it will only ever be used when using the local directly (i.e.,
- // not through a pointer). That is, whenever we directly write to a local, this will pop
- // everything else off the stack, invalidating all previous pointers,
- // and in particular, *all* raw pointers.
- (Tag::Tagged(extra.borrow_mut().new_ptr()), Permission::Unique),
- MemoryKind::Machine(MiriMemoryKind::Static) =>
- (extra.borrow_mut().static_base_ptr(id), Permission::SharedReadWrite),
- _ =>
- (Tag::Untagged, Permission::SharedReadWrite),
+ // New unique borrow. This tag is not accessible by the program,
+ // so it will only ever be used when using the local directly (i.e.,
+ // not through a pointer). That is, whenever we directly write to a local, this will pop
+ // 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`.
+ // Thus we call `global_base_ptr` such that the global pointers get the same tag
+ // as what we use here.
+ // `ExternStatic` 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::ExternStatic | MiriMemoryKind::Tls | MiriMemoryKind::Env) =>
+ (extra.borrow_mut().global_base_ptr(id), Permission::SharedReadWrite),
+ // Everything else we handle like raw pointers for now.
+ _ => {
+ let mut extra = extra.borrow_mut();
+ let tag = if extra.track_raw { Tag::Tagged(extra.new_ptr()) } else { Tag::Untagged };
+ (tag, Permission::SharedReadWrite)
+ }