core: Add wrapper for calling into guest code. (#967)

This commit is contained in:
squidbus 2024-09-23 10:30:16 -07:00 committed by GitHub
parent ad9f1370d5
commit 4ba19a02b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 57 additions and 35 deletions

View file

@ -90,11 +90,8 @@ void Linker::Execute() {
// Init primary thread.
Common::SetCurrentThreadName("GAME_MainThread");
#ifdef ARCH_X86_64
InitializeThreadPatchStack();
#endif
Libraries::Kernel::pthreadInitSelfMainThread();
InitTlsForThread(true);
EnsureThreadInitialized(true);
// Start shared library modules
for (auto& m : m_modules) {
@ -335,6 +332,17 @@ void* Linker::TlsGetAddr(u64 module_index, u64 offset) {
return addr + offset;
}
thread_local std::once_flag init_tls_flag;
void Linker::EnsureThreadInitialized(bool is_primary) {
std::call_once(init_tls_flag, [this, is_primary] {
#ifdef ARCH_X86_64
InitializeThreadPatchStack();
#endif
InitTlsForThread(is_primary);
});
}
void Linker::InitTlsForThread(bool is_primary) {
static constexpr size_t TcbSize = 0x40;
static constexpr size_t TlsAllocAlign = 0x20;