Open
Conversation
philipc
reviewed
Sep 22, 2024
| let len = file.metadata().ok()?.len().try_into().ok()?; | ||
| unsafe { Mmap::map(&file, len, 0) } | ||
| // SAFETY: All files we mmap are mmaped by the dynamic linker or the kernel already for the | ||
| // executable code of the process. Modifying them would cause crashes or UB anyways. |
Contributor
There was a problem hiding this comment.
This is true for some but not all uses of mmap in this crate. DWARF can be in a separate file that is not loaded by the dynamic linker or kernel (.dSYM on macOS, .debug/.dwz/.dwp on linux, or unpacked object files on both).
That doesn't mean we should use fs::read for those though. We don't need to read all of the DWARF, and doing so would affect performance and memory usage.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supercedes #667
Document safety preconditions and reasoning for why they're followed. I'd like to push the unsafety down another level, or just remove the
mmapfunction (makeMmapa common type with sys impls for the platform-specific bits), but those both are a lot more work.