feat: TLS runtime - PT_TLS loading and per-thread FS base
MontaukOS binaries could not use thread-local storage: the ELF loader ignored PT_TLS and no FS base was ever programmed, so any %fs access (initial-exec/local-exec TLS, e.g. libbfd's _Thread_local error state) page faulted at address 0. This is the kernel prerequisite for cc1plus/libstdc++ in the GCC port. ELF loader: parse PT_TLS and build the main thread's TLS block above the loaded image (x86-64 variant II ABI: block below the thread pointer, TP = base + align_up(memsz, align), .tdata copied from the template, .tbss zeroed, ABI self-pointer stored at [TP]). The template description is kept on the process for thread spawns. Scheduler: fsBase per thread, loaded into IA32_FS_BASE at every dispatch site through a per-CPU cache - TLS-free processes cost one MSR write per CPU ever, and userspace cannot desync the cache since CR4.FSGSBASE stays off. SYS_THREAD_SPAWN gives each new thread its own TLS block copied from the template (allocated from the process heap; reclaimed at process teardown). Ships tls-test.elf in the SDK (built by the devkit target): checks .tdata values, .tbss zeroing, and the %fs:0 self-pointer, exiting nonzero on failure. Boot-smoke verified; existing TLS-free programs are unaffected. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
@@ -35,6 +35,7 @@ namespace Smp {
|
||||
int cpuIndex; // 0-based CPU index
|
||||
uint32_t lapicId; // local APIC ID
|
||||
uint64_t idleSavedRsp; // RSP saved when switching from idle to process
|
||||
uint64_t currentFsBase = ~0ULL; // last IA32_FS_BASE written on this CPU
|
||||
volatile bool started; // set by AP after init is complete
|
||||
|
||||
Hal::TSS64* tss; // pointer to this CPU's TSS
|
||||
|
||||
Reference in New Issue
Block a user