mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
UserspaceEmulator: Add TLS regions to reachability checking
This commit is contained in:
parent
1dcc21d32e
commit
c13da77e85
2 changed files with 22 additions and 8 deletions
|
@ -156,14 +156,16 @@ bool MallocTracer::is_reachable(const Mallocation& mallocation) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool reachable = false;
|
||||||
|
|
||||||
// 2. Search in other memory regions for pointers to this mallocation
|
// 2. Search in other memory regions for pointers to this mallocation
|
||||||
for (auto& region : Emulator::the().mmu().regions()) {
|
Emulator::the().mmu().for_each_region([&](auto& region) {
|
||||||
// Skip the stack
|
// Skip the stack
|
||||||
if (region.is_stack())
|
if (region.is_stack())
|
||||||
continue;
|
return IterationDecision::Continue;
|
||||||
// Skip malloc blocks
|
// Skip malloc blocks
|
||||||
if (region.is_mmap() && static_cast<const MmapRegion&>(region).is_malloc_block())
|
if (region.is_mmap() && static_cast<const MmapRegion&>(region).is_malloc_block())
|
||||||
continue;
|
return IterationDecision::Continue;
|
||||||
|
|
||||||
size_t pointers_in_region = region.size() / sizeof(u32);
|
size_t pointers_in_region = region.size() / sizeof(u32);
|
||||||
for (size_t i = 0; i < pointers_in_region; ++i) {
|
for (size_t i = 0; i < pointers_in_region; ++i) {
|
||||||
|
@ -172,12 +174,13 @@ bool MallocTracer::is_reachable(const Mallocation& mallocation) const
|
||||||
#ifdef REACHABLE_DEBUG
|
#ifdef REACHABLE_DEBUG
|
||||||
dbgprintf("mallocation %p is reachable from region %p-%p\n", mallocation.address, region.base(), region.end() - 1);
|
dbgprintf("mallocation %p is reachable from region %p-%p\n", mallocation.address, region.base(), region.end() - 1);
|
||||||
#endif
|
#endif
|
||||||
return true;
|
reachable = true;
|
||||||
|
return IterationDecision::Break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return IterationDecision::Continue;
|
||||||
|
});
|
||||||
return false;
|
return reachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MallocTracer::dump_leak_report()
|
void MallocTracer::dump_leak_report()
|
||||||
|
|
|
@ -98,7 +98,18 @@ public:
|
||||||
|
|
||||||
SharedBufferRegion* shbuf_region(int shbuf_id);
|
SharedBufferRegion* shbuf_region(int shbuf_id);
|
||||||
|
|
||||||
NonnullOwnPtrVector<Region>& regions() { return m_regions; }
|
template<typename Callback>
|
||||||
|
void for_each_region(Callback callback)
|
||||||
|
{
|
||||||
|
if (m_tls_region) {
|
||||||
|
if (callback(*m_tls_region) == IterationDecision::Break)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (auto& region : m_regions) {
|
||||||
|
if (callback(region) == IterationDecision::Break)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OwnPtr<Region> m_tls_region;
|
OwnPtr<Region> m_tls_region;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue