mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:17:35 +00:00
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! :^)
This commit is contained in:
parent
f2d3cc7325
commit
be5f42adea
14 changed files with 1088 additions and 752 deletions
|
@ -35,20 +35,22 @@ public:
|
|||
SimpleRegion(u32 base, u32 size);
|
||||
virtual ~SimpleRegion() 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; }
|
||||
|
||||
virtual u8* cacheable_ptr(u32 offset) override;
|
||||
|
||||
private:
|
||||
u8* m_data { nullptr };
|
||||
u8* m_shadow_data { nullptr };
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue