mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:17:35 +00:00
ELFLoader: Add program header support.
We don't do anything useful with the data yet, but I'm gonna rewrite the layout code to run off of the program header table instead. This will allow us to map .text and .rodata sections in read-only memory.
This commit is contained in:
parent
20fb1fc377
commit
8f51f0e6b2
3 changed files with 63 additions and 0 deletions
|
@ -91,6 +91,11 @@ unsigned ELFImage::sectionCount() const
|
|||
return header().e_shnum;
|
||||
}
|
||||
|
||||
unsigned ELFImage::program_header_count() const
|
||||
{
|
||||
return header().e_phnum;
|
||||
}
|
||||
|
||||
bool ELFImage::parse()
|
||||
{
|
||||
// We only support i386.
|
||||
|
@ -148,6 +153,12 @@ const Elf32_Ehdr& ELFImage::header() const
|
|||
return *reinterpret_cast<const Elf32_Ehdr*>(rawData(0));
|
||||
}
|
||||
|
||||
const Elf32_Phdr& ELFImage::program_header_internal(unsigned index) const
|
||||
{
|
||||
ASSERT(index < header().e_phnum);
|
||||
return *reinterpret_cast<const Elf32_Phdr*>(rawData(header().e_phoff + (index * sizeof(Elf32_Phdr))));
|
||||
}
|
||||
|
||||
const Elf32_Shdr& ELFImage::sectionHeader(unsigned index) const
|
||||
{
|
||||
ASSERT(index < header().e_shnum);
|
||||
|
@ -167,6 +178,12 @@ const ELFImage::Section ELFImage::section(unsigned index) const
|
|||
return Section(*this, index);
|
||||
}
|
||||
|
||||
const ELFImage::ProgramHeader ELFImage::program_header(unsigned index) const
|
||||
{
|
||||
ASSERT(index < program_header_count());
|
||||
return ProgramHeader(*this, index);
|
||||
}
|
||||
|
||||
const ELFImage::Relocation ELFImage::RelocationSection::relocation(unsigned index) const
|
||||
{
|
||||
ASSERT(index < relocationCount());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue