diff options
author | Andreas Kling <kling@serenityos.org> | 2020-11-16 09:44:30 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-16 09:44:30 +0100 |
commit | 3c64cec4d70a7e022e8e5c037f2ca90199936fdb (patch) | |
tree | dacdda7214081b905c3c30d1318f131584f9954c /DevTools/UserspaceEmulator | |
parent | f41b9946e299ba7c2c779c25ddb16dea6ffecdc8 (diff) | |
download | serenity-3c64cec4d70a7e022e8e5c037f2ca90199936fdb.zip |
UserspaceEmulator: Devirtualize read/write/execute region permissions
These are getting quite hot (~4% of general emulation profile combined)
so let's just devirtualize them and turn the function calls into simple
boolean checks.
Diffstat (limited to 'DevTools/UserspaceEmulator')
-rw-r--r-- | DevTools/UserspaceEmulator/MmapRegion.cpp | 2 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/MmapRegion.h | 12 | ||||
-rw-r--r-- | DevTools/UserspaceEmulator/SoftMMU.h | 13 |
3 files changed, 17 insertions, 10 deletions
diff --git a/DevTools/UserspaceEmulator/MmapRegion.cpp b/DevTools/UserspaceEmulator/MmapRegion.cpp index f0036f729c..5f5aaf9354 100644 --- a/DevTools/UserspaceEmulator/MmapRegion.cpp +++ b/DevTools/UserspaceEmulator/MmapRegion.cpp @@ -50,8 +50,8 @@ NonnullOwnPtr<MmapRegion> MmapRegion::create_file_backed(u32 base, u32 size, u32 MmapRegion::MmapRegion(u32 base, u32 size, int prot) : Region(base, size) - , m_prot(prot) { + set_prot(prot); m_shadow_data = (u8*)malloc(size); memset(m_shadow_data, 1, size); } diff --git a/DevTools/UserspaceEmulator/MmapRegion.h b/DevTools/UserspaceEmulator/MmapRegion.h index dacc2f7d9f..9240fe3d65 100644 --- a/DevTools/UserspaceEmulator/MmapRegion.h +++ b/DevTools/UserspaceEmulator/MmapRegion.h @@ -53,14 +53,15 @@ public: virtual u8* data() override { return m_data; } virtual u8* shadow_data() override { return m_shadow_data; } - virtual bool is_readable() const override { return m_prot & PROT_READ; } - virtual bool is_writable() const override { return m_prot & PROT_WRITE; } - virtual bool is_executable() const override { return m_prot & PROT_EXEC; } - bool is_malloc_block() const { return m_malloc; } void set_malloc(bool b) { m_malloc = b; } - void set_prot(int prot) { m_prot = prot; } + void set_prot(int prot) + { + set_readable(prot & PROT_READ); + set_writable(prot & PROT_WRITE); + set_executable(prot & PROT_EXEC); + } MallocRegionMetadata* malloc_metadata() { return m_malloc_metadata; } void set_malloc_metadata(Badge<MallocTracer>, NonnullOwnPtr<MallocRegionMetadata> metadata) { m_malloc_metadata = move(metadata); } @@ -71,7 +72,6 @@ private: u8* m_data { nullptr }; u8* m_shadow_data { nullptr }; - int m_prot { 0 }; bool m_file_backed { false }; bool m_malloc { false }; diff --git a/DevTools/UserspaceEmulator/SoftMMU.h b/DevTools/UserspaceEmulator/SoftMMU.h index e40bae9a7c..dda7582f15 100644 --- a/DevTools/UserspaceEmulator/SoftMMU.h +++ b/DevTools/UserspaceEmulator/SoftMMU.h @@ -69,9 +69,13 @@ public: bool is_text() const { return m_text; } void set_text(bool b) { m_text = b; } - virtual bool is_readable() const { return true; } - virtual bool is_writable() const { return true; } - virtual bool is_executable() const { return true; } + bool is_readable() const { return m_readable; } + bool is_writable() const { return m_writable; } + bool is_executable() const { return m_executable; } + + void set_readable(bool b) { m_readable = b; } + void set_writable(bool b) { m_writable = b; } + void set_executable(bool b) { m_executable = b; } virtual u8* data() = 0; virtual u8* shadow_data() = 0; @@ -89,6 +93,9 @@ public: bool m_stack { false }; bool m_text { false }; + bool m_readable { true }; + bool m_writable { true }; + bool m_executable { true }; }; ValueWithShadow<u8> read8(X86::LogicalAddress); |