Kernel: Copy over TLS region size and alignment when forking

Previously we would unintentionally leave them zero-initialized,
resulting in any threads created post fork (but without execve) having
invalid thread local storage pointers stored in their FS register.
This commit is contained in:
Idan Horowitz 2023-12-15 19:15:57 +02:00 committed by Andreas Kling
commit 2a6b492c7f
Notes: sideshowbarker 2024-07-17 06:09:44 +09:00

View file

@ -168,8 +168,11 @@ ErrorOr<FlatPtr> Process::sys$fork(RegisterState& regs)
TRY(child_space->region_tree().place_specifically(*region_clone, region.range())); TRY(child_space->region_tree().place_specifically(*region_clone, region.range()));
auto* child_region = region_clone.leak_ptr(); auto* child_region = region_clone.leak_ptr();
if (&region == m_master_tls_region.unsafe_ptr()) if (&region == m_master_tls_region.unsafe_ptr()) {
child->m_master_tls_region = TRY(child_region->try_make_weak_ptr()); child->m_master_tls_region = TRY(child_region->try_make_weak_ptr());
child->m_master_tls_size = m_master_tls_size;
child->m_master_tls_alignment = m_master_tls_alignment;
}
} }
return {}; return {};
}); });