sunshowers edited PR #9681.
sunshowers edited PR #9681:
This is part of the work to centralize memory management into the
mmap
module. This commit introduces a few structures which aid in that process, and
starts converting one of the functions (MemoryImageSource::map_at) into this
module.The structures introduced are:
MemoryBase:RuntimeLinearMemory::base_ptris now
RuntimeLinearMemory::base, which returns aMemoryBase. This is either a
raw pointer or an mmap + an offset into it.
MmapOffset: A combination of a reference to an mmap and an offset into it.
Logically represents a pointer into a mapped section of memory.
MmapOffsetRaw: Some components likeMemoryImageSlotlogically work on
borrowed memory, but adding lifetime parameters to them would introduce
self-reference issues. Instead, store a raw form of theMmapOffsetsuch
that it can be reconstructed at runtime. This should work for most future
work here, but not all of it -- I've written out some comments along with
ideas.On Zulip there was a suggestion to use
Arc<Mmap>rather than a lifetime
parameter. To be honest it's quite appealing! One of the challenges though
is thatMmaphas several&mutmethods. The methods fall into two categories:
- Methods like
make_accessible, which can be changed to be&selfsince the OS performs synchronization of mapped memory.- Methods like
slice_mut, which are quite difficult to turn into&selfmethods. It would be too easy to callself.slice_mut(0..host_page_size()); self.slice_mut(0..host_page_size());and cause an insta-UB. I spent some time looking at how to do this but found it too difficult :(
sunshowers commented on PR #9681:
Methods like slice_mut, which are quite difficult to turn into &self methods. It would be too easy to call self.slice_mut(0..host_page_size()); self.slice_mut(0..host_page_size()); and cause an insta-UB. I spent some time looking at how to do this but found it too difficult :(
Ah interesting, it looks like the only seriously affected use is in some tests.
sunshowers edited a comment on PR #9681:
Methods like slice_mut, which are quite difficult to turn into &self methods. It would be too easy to call self.slice_mut(0..host_page_size()); self.slice_mut(0..host_page_size()); and cause an insta-UB. I spent some time looking at how to do this but found it too difficult :(
Ah interesting, it looks like the only seriously affected use is in some tests. Maybe this is more feasible than I think.
sunshowers commented on PR #9681:
Moving to draft for now -- I think
Arcis possible to make work.
sunshowers closed without merge PR #9681.
sunshowers commented on PR #9681:
Yeah
Arcis definitely possible -- going to re-do this after moving over toArc.
Last updated: Dec 13 2025 at 19:03 UTC