1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +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

@ -6,7 +6,7 @@
class ELFDynamicObject {
public:
explicit ELFDynamicObject(VirtualAddress base_address, u32 dynamic_offset);
explicit ELFDynamicObject(VirtualAddress base_address, VirtualAddress dynamic_section_address);
~ELFDynamicObject();
void dump() const;
@ -196,7 +196,7 @@ private:
void for_each_dynamic_entry(F) const;
VirtualAddress m_base_address;
u32 m_dynamic_offset;
VirtualAddress m_dynamic_address;
Symbol m_the_undefined_symbol { *this, 0, {} };
unsigned m_symbol_count { 0 };
@ -255,7 +255,7 @@ inline void ELFDynamicObject::for_each_symbol(F func) const
template<typename F>
inline void ELFDynamicObject::for_each_dynamic_entry(F func) const
{
auto* dyns = reinterpret_cast<const Elf32_Dyn*>(m_base_address.offset(m_dynamic_offset).as_ptr());
auto* dyns = reinterpret_cast<const Elf32_Dyn*>(m_dynamic_address.as_ptr());
for (unsigned i = 0;; ++i) {
auto&& dyn = DynamicEntry(dyns[i]);
if (dyn.tag() == DT_NULL)