mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:28:13 +00:00
Kernel: Support thread-local storage
This patch adds support for TLS according to the x86 System V ABI. Each thread gets a thread-specific memory region, and the GS segment register always points _to a pointer_ to the thread-specific memory. In other words, to access thread-local variables, userspace programs start by dereferencing the pointer at [gs:0]. The Process keeps a master copy of the TLS segment that new threads should use, and when a new thread is created, they get a copy of it. It's basically whatever the PT_TLS program header in the ELF says.
This commit is contained in:
parent
bcfdf9ffa7
commit
ec6bceaa08
7 changed files with 92 additions and 5 deletions
|
@ -460,6 +460,12 @@ bool Scheduler::context_switch(Thread& thread)
|
|||
descriptor.descriptor_type = 0;
|
||||
}
|
||||
|
||||
if (!thread.thread_specific_data().is_null()) {
|
||||
auto& descriptor = thread_specific_descriptor();
|
||||
descriptor.set_base(thread.thread_specific_data().as_ptr());
|
||||
descriptor.set_limit(sizeof(ThreadSpecificData*));
|
||||
}
|
||||
|
||||
auto& descriptor = get_gdt_entry(thread.selector());
|
||||
descriptor.type = 11; // Busy TSS
|
||||
flush_gdt();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue