1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:37:43 +00:00

LibELF: Map .text segment with MAP_ANONYMOUS for shared objects

We need to workaround the fact that MAP_PRIVATE when passed a file
descriptor doesn't work the way we expect. We can't change the
permissions on our mmap to PROT_WRITE if the original executable doesn't
have PROT_WRITE.

Because of this, we need to construct our ELFDynamicObject using the
actual virtual address of the .dynamic section, instead of using the
offset into the ELFImage that was actually getting modified by accident
...somehow. Not clear what was going on.
This commit is contained in:
Andrew Kaster 2020-01-08 21:38:05 -07:00 committed by Andreas Kling
parent e594724b01
commit 2e349337d3
4 changed files with 26 additions and 18 deletions

View file

@ -8,9 +8,9 @@
static const char* name_for_dtag(Elf32_Sword d_tag);
ELFDynamicObject::ELFDynamicObject(VirtualAddress base_address, u32 dynamic_offset)
ELFDynamicObject::ELFDynamicObject(VirtualAddress base_address, VirtualAddress dynamic_section_addresss)
: m_base_address(base_address)
, m_dynamic_offset(dynamic_offset)
, m_dynamic_address(dynamic_section_addresss)
{
parse();
}
@ -32,7 +32,7 @@ void ELFDynamicObject::dump() const
return IterationDecision::Continue;
});
dbgprintf("Dynamic section at offset 0x%x contains %zu entries:\n", m_dynamic_offset, num_dynamic_sections);
dbgprintf("Dynamic section at address 0x%x contains %zu entries:\n", m_dynamic_address.as_ptr(), num_dynamic_sections);
dbgprintf(builder.to_string().characters());
}