From 4e87d1f9d1ae875d98af62fabdacb75e696e0ba0 Mon Sep 17 00:00:00 2001 From: Gliniak Date: Sat, 28 Jan 2023 21:24:32 +0100 Subject: [PATCH] [Kernel/Thread] Set TLS slot to 0 while freeing --- src/xenia/kernel/kernel_state.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index 95144ee09..c6f1853a3 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -138,7 +138,17 @@ void KernelState::set_process_type(uint32_t value) { uint32_t KernelState::AllocateTLS() { return uint32_t(tls_bitmap_.Acquire()); } -void KernelState::FreeTLS(uint32_t slot) { tls_bitmap_.Release(slot); } +void KernelState::FreeTLS(uint32_t slot) { + const std::vector> threads = + object_table()->GetObjectsByType(); + + for (const object_ref& thread : threads) { + if (thread->is_guest_thread()) { + thread->SetTLSValue(slot, 0); + } + } + tls_bitmap_.Release(slot); +} void KernelState::RegisterTitleTerminateNotification(uint32_t routine, uint32_t priority) {