Skip to content

Commit

Permalink
Have Mmap take ownership of File
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftSpider committed Sep 22, 2024
1 parent 2fd0265 commit 2183675
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn mmap(path: &Path) -> Option<Mmap> {
let len = file.metadata().ok()?.len().try_into().ok()?;
// 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.
unsafe { Mmap::map(&file, len, 0) }
unsafe { Mmap::map(file, len, 0) }
}

cfg_if::cfg_if! {
Expand Down
2 changes: 1 addition & 1 deletion src/symbolize/gimli/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Mapping {
// NOTE: we map the remainder of the entire archive instead of just the library so we don't have to determine its length
// SAFETY: See `super::mmap` function
let map = unsafe {
super::mmap::Mmap::map(&file, usize::try_from(len - zip_offset).ok()?, zip_offset)
super::mmap::Mmap::map(file, usize::try_from(len - zip_offset).ok()?, zip_offset)
}?;

Mapping::mk(map, |map, stash| {
Expand Down
2 changes: 1 addition & 1 deletion src/symbolize/gimli/mmap_fake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl Mmap {
///
/// # Safety
/// This function is always safe to call.
pub unsafe fn map(mut file: &File, len: usize, offset: u64) -> Option<Mmap> {
pub unsafe fn map(mut file: File, len: usize, offset: u64) -> Option<Mmap> {
let mut mmap = Mmap {
vec: Vec::with_capacity(len),
};
Expand Down
2 changes: 1 addition & 1 deletion src/symbolize/gimli/mmap_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Mmap {
/// - Mapped files must not be altered for the lifetime of the returned value.
///
/// [^1]: https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/mmap.html
pub unsafe fn map(file: &File, len: usize, offset: u64) -> Option<Mmap> {
pub unsafe fn map(file: File, len: usize, offset: u64) -> Option<Mmap> {
let ptr = mmap64(
ptr::null_mut(),
len,
Expand Down
3 changes: 1 addition & 2 deletions src/symbolize/gimli/mmap_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ impl Mmap {
/// - Mapped files must not be altered for the lifetime of the returned value.'
///
/// [^1]: https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-mapviewoffile
pub unsafe fn map(file: &File, len: usize, offset: u64) -> Option<Mmap> {
let file = file.try_clone().ok()?;
pub unsafe fn map(file: File, len: usize, offset: u64) -> Option<Mmap> {
let mapping = CreateFileMappingA(
file.as_raw_handle(),
ptr::null_mut(),
Expand Down

0 comments on commit 2183675

Please sign in to comment.