1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 06:08:12 +00:00

UserspaceEmulator: Mark mmap regions as malloc blocks when mallocing

We don't have to be clever at all to figure out which MmapRegions are
malloc blocks, we can just mark the containing region as such when
the emulated process performs a malloc! :^)
This commit is contained in:
Andreas Kling 2020-08-01 09:13:45 +02:00
parent 5de7bae383
commit 030edbd513
3 changed files with 7 additions and 8 deletions

View file

@ -44,6 +44,10 @@ void MallocTracer::target_did_malloc(Badge<SoftCPU>, FlatPtr address, size_t siz
ASSERT(region);
ASSERT(region->is_mmap());
auto& mmap_region = static_cast<MmapRegion&>(*region);
// Mark the containing mmap region as a malloc block!
mmap_region.set_malloc(true);
auto* shadow_bits = mmap_region.shadow_data() + address - mmap_region.base();
memset(shadow_bits, 0, size);

View file

@ -65,13 +65,6 @@ MmapRegion::~MmapRegion()
free(m_data);
}
bool MmapRegion::is_malloc_block() const
{
// FIXME: This is obviously incomplete!
// We should somehow know which mmap regions are malloc blocks.
return !m_file_backed;
}
ValueWithShadow<u8> MmapRegion::read8(FlatPtr offset)
{
if (!is_readable()) {

View file

@ -52,7 +52,8 @@ public:
bool is_writable() const { return m_prot & PROT_WRITE; }
bool is_executable() const { return m_prot & PROT_EXEC; }
bool is_malloc_block() const;
bool is_malloc_block() const { return m_malloc; }
void set_malloc(bool b) { m_malloc = b; }
private:
MmapRegion(u32 base, u32 size, int prot);
@ -62,6 +63,7 @@ private:
u8* m_shadow_data { nullptr };
int m_prot { 0 };
bool m_file_backed { false };
bool m_malloc { false };
};
}