summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2015-05-11 06:19:54 +0200
committerSubv <subv2112@gmail.com>2015-05-12 03:09:23 +0200
commitdda94e56dde35f5df969b71b2be9195b7d8cdc05 (patch)
treebbded5ba6fc9d9a52268614f87c8ac11ed5789f6 /src/core/hle/kernel
parentMerge pull request #750 from Subv/process_svc (diff)
downloadyuzu-dda94e56dde35f5df969b71b2be9195b7d8cdc05.tar
yuzu-dda94e56dde35f5df969b71b2be9195b7d8cdc05.tar.gz
yuzu-dda94e56dde35f5df969b71b2be9195b7d8cdc05.tar.bz2
yuzu-dda94e56dde35f5df969b71b2be9195b7d8cdc05.tar.lz
yuzu-dda94e56dde35f5df969b71b2be9195b7d8cdc05.tar.xz
yuzu-dda94e56dde35f5df969b71b2be9195b7d8cdc05.tar.zst
yuzu-dda94e56dde35f5df969b71b2be9195b7d8cdc05.zip
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/process.h3
-rw-r--r--src/core/hle/kernel/thread.cpp21
-rw-r--r--src/core/hle/kernel/thread.h2
3 files changed, 19 insertions, 7 deletions
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 22cd1049b..90881054c 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -74,6 +74,9 @@ public:
/// The id of this process
u32 process_id = next_process_id++;
+ /// Bitmask of the used TLS slots
+ std::bitset<300> used_tls_slots;
+
/**
* Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them
* to this process.
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() {
for (auto& wait_object : wait_objects) {
wait_object->RemoveWaitingThread(this);
}
+
+ Kernel::g_current_process->used_tls_slots[tls_index] = false;
}
Thread* ArbitrateHighestPriorityThread(u32 address) {
@@ -404,12 +406,19 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
thread->name = std::move(name);
thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
thread->owner_process = g_current_process;
+ thread->tls_index = -1;
+
+ // Find the next available TLS index, and mark it as used
+ auto& used_tls_slots = Kernel::g_current_process->used_tls_slots;
+ for (unsigned int i = 0; i < used_tls_slots.size(); ++i) {
+ if (used_tls_slots[i] == false) {
+ thread->tls_index = i;
+ used_tls_slots[i] = true;
+ break;
+ }
+ }
- VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200;
-
- ASSERT_MSG(tls_address < Memory::TLS_AREA_VADDR_END, "Too many threads");
-
- thread->tls_address = tls_address;
+ ASSERT_MSG(thread->tls_index != -1, "Out of TLS space");
// TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
// to initialize the context
@@ -505,7 +514,7 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {
}
VAddr Thread::GetTLSAddress() const {
- return tls_address;
+ return Memory::TLS_AREA_VADDR + tls_index * 0x200;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 1d4d010fe..cfbebab08 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -157,7 +157,7 @@ public:
s32 processor_id;
- VAddr tls_address; ///< Address of the Thread Local Storage of the thread
+ s32 tls_index; ///< Index of the Thread Local Storage of the thread
/// Mutexes currently held by this thread, which will be released when it exits.
boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;