Skip to content

interpret/allocation: get_range on ProvenanceMap #145540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
}
}

/// Gets the provenances of all bytes (including from pointers) in a range.
pub fn get_range(
&self,
cx: &impl HasDataLayout,
range: AllocRange,
) -> impl Iterator<Item = Prov> {
let ptr_provs = self.range_ptrs_get(range, cx).iter().map(|(_, p)| *p);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the wrong range. You have to use adjusted_range_ptrs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't adjusted_range_ptrs only give us the offsets and not provenances? range_ptrs_get uses that internally anyways

Copy link
Member

@RalfJung RalfJung Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, d'oh, right...

I shouldn't review when I am too tired.^^

let byte_provs = self.range_bytes_get(range).iter().map(|(_, (p, _))| *p);
ptr_provs.chain(byte_provs)
}

/// Attempt to merge per-byte provenance back into ptr chunks, if the right fragments
/// sit next to each other. Return `false` is that is not possible due to partial pointers.
pub fn merge_bytes(&mut self, cx: &impl HasDataLayout) -> bool {
Expand Down
11 changes: 3 additions & 8 deletions src/tools/miri/src/shims/native_lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {

match evt {
AccessEvent::Read(_) => {
// FIXME: ProvenanceMap should have something like get_range().
let p_map = alloc.provenance();
for idx in overlap {
// If a provenance was read by the foreign code, expose it.
if let Some((prov, _idx)) = p_map.get_byte(Size::from_bytes(idx), this)
{
this.expose_provenance(prov)?;
}
// If a provenance was read by the foreign code, expose it.
for prov in alloc.provenance().get_range(this, overlap.into()) {
this.expose_provenance(prov)?;
}
}
AccessEvent::Write(_, certain) => {
Expand Down
Loading