mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-06 23:11:25 +12:00
Make TLS great again
And clean System.h a bit
This commit is contained in:
parent
6296453ef3
commit
fc9fdca3f6
10 changed files with 141 additions and 163 deletions
|
@ -10,67 +10,6 @@ namespace vm { using namespace psv; }
|
|||
|
||||
const arm_decoder<arm_interpreter> s_arm_interpreter;
|
||||
|
||||
#define TLS_MAX 128
|
||||
|
||||
u32 g_armv7_tls_start;
|
||||
|
||||
std::array<atomic_t<u32>, TLS_MAX> g_armv7_tls_owners;
|
||||
|
||||
void armv7_init_tls()
|
||||
{
|
||||
g_armv7_tls_start = Emu.GetTLSMemsz() ? vm::alloc(Emu.GetTLSMemsz() * TLS_MAX, vm::main) : 0;
|
||||
|
||||
for (auto& v : g_armv7_tls_owners)
|
||||
{
|
||||
v = 0;
|
||||
}
|
||||
}
|
||||
|
||||
u32 armv7_get_tls(u32 thread)
|
||||
{
|
||||
if (!Emu.GetTLSMemsz() || !thread)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < TLS_MAX; i++)
|
||||
{
|
||||
if (g_armv7_tls_owners[i] == thread)
|
||||
{
|
||||
return g_armv7_tls_start + i * Emu.GetTLSMemsz(); // if already initialized, return TLS address
|
||||
}
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < TLS_MAX; i++)
|
||||
{
|
||||
if (g_armv7_tls_owners[i].compare_and_swap_test(0, thread))
|
||||
{
|
||||
const u32 addr = g_armv7_tls_start + i * Emu.GetTLSMemsz(); // get TLS address
|
||||
std::memcpy(vm::base(addr), vm::base(Emu.GetTLSAddr()), Emu.GetTLSFilesz()); // initialize from TLS image
|
||||
std::memset(vm::base(addr + Emu.GetTLSFilesz()), 0, Emu.GetTLSMemsz() - Emu.GetTLSFilesz()); // fill the rest with zeros
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
throw EXCEPTION("Out of TLS memory");
|
||||
}
|
||||
|
||||
void armv7_free_tls(u32 thread)
|
||||
{
|
||||
if (!Emu.GetTLSMemsz())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& v : g_armv7_tls_owners)
|
||||
{
|
||||
if (v.compare_and_swap_test(thread, 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ARMv7Thread::get_name() const
|
||||
{
|
||||
return fmt::format("ARMv7[0x%x] Thread (%s)", id, m_name);
|
||||
|
@ -119,7 +58,7 @@ void ARMv7Thread::cpu_init()
|
|||
PC = PC & ~1; // and fix PC
|
||||
ITSTATE.IT = 0;
|
||||
SP = stack_addr + stack_size;
|
||||
TLS = armv7_get_tls(id);
|
||||
TLS = 0;
|
||||
}
|
||||
|
||||
extern thread_local std::string(*g_tls_log_prefix)();
|
||||
|
@ -174,8 +113,6 @@ void ARMv7Thread::cpu_task_main()
|
|||
|
||||
ARMv7Thread::~ARMv7Thread()
|
||||
{
|
||||
armv7_free_tls(id);
|
||||
|
||||
if (stack_addr)
|
||||
{
|
||||
vm::dealloc_verbose_nothrow(stack_addr, vm::main);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue