1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

UserspaceEmulator: Add basic TLS (thread-local storage) support

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.
This commit is contained in:
Andreas Kling 2020-07-12 00:54:09 +02:00
parent df95e25eaa
commit 734f63d522
4 changed files with 77 additions and 50 deletions

View file

@ -27,7 +27,9 @@
#pragma once
#include <AK/NonnullOwnPtrVector.h>
#include <AK/OwnPtr.h>
#include <AK/Types.h>
#include <LibX86/Instruction.h>
namespace UserspaceEmulator {
@ -63,18 +65,21 @@ public:
u32 m_size { 0 };
};
u8 read8(u32 address);
u16 read16(u32 address);
u32 read32(u32 address);
u8 read8(X86::LogicalAddress);
u16 read16(X86::LogicalAddress);
u32 read32(X86::LogicalAddress);
void write8(u32 address, u8 value);
void write16(u32 address, u16 value);
void write32(u32 address, u32 value);
void write8(X86::LogicalAddress, u8);
void write16(X86::LogicalAddress, u16);
void write32(X86::LogicalAddress, u32);
Region* find_region(X86::LogicalAddress);
Region* find_region(u32 address);
void add_region(NonnullOwnPtr<Region>);
void set_tls_region(NonnullOwnPtr<Region>);
private:
OwnPtr<Region> m_tls_region;
NonnullOwnPtrVector<Region> m_regions;
};