diff --git a/src/core/libraries/kernel/libkernel.cpp b/src/core/libraries/kernel/libkernel.cpp index bc2717ae..ff9e290a 100644 --- a/src/core/libraries/kernel/libkernel.cpp +++ b/src/core/libraries/kernel/libkernel.cpp @@ -177,7 +177,7 @@ s32 PS4_SYSV_ABI sceKernelLoadStartModule(const char* moduleFileName, size_t arg // Load PRX module and relocate any modules that import it. auto* linker = Common::Singleton::Instance(); - u32 handle = linker->LoadModule(path); + u32 handle = linker->LoadModule(path, true); if (handle == -1) { return ORBIS_KERNEL_ERROR_EINVAL; } diff --git a/src/core/linker.cpp b/src/core/linker.cpp index 15dccb04..b5613970 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -96,7 +96,7 @@ void Linker::Execute() { } } -s32 Linker::LoadModule(const std::filesystem::path& elf_name) { +s32 Linker::LoadModule(const std::filesystem::path& elf_name, bool is_dynamic) { std::scoped_lock lk{mutex}; if (!std::filesystem::exists(elf_name)) { @@ -110,6 +110,7 @@ s32 Linker::LoadModule(const std::filesystem::path& elf_name) { return -1; } + num_static_modules += !is_dynamic; m_modules.emplace_back(std::move(module)); return m_modules.size() - 1; } @@ -349,7 +350,8 @@ void Linker::InitTlsForThread(bool is_primary) { dtv_table[1].counter = num_dtvs; // Copy init images to TLS thread blocks and map them to DTV slots. - for (const auto& module : m_modules) { + for (u32 i = 0; i < num_static_modules; i++) { + auto* module = m_modules[i].get(); if (module->tls.image_size == 0) { continue; } diff --git a/src/core/linker.h b/src/core/linker.h index 05484924..aee8c8fd 100644 --- a/src/core/linker.h +++ b/src/core/linker.h @@ -86,7 +86,7 @@ public: void* TlsGetAddr(u64 module_index, u64 offset); void InitTlsForThread(bool is_primary = false); - s32 LoadModule(const std::filesystem::path& elf_name); + s32 LoadModule(const std::filesystem::path& elf_name, bool is_dynamic = false); Module* FindByAddress(VAddr address); void Relocate(Module* module); @@ -103,6 +103,7 @@ private: u32 dtv_generation_counter{1}; size_t static_tls_size{}; u32 max_tls_index{}; + u32 num_static_modules{}; HeapApiFunc heap_api_func{}; std::vector> m_modules; Loader::SymbolsResolver m_hle_symbols{};