Skip to content

Commit

Permalink
ElfParser<B>
Browse files Browse the repository at this point in the history
  • Loading branch information
d-e-s-o committed Nov 1, 2024
1 parent 1e73b73 commit 4a27c63
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/elf/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl<'r> Backend<'r> for File {

/// A parser for ELF64 files.
#[derive(Debug)]
pub(crate) struct ElfParser {
pub(crate) struct ElfParser<B = Mmap> {
/// A cache for relevant parts of the ELF file.
// SAFETY: We must not hand out references with a 'static lifetime to
// this member. Rather, they should never outlive `self`.
Expand All @@ -660,13 +660,13 @@ pub(crate) struct ElfParser {
// in there. Given that it is an implementation detail, we can live
// with this slightly counter-intuitive split.
decompressed: InsertMap<usize, Vec<u8>>,
/// The memory mapped file.
_mmap: Mmap,
/// The path to the ELF file being worked on, if available.
path: Option<PathBuf>,
/// The backend used.
_backend: B,
}

impl ElfParser {
impl ElfParser<Mmap> {
/// Create an `ElfParser` from an open file.
pub(crate) fn open_file<P>(file: &File, path: P) -> Result<Self>
where
Expand All @@ -685,7 +685,7 @@ impl ElfParser {
let elf_data = unsafe { mem::transmute::<&[u8], &'static [u8]>(mmap.deref()) };

let parser = ElfParser {
_mmap: mmap,
_backend: mmap,
decompressed: InsertMap::new(),
cache: Cache::new(elf_data),
path,
Expand All @@ -699,7 +699,9 @@ impl ElfParser {
File::open(path).with_context(|| format!("failed to open {}", path.display()))?;
Self::open_file(&file, path)
}
}

impl<B> ElfParser<B> {
/// Retrieve the data corresponding to the ELF section at index
/// `idx`, optionally decompressing it if it is compressed.
///
Expand Down

0 comments on commit 4a27c63

Please sign in to comment.