Menu

- Learn
- Documentation
  - Language Reference
  - Library Reference
  - Command-line Reference
  - Feature Overview
  - Articles
- Downloads
- Packages
- Community
  - Blog
  - Orgs using D
  - Twitter
  - Calendar
  - Forums
  - IRC
  - Community Discord
  - Wiki
  - GitHub
  - Issues
  - Get involved
  - Contributors
  - Foundation
  - Security Team
  - Donate
  - Sponsors
- Resources
  - Tour
  - Books
  - Tutorials
  - Tools
  - Editors
  - IDEs
  - run.dlang.io
  - Visual D
  - Acknowledgments
  - D Style
  - Glossary
  - Sitemap

Search
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

# core.internal.elf.io

Provides (read-only) memory-mapped I/O for ELF files.

Reference http://www.dwarfstd.org/

License:
Boost License 1.0.
Authors:
Yazan Dabain, Martin Kinkelin

Source core/elf/io.d

template `ElfIO`(Elf_Ehdr, Elf_Shdr, ubyte ELFCLASS)
  File-based memory-mapped I/O (read-only). Only supports ELF files with a byte-order matching the target platform's.
  Parameters:

  Elf_Ehdr | Expected type of the ELF header (Elf{32,64}Ehdr)
  Elf_Shdr | Expected type of the ELF section header (Elf{32,64}Shdr)
  ELFCLASS | Expected ELF class (ELFCLASS{32,64})

  struct `ElfFile`;
    ELF file (with memory-mapped ELF header).
    static bool `open`(const(char)* `path`, out ElfFile `file`);
      Tries to open the specified file as ELF file matching the ElfIO template parameters.
      Returns:
      True on success.
    this(int `fd`);
      Constructs an instance based on the specified file descriptor. Doesn't validate the file header. The file is closed when destructing the instance.
    TypedMMapRegion!Elf_Ehdr `ehdr`;
      Memory-mapped ELF header.
    const bool `isValid`();
      Returns true if the ELF file header matches the ElfIO template parameters.
    const NamedSections `namedSections`();
      Returns a struct to iterate over the named sections.
      Examples:

          foreach (index, name, sectionHeader; elfFile.namedSections) ...

    const bool `findSectionHeaderByName`(const(char)[] `sectionName`, out ElfSectionHeader `header`);
      Tries to find the header of the section with the specified name.
      Returns:
      True on success.
  struct `NamedSections`;
    Enables iterating over an ELF file's (named) sections.
    alias `Callback` = int delegate(size_t index, const(char)[] name, ElfSectionHeader sectionHeader);
      name: null-terminated
    int `opApply`(scope Callback `dg`);
  struct `ElfSectionHeader`;
    Memory-mapped ELF section header.
    this(const ref ElfFile `file`, size_t `index`);
      Constructs a new instance based on the specified file and section index.
    TypedMMapRegion!Elf_Shdr `shdr`;
      Memory-mapped section header.
  struct `ElfSection`;
    Memory-mapped ELF section data.
    this(const ref ElfFile `file`, const ref ElfSectionHeader `shdr`);
      Constructs a new instance based on the specified file and section header.
    const const(void)[] `data`();
      Returns the memory-mapped section data. The data is accessible as long as this ElfSection is alive.
enum int `ELFCLASS32`;
  ELF class for 32-bit ELF files.
enum int `ELFCLASS64`;
  ELF class for 64-bit ELF files.
alias `Elf_Ehdr` = core.sys.elf.Elf64_Ehdr;
  Native ELF header type.
alias `Elf_Shdr` = core.sys.elf.Elf64_Shdr;
  Native ELF section header type.
alias `ELFCLASS` = ELFCLASS64;
  Native ELF class.
alias `NativeElfIO` = ElfIO!(Elf64_Ehdr, Elf64_Shdr, cast(ubyte)2u);
alias `ElfFile` = ElfIO!(Elf64_Ehdr, Elf64_Shdr, cast(ubyte)2u).`ElfFile`;
  Native ELF file.
alias `ElfSectionHeader` = ElfIO!(Elf64_Ehdr, Elf64_Shdr, cast(ubyte)2u).`ElfSectionHeader`;
  Native ELF section header.
alias `ElfSection` = ElfIO!(Elf64_Ehdr, Elf64_Shdr, cast(ubyte)2u).`ElfSection`;
  Native ELF section.
nothrow @nogc char* `thisExePath`();
  Returns the path to the process' executable as newly allocated C string (free() when done), or null on error.

Copyright © 1999-2022 by the D Language Foundation | Page generated by Ddoc on Mon Nov 14 18:06:33 2022