mirror of
https://github.com/PabloMK7/citra.git
synced 2024-11-29 10:50:17 +00:00
Merge pull request #741 from Subv/tls
Give each emulated thread it's own TLS memory
This commit is contained in:
commit
2a19de1d09
4 changed files with 26 additions and 7 deletions
|
@ -61,10 +61,6 @@ int Init() {
|
||||||
g_sys_core = new ARM_DynCom(USER32MODE);
|
g_sys_core = new ARM_DynCom(USER32MODE);
|
||||||
g_app_core = new ARM_DynCom(USER32MODE);
|
g_app_core = new ARM_DynCom(USER32MODE);
|
||||||
|
|
||||||
// TODO: Whenever TLS is implemented, this should contain
|
|
||||||
// the address of the 0x200-byte TLS
|
|
||||||
g_app_core->SetCP15Register(CP15_THREAD_URO, Memory::TLS_AREA_VADDR);
|
|
||||||
|
|
||||||
LOG_DEBUG(Core, "Initialized OK");
|
LOG_DEBUG(Core, "Initialized OK");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "core/hle/kernel/kernel.h"
|
#include "core/hle/kernel/kernel.h"
|
||||||
|
#include "core/hle/kernel/thread.h"
|
||||||
#include "core/mem_map.h"
|
#include "core/mem_map.h"
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
@ -12,12 +13,15 @@ namespace Kernel {
|
||||||
static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header
|
static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the command buffer in kernel memory
|
* Returns a pointer to the command buffer in the current thread's TLS
|
||||||
|
* TODO(Subv): This is not entirely correct, the command buffer should be copied from
|
||||||
|
* the thread's TLS to an intermediate buffer in kernel memory, and then copied again to
|
||||||
|
* the service handler process' memory.
|
||||||
* @param offset Optional offset into command buffer
|
* @param offset Optional offset into command buffer
|
||||||
* @return Pointer to command buffer
|
* @return Pointer to command buffer
|
||||||
*/
|
*/
|
||||||
inline static u32* GetCommandBuffer(const int offset = 0) {
|
inline static u32* GetCommandBuffer(const int offset = 0) {
|
||||||
return (u32*)Memory::GetPointer(Memory::TLS_AREA_VADDR + kCommandHeaderOffset + offset);
|
return (u32*)Memory::GetPointer(GetCurrentThread()->GetTLSAddress() + kCommandHeaderOffset + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -197,6 +197,7 @@ static void SwitchContext(Thread* new_thread) {
|
||||||
new_thread->current_priority = new_thread->nominal_priority;
|
new_thread->current_priority = new_thread->nominal_priority;
|
||||||
|
|
||||||
Core::g_app_core->LoadContext(new_thread->context);
|
Core::g_app_core->LoadContext(new_thread->context);
|
||||||
|
Core::g_app_core->SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress());
|
||||||
} else {
|
} else {
|
||||||
current_thread = nullptr;
|
current_thread = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -402,6 +403,12 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
|
||||||
thread->name = std::move(name);
|
thread->name = std::move(name);
|
||||||
thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
|
thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
// TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
|
// TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
|
||||||
// to initialize the context
|
// to initialize the context
|
||||||
Core::g_app_core->ResetContext(thread->context, stack_top, entry_point, arg);
|
Core::g_app_core->ResetContext(thread->context, stack_top, entry_point, arg);
|
||||||
|
@ -495,6 +502,10 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {
|
||||||
context.cpu_registers[1] = output;
|
context.cpu_registers[1] = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VAddr Thread::GetTLSAddress() const {
|
||||||
|
return tls_address;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void ThreadingInit() {
|
void ThreadingInit() {
|
||||||
|
|
|
@ -135,6 +135,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns the Thread Local Storage address of the current thread
|
||||||
|
* @returns VAddr of the thread's TLS
|
||||||
|
*/
|
||||||
|
VAddr GetTLSAddress() const;
|
||||||
|
|
||||||
Core::ThreadContext context;
|
Core::ThreadContext context;
|
||||||
|
|
||||||
u32 thread_id;
|
u32 thread_id;
|
||||||
|
@ -150,6 +156,8 @@ public:
|
||||||
|
|
||||||
s32 processor_id;
|
s32 processor_id;
|
||||||
|
|
||||||
|
VAddr tls_address; ///< Address of the Thread Local Storage of the thread
|
||||||
|
|
||||||
/// Mutexes currently held by this thread, which will be released when it exits.
|
/// Mutexes currently held by this thread, which will be released when it exits.
|
||||||
boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
|
boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue