aboutsummaryrefslogtreecommitdiff
path: root/vendor/backtrace/src/symbolize/gimli/mmap_windows.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/backtrace/src/symbolize/gimli/mmap_windows.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/backtrace/src/symbolize/gimli/mmap_windows.rs')
-rw-r--r--vendor/backtrace/src/symbolize/gimli/mmap_windows.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/vendor/backtrace/src/symbolize/gimli/mmap_windows.rs b/vendor/backtrace/src/symbolize/gimli/mmap_windows.rs
new file mode 100644
index 0000000..b39509d
--- /dev/null
+++ b/vendor/backtrace/src/symbolize/gimli/mmap_windows.rs
@@ -0,0 +1,57 @@
+use super::super::super::windows::*;
+use super::mystd::fs::File;
+use super::mystd::os::windows::prelude::*;
+use core::ops::Deref;
+use core::ptr;
+use core::slice;
+
+pub struct Mmap {
+ // keep the file alive to prevent it from being deleted which would cause
+ // us to read bad data.
+ _file: File,
+ ptr: *mut c_void,
+ len: usize,
+}
+
+impl Mmap {
+ pub unsafe fn map(file: &File, len: usize) -> Option<Mmap> {
+ let file = file.try_clone().ok()?;
+ let mapping = CreateFileMappingA(
+ file.as_raw_handle() as *mut _,
+ ptr::null_mut(),
+ PAGE_READONLY,
+ 0,
+ 0,
+ ptr::null(),
+ );
+ if mapping.is_null() {
+ return None;
+ }
+ let ptr = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, len);
+ CloseHandle(mapping);
+ if ptr.is_null() {
+ return None;
+ }
+ Some(Mmap {
+ _file: file,
+ ptr,
+ len,
+ })
+ }
+}
+impl Deref for Mmap {
+ type Target = [u8];
+
+ fn deref(&self) -> &[u8] {
+ unsafe { slice::from_raw_parts(self.ptr as *const u8, self.len) }
+ }
+}
+
+impl Drop for Mmap {
+ fn drop(&mut self) {
+ unsafe {
+ let r = UnmapViewOfFile(self.ptr);
+ debug_assert!(r != 0);
+ }
+ }
+}