diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-16 19:27:03 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-16 19:27:03 +0200 |
commit | e50874621a86893eb5b267cca89203e9052093cd (patch) | |
tree | 29ea60ceb2be8020fa2b98cdc80110d835134654 /DevTools/UserspaceEmulator | |
parent | 3dc1c809581cba246fe29afda5e2739e2c887b17 (diff) | |
download | serenity-e50874621a86893eb5b267cca89203e9052093cd.zip |
UserspaceEmulator: Don't scan text segment for malloc leaks
There will be no (true positive) malloc addresses in the text segment.
Diffstat (limited to 'DevTools/UserspaceEmulator')
-rw-r--r-- | DevTools/UserspaceEmulator/Emulator.cpp | 2 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MallocTracer.cpp | 2 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SoftMMU.h | 4 |
3 files changed, 8 insertions, 0 deletions
diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp index 875b78340b..23e2855515 100644 --- a/DevTools/UserspaceEmulator/Emulator.cpp +++ b/DevTools/UserspaceEmulator/Emulator.cpp @@ -108,6 +108,8 @@ bool Emulator::load_elf() m_elf->image().for_each_program_header([&](const ELF::Image::ProgramHeader& program_header) { if (program_header.type() == PT_LOAD) { auto region = make<SimpleRegion>(program_header.vaddr().get(), program_header.size_in_memory()); + if (program_header.is_executable() && !program_header.is_writable()) + region->set_text(true); memcpy(region->data(), program_header.raw_data(), program_header.size_in_image()); mmu().add_region(move(region)); return; diff --git a/DevTools/UserspaceEmulator/MallocTracer.cpp b/DevTools/UserspaceEmulator/MallocTracer.cpp index 36bad55a19..72c183d99a 100644 --- a/DevTools/UserspaceEmulator/MallocTracer.cpp +++ b/DevTools/UserspaceEmulator/MallocTracer.cpp @@ -163,6 +163,8 @@ bool MallocTracer::is_reachable(const Mallocation& mallocation) const // Skip the stack if (region.is_stack()) return IterationDecision::Continue; + if (region.is_text()) + return IterationDecision::Continue; // Skip malloc blocks if (region.is_mmap() && static_cast<const MmapRegion&>(region).is_malloc_block()) return IterationDecision::Continue; diff --git a/DevTools/UserspaceEmulator/SoftMMU.h b/DevTools/UserspaceEmulator/SoftMMU.h index d73eff7165..7202b73ab1 100644 --- a/DevTools/UserspaceEmulator/SoftMMU.h +++ b/DevTools/UserspaceEmulator/SoftMMU.h @@ -63,6 +63,9 @@ public: bool is_stack() const { return m_stack; } void set_stack(bool b) { m_stack = b; } + bool is_text() const { return m_text; } + void set_text(bool b) { m_text = b; } + protected: Region(u32 base, u32 size) : m_base(base) @@ -75,6 +78,7 @@ public: u32 m_size { 0 }; bool m_stack { false }; + bool m_text { false }; }; u8 read8(X86::LogicalAddress); |