diff options
author | Andreas Kling <kling@serenityos.org> | 2020-11-14 18:36:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-14 22:52:04 +0100 |
commit | d88b36448b46f97646438e5a54e6ce07e35b5f38 (patch) | |
tree | a93742d168b4de5b32343c258106d4e5b2084716 /DevTools/UserspaceEmulator | |
parent | 2fceffff6fd243fee4ee53defb752c10baf197dc (diff) | |
download | serenity-d88b36448b46f97646438e5a54e6ce07e35b5f38.zip |
UserspaceEmulator: Add some helpers to tidy up TrackedChunkedBlock
Diffstat (limited to 'DevTools/UserspaceEmulator')
-rw-r--r-- | DevTools/UserspaceEmulator/MallocTracer.cpp | 24 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MallocTracer.h | 3 |
2 files changed, 18 insertions, 9 deletions
diff --git a/DevTools/UserspaceEmulator/MallocTracer.cpp b/DevTools/UserspaceEmulator/MallocTracer.cpp index 440d85b7b6..d3c8517977 100644 --- a/DevTools/UserspaceEmulator/MallocTracer.cpp +++ b/DevTools/UserspaceEmulator/MallocTracer.cpp @@ -72,20 +72,28 @@ void MallocTracer::target_did_malloc(Badge<SoftCPU>, FlatPtr address, size_t siz auto& block = const_cast<TrackedChunkedBlock&>(*tracked_chunked_block.value()); block.address = chunked_block_address; block.chunk_size = mmap_region.read32(offsetof(CommonHeader, m_size)).value(); - auto chunk_count = (ChunkedBlock::block_size - sizeof(ChunkedBlock)) / block.chunk_size; - block.mallocations.resize(chunk_count); - dbgln("Tracking ChunkedBlock @ {:p} with chunk_size={}, chunk_count={}", block.address, block.chunk_size, chunk_count); + block.mallocations.resize((ChunkedBlock::block_size - sizeof(ChunkedBlock)) / block.chunk_size); + dbgln("Tracking ChunkedBlock @ {:p} with chunk_size={}, chunk_count={}", block.address, block.chunk_size, block.mallocations.size()); } ASSERT(tracked_chunked_block.has_value()); auto& block = const_cast<TrackedChunkedBlock&>(*tracked_chunked_block.value()); - auto chunk_offset = address - (block.address + sizeof(ChunkedBlock)); - auto chunk_index = chunk_offset / block.chunk_size; - block.mallocations[chunk_index] = { address, size, true, false, Emulator::the().raw_backtrace(), Vector<FlatPtr>() }; + block.mallocation_for_address(address) = { address, size, true, false, Emulator::the().raw_backtrace(), Vector<FlatPtr>() }; } else { m_big_mallocations.append({ address, size, true, false, Emulator::the().raw_backtrace(), Vector<FlatPtr>() }); } } +ALWAYS_INLINE MallocTracer::Mallocation& MallocTracer::TrackedChunkedBlock::mallocation_for_address(FlatPtr address) const +{ + return const_cast<Mallocation&>(this->mallocations[chunk_index_for_address(address)]); +} + +ALWAYS_INLINE size_t MallocTracer::TrackedChunkedBlock::chunk_index_for_address(FlatPtr address) const +{ + auto chunk_offset = address - (this->address + sizeof(ChunkedBlock)); + return chunk_offset / this->chunk_size; +} + void MallocTracer::target_did_free(Badge<SoftCPU>, FlatPtr address) { if (!address) @@ -143,9 +151,7 @@ MallocTracer::Mallocation* MallocTracer::find_mallocation(FlatPtr address) auto chunked_block = m_chunked_blocks.get(possible_chunked_block); if (chunked_block.has_value()) { auto& block = *chunked_block.value(); - auto chunk_offset = address - (block.address + sizeof(ChunkedBlock)); - auto chunk_index = chunk_offset / block.chunk_size; - auto& mallocation = block.mallocations[chunk_index]; + auto& mallocation = block.mallocation_for_address(address); if (mallocation.used) { ASSERT(mallocation.contains(address)); return const_cast<Mallocation*>(&mallocation); diff --git a/DevTools/UserspaceEmulator/MallocTracer.h b/DevTools/UserspaceEmulator/MallocTracer.h index 4a90405fe6..aad1d66adb 100644 --- a/DevTools/UserspaceEmulator/MallocTracer.h +++ b/DevTools/UserspaceEmulator/MallocTracer.h @@ -69,6 +69,9 @@ private: FlatPtr address { 0 }; size_t chunk_size { 0 }; + size_t chunk_index_for_address(FlatPtr) const; + Mallocation& mallocation_for_address(FlatPtr) const; + Vector<Mallocation> mallocations; }; |