pub type MappedGsym = Gsym<MappedBytes>;Available on crate feature
mmap only.Expand description
GSYM reader backed directly by a read-only memory map.
This is the same reader as Gsym with opaque mapped-byte storage, so it
has the same query API. Mapping suits a large file with sparse lookups, where
reading the whole file into memory would cost more than the lookups do.
Both constructors are unsafe because a memory map is not a snapshot. If
any process truncates or rewrites the file while it is mapped, results
borrowed from it can observe changed bytes or become invalid.
Gsym::open reads an owned snapshot instead and carries no such
requirement.
use gsym::MappedGsym;
// SAFETY: this process controls the file and keeps it immutable while mapped.
let gsym = unsafe { MappedGsym::map("app.gsym")? };
if let Some(symbol) = gsym.lookup(0x401000)? {
println!("{}", String::from_utf8_lossy(symbol.frames()[0].name));
}A mapped reader and an owned one parse the same file identically:
use gsym::{Gsym, MappedGsym};
let snapshot = Gsym::open("app.gsym")?;
// SAFETY: this application owns the file and keeps it immutable while mapped.
let mapped = unsafe { MappedGsym::map("app.gsym")? };
let file = std::fs::File::open("app.gsym")?;
// SAFETY: the same file-stability guarantee applies to this mapping.
let mapped_file = unsafe { MappedGsym::map_file(&file)? };
assert_eq!(snapshot.header(), mapped.header());
assert_eq!(mapped.header(), mapped_file.header());Aliased Typeยง
pub struct MappedGsym { /* private fields */ }