Does `dealloc` care about provenance?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
https://doc.rust-lang.org/alloc/alloc/fn.dealloc.html points to https://doc.rust-lang.org/alloc/alloc/trait.GlobalAlloc.html#tymethod.dealloc, which says nothing about provenance, just
ptris a block of memory currently allocated via this allocator and,layoutis the same layout that was used to allocate that block of memory.
(https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html#tymethod.deallocate also doesn't mention provenance, nor does https://doc.rust-lang.org/alloc/alloc/trait.Allocator.html#currently-allocated-memory.)
Does the ptr need to have any particular provenance? Does an allocator need to launder the provenance back to a known-valid one in order to read/write through the pointer it got in dealloc?
Whatever the answer, it would be good to say either way in docs.
FWIW, MIRI rejects this today ("pointer not dereferenceable"):
let layout = Layout::new::<i32>();
let p: *mut u8 = alloc(layout);
let other: *mut u8 = without_provenance_mut(p.addr());
dealloc(other, layout);
And also rejects this (with an odd "does not point to the beginning of an object" error that's arguably not true):
let layout = Layout::new::<i32>();
let p: *mut u8 = alloc(layout);
let mut mylocal = 10_u8;
let other = (&raw mut mylocal).with_addr(p.addr());
dealloc(other, layout);
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the linked alloc::dealloc, GlobalAlloc::dealloc, Allocator::deallocate, and currently-allocated-memory documentation, then reproduce the two Miri examples. Research and document whether the pointer passed to dealloc requires particular provenance, including any implications for allocator reads or writes. Done means the relevant docs state the provenance requirement unambiguously.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100