summaryrefslogtreecommitdiff
path: root/DevTools/UserspaceEmulator/MmapRegion.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-07-21 02:29:59 +0200
committerAndreas Kling <kling@serenityos.org>2020-07-21 02:37:29 +0200
commitbe5f42adea1a75db6e6fdf49e9e4c6c9992d7c6d (patch)
treeb32e2828df3366be2a6923fcafc39cdc21b1e9c6 /DevTools/UserspaceEmulator/MmapRegion.h
parentf2d3cc7325c6c75b7ceff55c030c22ac89e3ce4d (diff)
downloadserenity-be5f42adea1a75db6e6fdf49e9e4c6c9992d7c6d.zip
UserspaceEmulator+LibX86: Start tracking uninitialized memory :^)
This patch introduces the concept of shadow bits. For every byte of memory there is a corresponding shadow byte that contains metadata about that memory. Initially, the only metadata is whether the byte has been initialized or not. That's represented by the least significant shadow bit. Shadow bits travel together with regular values throughout the entire CPU and MMU emulation. There are two main helper classes to facilitate this: ValueWithShadow and ValueAndShadowReference. ValueWithShadow<T> is basically a struct { T value; T shadow; } whereas ValueAndShadowReference<T> is struct { T& value; T& shadow; }. The latter is used as a wrapper around general-purpose registers, since they can't use the plain ValueWithShadow memory as we need to be able to address individual 8-bit and 16-bit subregisters (EAX, AX, AL, AH.) Whenever a computation is made using uninitialized inputs, the result is tainted and becomes uninitialized as well. This allows us to track this state as it propagates throughout memory and registers. This patch doesn't yet keep track of tainted flags, that will be an important upcoming improvement to this. I'm sure I've messed up some things here and there, but it seems to basically work, so we have a place to start! :^)
Diffstat (limited to 'DevTools/UserspaceEmulator/MmapRegion.h')
-rw-r--r--DevTools/UserspaceEmulator/MmapRegion.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/DevTools/UserspaceEmulator/MmapRegion.h b/DevTools/UserspaceEmulator/MmapRegion.h
index 57c02ed73d..a32c5271d9 100644
--- a/DevTools/UserspaceEmulator/MmapRegion.h
+++ b/DevTools/UserspaceEmulator/MmapRegion.h
@@ -37,15 +37,16 @@ public:
static NonnullOwnPtr<MmapRegion> create_file_backed(u32 base, u32 size, u32 prot, int flags, int fd, off_t offset);
virtual ~MmapRegion() override;
- virtual u8 read8(u32 offset) override;
- virtual u16 read16(u32 offset) override;
- virtual u32 read32(u32 offset) override;
+ virtual ValueWithShadow<u8> read8(u32 offset) override;
+ virtual ValueWithShadow<u16> read16(u32 offset) override;
+ virtual ValueWithShadow<u32> read32(u32 offset) override;
- virtual void write8(u32 offset, u8 value) override;
- virtual void write16(u32 offset, u16 value) override;
- virtual void write32(u32 offset, u32 value) override;
+ virtual void write8(u32 offset, ValueWithShadow<u8>) override;
+ virtual void write16(u32 offset, ValueWithShadow<u16>) override;
+ virtual void write32(u32 offset, ValueWithShadow<u32>) override;
u8* data() { return m_data; }
+ u8* shadow_data() { return m_shadow_data; }
bool is_readable() const { return m_prot & PROT_READ; }
bool is_writable() const { return m_prot & PROT_WRITE; }
@@ -58,6 +59,7 @@ private:
virtual bool is_mmap() const override { return true; }
u8* m_data { nullptr };
+ u8* m_shadow_data { nullptr };
int m_prot { 0 };
bool m_file_backed { false };
};