diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-01 19:37:36 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-01 19:37:36 +0100 |
commit | febc8a5ac70b9d5638a9e5a3940d1b055230e5d4 (patch) | |
tree | cc0658db048819fdce07a9dd8a4cc7b969ae0786 /DevTools/UserspaceEmulator | |
parent | db790dda6252630c68a82c827de51a8438b97cb6 (diff) | |
download | serenity-febc8a5ac70b9d5638a9e5a3940d1b055230e5d4.zip |
UserspaceEmulator: Remove hand-rolled is_foo() helpers in favor of RTTI
Diffstat (limited to 'DevTools/UserspaceEmulator')
-rw-r--r-- | DevTools/UserspaceEmulator/Emulator.cpp | 6 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MallocTracer.cpp | 8 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MallocTracer.h | 2 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MmapRegion.h | 1 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/Region.h | 3 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SharedBufferRegion.h | 2 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SoftMMU.cpp | 8 |
7 files changed, 13 insertions, 17 deletions
diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp index 0f7b9948cb..5a6c091f37 100644 --- a/DevTools/UserspaceEmulator/Emulator.cpp +++ b/DevTools/UserspaceEmulator/Emulator.cpp @@ -280,7 +280,7 @@ const MmapRegion* Emulator::find_text_region(FlatPtr address) { const MmapRegion* matching_region = nullptr; mmu().for_each_region([&](auto& region) { - if (!region.is_mmap()) + if (!is<MmapRegion>(region)) return IterationDecision::Continue; const auto& mmap_region = static_cast<const MmapRegion&>(region); if (!(mmap_region.is_executable() && address >= mmap_region.base() && address < mmap_region.base() + mmap_region.size())) @@ -1045,7 +1045,7 @@ FlatPtr Emulator::virt$mremap(FlatPtr params_addr) mmu().copy_from_vm(¶ms, params_addr, sizeof(params)); if (auto* region = mmu().find_region({ m_cpu.ds(), params.old_address })) { - if (!region->is_mmap()) + if (!is<MmapRegion>(*region)) return -EINVAL; ASSERT(region->size() == params.old_size); auto& mmap_region = *(MmapRegion*)region; @@ -1094,7 +1094,7 @@ u32 Emulator::virt$unveil(u32) u32 Emulator::virt$mprotect(FlatPtr base, size_t size, int prot) { if (auto* region = mmu().find_region({ m_cpu.ds(), base })) { - if (!region->is_mmap()) + if (!is<MmapRegion>(*region)) return -EINVAL; ASSERT(region->size() == size); auto& mmap_region = *(MmapRegion*)region; diff --git a/DevTools/UserspaceEmulator/MallocTracer.cpp b/DevTools/UserspaceEmulator/MallocTracer.cpp index 9661e615a5..c2ead0409d 100644 --- a/DevTools/UserspaceEmulator/MallocTracer.cpp +++ b/DevTools/UserspaceEmulator/MallocTracer.cpp @@ -45,7 +45,7 @@ template<typename Callback> inline void MallocTracer::for_each_mallocation(Callback callback) const { m_emulator.mmu().for_each_region([&](auto& region) { - if (region.is_mmap() && static_cast<const MmapRegion&>(region).is_malloc_block()) { + if (is<MmapRegion>(region) && static_cast<const MmapRegion&>(region).is_malloc_block()) { auto* malloc_data = static_cast<MmapRegion&>(region).malloc_metadata(); for (auto& mallocation : malloc_data->mallocations) { if (mallocation.used && callback(mallocation) == IterationDecision::Break) @@ -62,7 +62,7 @@ void MallocTracer::target_did_malloc(Badge<SoftCPU>, FlatPtr address, size_t siz return; auto* region = m_emulator.mmu().find_region({ 0x23, address }); ASSERT(region); - ASSERT(region->is_mmap()); + ASSERT(is<MmapRegion>(*region)); auto& mmap_region = static_cast<MmapRegion&>(*region); // Mark the containing mmap region as a malloc block! @@ -145,7 +145,7 @@ void MallocTracer::target_did_realloc(Badge<SoftCPU>, FlatPtr address, size_t si return; auto* region = m_emulator.mmu().find_region({ 0x23, address }); ASSERT(region); - ASSERT(region->is_mmap()); + ASSERT(is<MmapRegion>(*region)); auto& mmap_region = static_cast<MmapRegion&>(*region); ASSERT(mmap_region.is_malloc_block()); @@ -334,7 +334,7 @@ bool MallocTracer::is_reachable(const Mallocation& mallocation) const if (!region.is_readable()) return IterationDecision::Continue; // Skip malloc blocks - if (region.is_mmap() && static_cast<const MmapRegion&>(region).is_malloc_block()) + if (is<MmapRegion>(region) && static_cast<const MmapRegion&>(region).is_malloc_block()) return IterationDecision::Continue; size_t pointers_in_region = region.size() / sizeof(u32); diff --git a/DevTools/UserspaceEmulator/MallocTracer.h b/DevTools/UserspaceEmulator/MallocTracer.h index 9741542f76..53da97acf1 100644 --- a/DevTools/UserspaceEmulator/MallocTracer.h +++ b/DevTools/UserspaceEmulator/MallocTracer.h @@ -95,7 +95,7 @@ private: ALWAYS_INLINE Mallocation* MallocTracer::find_mallocation(const Region& region, FlatPtr address) { - if (!region.is_mmap()) + if (!is<MmapRegion>(region)) return nullptr; if (!static_cast<const MmapRegion&>(region).is_malloc_block()) return nullptr; diff --git a/DevTools/UserspaceEmulator/MmapRegion.h b/DevTools/UserspaceEmulator/MmapRegion.h index 51c2a8e370..75a42340ab 100644 --- a/DevTools/UserspaceEmulator/MmapRegion.h +++ b/DevTools/UserspaceEmulator/MmapRegion.h @@ -65,7 +65,6 @@ public: private: MmapRegion(u32 base, u32 size, int prot); - virtual bool is_mmap() const override { return true; } u8* m_data { nullptr }; u8* m_shadow_data { nullptr }; diff --git a/DevTools/UserspaceEmulator/Region.h b/DevTools/UserspaceEmulator/Region.h index b75f37f517..ffb15cf941 100644 --- a/DevTools/UserspaceEmulator/Region.h +++ b/DevTools/UserspaceEmulator/Region.h @@ -27,6 +27,7 @@ #pragma once #include "ValueWithShadow.h" +#include <AK/TypeCasts.h> #include <AK/Types.h> namespace UserspaceEmulator { @@ -54,8 +55,6 @@ public: virtual ValueWithShadow<u64> read64(u32 offset) = 0; virtual u8* cacheable_ptr([[maybe_unused]] u32 offset) { return nullptr; } - virtual bool is_shared_buffer() const { return false; } - virtual bool is_mmap() const { return false; } bool is_stack() const { return m_stack; } void set_stack(bool b) { m_stack = b; } diff --git a/DevTools/UserspaceEmulator/SharedBufferRegion.h b/DevTools/UserspaceEmulator/SharedBufferRegion.h index 1d56b81ca2..b3c7d68d5c 100644 --- a/DevTools/UserspaceEmulator/SharedBufferRegion.h +++ b/DevTools/UserspaceEmulator/SharedBufferRegion.h @@ -49,8 +49,6 @@ public: virtual u8* data() override { return m_data; } virtual u8* shadow_data() override { return m_shadow_data; } - bool is_shared_buffer() const override { return true; } - int shbuf_id() const { return m_shbuf_id; } int allow_all(); diff --git a/DevTools/UserspaceEmulator/SoftMMU.cpp b/DevTools/UserspaceEmulator/SoftMMU.cpp index 04e2242136..50da131f1c 100644 --- a/DevTools/UserspaceEmulator/SoftMMU.cpp +++ b/DevTools/UserspaceEmulator/SoftMMU.cpp @@ -44,7 +44,7 @@ void SoftMMU::add_region(NonnullOwnPtr<Region> region) ASSERT(!find_region({ 0x23, region->base() })); // FIXME: More sanity checks pls - if (region->is_shared_buffer()) + if (is<SharedBufferRegion>(*region)) m_shbuf_regions.set(static_cast<SharedBufferRegion*>(region.ptr())->shbuf_id(), region.ptr()); size_t first_page_in_region = region->base() / PAGE_SIZE; @@ -63,7 +63,7 @@ void SoftMMU::remove_region(Region& region) m_page_to_region_map[first_page_in_region + i] = nullptr; } - if (region.is_shared_buffer()) + if (is<SharedBufferRegion>(region)) m_shbuf_regions.remove(static_cast<SharedBufferRegion&>(region).shbuf_id()); m_regions.remove_first_matching([&](auto& entry) { return entry.ptr() == ®ion; }); } @@ -253,7 +253,7 @@ bool SoftMMU::fast_fill_memory8(X86::LogicalAddress address, size_t size, ValueW if (!region->contains(address.offset() + size - 1)) return false; - if (region->is_mmap() && static_cast<const MmapRegion&>(*region).is_malloc_block()) { + if (is<MmapRegion>(*region) && static_cast<const MmapRegion&>(*region).is_malloc_block()) { if (auto* tracer = m_emulator.malloc_tracer()) { // FIXME: Add a way to audit an entire range of memory instead of looping here! for (size_t i = 0; i < size; ++i) { @@ -278,7 +278,7 @@ bool SoftMMU::fast_fill_memory32(X86::LogicalAddress address, size_t count, Valu if (!region->contains(address.offset() + (count * sizeof(u32)) - 1)) return false; - if (region->is_mmap() && static_cast<const MmapRegion&>(*region).is_malloc_block()) { + if (is<MmapRegion>(*region) && static_cast<const MmapRegion&>(*region).is_malloc_block()) { if (auto* tracer = m_emulator.malloc_tracer()) { // FIXME: Add a way to audit an entire range of memory instead of looping here! for (size_t i = 0; i < count; ++i) { |