summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/thread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/thread.cpp')
-rw-r--r--src/core/hle/kernel/thread.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index ab69a4262..34dc257aa 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -107,6 +107,8 @@ void Thread::Stop() {
107 for (auto& wait_object : wait_objects) { 107 for (auto& wait_object : wait_objects) {
108 wait_object->RemoveWaitingThread(this); 108 wait_object->RemoveWaitingThread(this);
109 } 109 }
110
111 Kernel::g_current_process->used_tls_slots[tls_index] = false;
110} 112}
111 113
112Thread* ArbitrateHighestPriorityThread(u32 address) { 114Thread* ArbitrateHighestPriorityThread(u32 address) {
@@ -404,12 +406,19 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
404 thread->name = std::move(name); 406 thread->name = std::move(name);
405 thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom(); 407 thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
406 thread->owner_process = g_current_process; 408 thread->owner_process = g_current_process;
409 thread->tls_index = -1;
410
411 // Find the next available TLS index, and mark it as used
412 auto& used_tls_slots = Kernel::g_current_process->used_tls_slots;
413 for (unsigned int i = 0; i < used_tls_slots.size(); ++i) {
414 if (used_tls_slots[i] == false) {
415 thread->tls_index = i;
416 used_tls_slots[i] = true;
417 break;
418 }
419 }
407 420
408 VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200; 421 ASSERT_MSG(thread->tls_index != -1, "Out of TLS space");
409
410 ASSERT_MSG(tls_address < Memory::TLS_AREA_VADDR_END, "Too many threads");
411
412 thread->tls_address = tls_address;
413 422
414 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used 423 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
415 // to initialize the context 424 // to initialize the context
@@ -505,7 +514,7 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {
505} 514}
506 515
507VAddr Thread::GetTLSAddress() const { 516VAddr Thread::GetTLSAddress() const {
508 return tls_address; 517 return Memory::TLS_AREA_VADDR + tls_index * 0x200;
509} 518}
510 519
511//////////////////////////////////////////////////////////////////////////////////////////////////// 520////////////////////////////////////////////////////////////////////////////////////////////////////