summaryrefslogtreecommitdiff
path: root/DevTools/UserspaceEmulator/SoftMMU.h
AgeCommit message (Collapse)Author
2020-07-21UserspaceEmulator+LibX86: Start tracking uninitialized memory :^)Andreas Kling
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! :^)
2020-07-16UserspaceEmulator: Don't scan text segment for malloc leaksAndreas Kling
There will be no (true positive) malloc addresses in the text segment.
2020-07-16UserspaceEmulator: Add TLS regions to reachability checkingAndreas Kling
2020-07-16UserspaceEmulator: Implement very basic leak checking :^)Andreas Kling
Upon exit, the emulator will now print a leak report of any malloc allocations that are still live and don't have pointers to their base address anywhere in either another live mallocation, or in one of the non-malloc-block memory regions. Note that the malloc-block memory region check is not fully functional and this will work even better once we get that fixed. This is pretty cool. :^)
2020-07-16UserspaceEmulator: Add ways to check if a Region is stack/mmapAndreas Kling
2020-07-15UserspaceEmulator: Add support for shared buffers (shbuf)Andreas Kling
We track these separately from regular mmap() regions, as they have slightly different behaviors.
2020-07-13UserspaceEmulator: Add a very simple instruction fetch cacheAndreas Kling
To avoid MMU region lookup on every single instruction fetch, we now cache a raw pointer to the current instruction. This gets automatically invalidated when we jump somewhere, but as long as we're executing sequentially, instruction fetches will hit the cache and bypass all the region lookup stuff. This is about a ~2x speedup. :^)
2020-07-13UserspaceEmulator: Add some more syscallsAndreas Kling
We can now unmap mapped memory, among other things. This is all very ad-hoc as I'm trying to run UserspaceEmulator inside itself. :^)
2020-07-12UserspaceEmulator: Add some convenient SoftMMU APIs for copying dataAndreas Kling
We'll soon want to copy data in and out of the SoftMMU memory space.
2020-07-12UserspaceEmulator: Add basic TLS (thread-local storage) supportAndreas Kling
The SoftMMU now receives full X86::LogicalAddress values from SoftCPU. This allows the MMU to reroute TLS accesses to a special memory region. The ELF executable's PT_TLS header tells us how to allocate the TLS. Basically, the GS register points to a magical 4-byte area which has a pointer to the TCB (thread control block). The TCB lives in normal flat memory space and is accessed through the DS register.
2020-07-10UserspaceEmulator: Add 8/16 bit memory read/write operationsAndreas Kling
2020-07-09UserspaceEmulator: Start sketching out a SoftMMU class :^)Andreas Kling
This Emulator sub-object will keep track of all active memory regions and handle memory read/write operations from the CPU. A memory region is currently represented by a virtual Region object that can implement arbitrary behavior by overriding read/write ops.