1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

Kernel: Protect processes' master TLS with a fine-grained spinlock

This moves it out of the scope of the big process lock, and allows us
to wean some syscalls off it, starting with sys$allocate_tls.
This commit is contained in:
Idan Horowitz 2023-12-16 12:37:28 +02:00 committed by Andreas Kling
parent cd56ec6e5c
commit 6a4b93b3e0
7 changed files with 91 additions and 86 deletions

View file

@ -431,9 +431,11 @@ Process::load(Memory::AddressSpace& new_space, NonnullRefPtr<OpenFileDescription
if (interpreter_description.is_null()) {
auto load_result = TRY(load_elf_object(new_space, main_program_description, load_offset, ShouldAllocateTls::Yes, ShouldAllowSyscalls::No, minimum_stack_size));
m_master_tls_region = load_result.tls_region;
m_master_tls_size = load_result.tls_size;
m_master_tls_alignment = load_result.tls_alignment;
m_master_tls.with([&load_result](auto& master_tls) {
master_tls.region = load_result.tls_region;
master_tls.size = load_result.tls_size;
master_tls.alignment = load_result.tls_alignment;
});
return load_result;
}
@ -490,25 +492,26 @@ ErrorOr<void> Process::do_exec(NonnullRefPtr<OpenFileDescription> main_program_d
auto allocated_space = TRY(Memory::AddressSpace::try_create(*this, nullptr));
OwnPtr<Memory::AddressSpace> old_space;
auto old_master_tls_region = m_master_tls_region;
auto old_master_tls_size = m_master_tls_size;
auto old_master_tls_alignment = m_master_tls_alignment;
auto old_master_tls = m_master_tls.with([](auto& master_tls) {
auto old = master_tls;
master_tls.region = nullptr;
master_tls.size = 0;
master_tls.alignment = 0;
return old;
});
auto& new_space = m_space.with([&](auto& space) -> Memory::AddressSpace& {
old_space = move(space);
space = move(allocated_space);
return *space;
});
m_master_tls_region = nullptr;
m_master_tls_size = 0;
m_master_tls_alignment = 0;
ArmedScopeGuard space_guard([&]() {
// If we failed at any point from now on we have to revert back to the old address space
m_space.with([&](auto& space) {
space = old_space.release_nonnull();
});
m_master_tls_region = old_master_tls_region;
m_master_tls_size = old_master_tls_size;
m_master_tls_alignment = old_master_tls_alignment;
m_master_tls.with([&](auto& master_tls) {
master_tls = old_master_tls;
});
Memory::MemoryManager::enter_process_address_space(*this);
});