1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:07:44 +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:
Andreas Kling 2019-09-07 15:50:44 +02:00
parent bcfdf9ffa7
commit ec6bceaa08
7 changed files with 92 additions and 5 deletions

View file

@ -35,6 +35,11 @@ bool ELFLoader::layout()
{
bool failed = false;
m_image.for_each_program_header([&](const ELFImage::ProgramHeader& program_header) {
if (program_header.type() == PT_TLS) {
auto* tls_image = tls_section_hook(program_header.size_in_memory(), program_header.alignment());
memcpy(tls_image, program_header.raw_data(), program_header.size_in_image());
return;
}
if (program_header.type() != PT_LOAD)
return;
#ifdef ELFLOADER_DEBUG