mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
UserspaceEmulator: Forget ChunkedBlocks after they are munmap()'ed
This is not ideal since we lose free() backtraces, but it will require some thinking to get this right.
This commit is contained in:
parent
2066f48b87
commit
8fd97bee7f
3 changed files with 16 additions and 0 deletions
|
@ -40,6 +40,14 @@ MallocTracer::MallocTracer()
|
|||
{
|
||||
}
|
||||
|
||||
void MallocTracer::notify_malloc_block_was_released(Badge<MmapRegion>, MmapRegion& region)
|
||||
{
|
||||
// FIXME: It's sad that we may lose a bunch of free() backtraces here,
|
||||
// but if the address is reused for a new ChunkedBlock, things will
|
||||
// get extremely confused.
|
||||
m_chunked_blocks.remove(region.base());
|
||||
}
|
||||
|
||||
void MallocTracer::target_did_malloc(Badge<SoftCPU>, FlatPtr address, size_t size)
|
||||
{
|
||||
auto* region = Emulator::the().mmu().find_region({ 0x20, address });
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
namespace UserspaceEmulator {
|
||||
|
||||
class MmapRegion;
|
||||
class SoftCPU;
|
||||
|
||||
class MallocTracer {
|
||||
|
@ -44,6 +45,8 @@ public:
|
|||
void target_did_free(Badge<SoftCPU>, FlatPtr address);
|
||||
void target_did_realloc(Badge<SoftCPU>, FlatPtr address, size_t);
|
||||
|
||||
void notify_malloc_block_was_released(Badge<MmapRegion>, MmapRegion&);
|
||||
|
||||
void audit_read(FlatPtr address, size_t);
|
||||
void audit_write(FlatPtr address, size_t);
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ MmapRegion::MmapRegion(u32 base, u32 size, int prot)
|
|||
|
||||
MmapRegion::~MmapRegion()
|
||||
{
|
||||
if (is_malloc_block()) {
|
||||
if (auto* tracer = Emulator::the().malloc_tracer())
|
||||
tracer->notify_malloc_block_was_released({}, *this);
|
||||
}
|
||||
|
||||
free(m_shadow_data);
|
||||
if (m_file_backed)
|
||||
munmap(m_data, size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue