Skip to content

Commit cce62d4

Browse files
committed
Document why we need an unsafe call to register a file for memory-mapped access; there is no other way
1 parent cfba7f9 commit cce62d4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

common/src/resolver.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ pub struct Registry {
8383
impl Registry {
8484
/// Register a file for memory-mapped access in the registry.
8585
pub fn register_file(&self, store: StoreId, object: ObjectId, file: &File) -> Result<()> {
86+
// SAFETY: This is safe because:
87+
// 1. We assume the file is stable (not truncated/modified during use)
88+
// 2. The mmap is wrapped in Arc for safe sharing across threads
89+
// 3. All access is bounds-checked in the resolve() method
90+
// 4. The file reference ensures the file descriptor stays valid
8691
let mmap = unsafe { Mmap::map(file) }.context("mmap failed")?;
8792
self.map.insert((store, object), Backing::Mmap(Arc::new(mmap)));
8893
Ok(())

0 commit comments

Comments
 (0)