From da7b4df1c36f7f975e282dfd131371029f190ed4 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Tue, 26 Mar 2024 18:48:26 +0200 Subject: [PATCH] implemented sceKernelGetProcParam --- src/core/hle/kernel/memory_management.cpp | 3 +++ src/core/hle/libraries/libkernel/libkernel.cpp | 10 ++++++++++ src/core/linker.cpp | 15 ++++++++++++++- src/core/linker.h | 2 ++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/core/hle/kernel/memory_management.cpp b/src/core/hle/kernel/memory_management.cpp index 9491b4a3..d6aa8cdb 100644 --- a/src/core/hle/kernel/memory_management.cpp +++ b/src/core/hle/kernel/memory_management.cpp @@ -85,6 +85,9 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess; switch (prot) { + case 0x03: + cpu_mode = VirtualMemory::MemoryMode::ReadWrite; + break; case 0x32: case 0x33: // SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL cpu_mode = VirtualMemory::MemoryMode::ReadWrite; diff --git a/src/core/hle/libraries/libkernel/libkernel.cpp b/src/core/hle/libraries/libkernel/libkernel.cpp index 8fbeb2d0..13d5b04b 100644 --- a/src/core/hle/libraries/libkernel/libkernel.cpp +++ b/src/core/hle/libraries/libkernel/libkernel.cpp @@ -19,11 +19,20 @@ #else #include #endif +#include +#include namespace Core::Libraries::LibKernel { static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return +static void* PS4_SYSV_ABI sceKernelGetProcParam() { + + auto* linker = Common::Singleton::Instance(); + + return reinterpret_cast(linker->GetProcParam()); +} + int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) { UNREACHABLE(); return 0; @@ -139,6 +148,7 @@ void LibKernel_Register(Loader::SymbolsResolver* sym) { LIB_FUNCTION("BPE9s9vQQXo", "libkernel", 1, "libkernel", 1, 1, posix_mmap); LIB_FUNCTION("1jfXLRVzisc", "libkernel", 1, "libkernel", 1, 1, sceKernelUsleep); LIB_FUNCTION("YSHRBRLn2pI", "libkernel", 1, "libkernel", 1, 1, _writev); + LIB_FUNCTION("959qrazPIrg", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcParam); Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym); Core::Libraries::LibKernel::timeSymbolsRegister(sym); diff --git a/src/core/linker.cpp b/src/core/linker.cpp index 712b4fb1..153abed1 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -164,6 +164,9 @@ void Linker::LoadModuleToMemory(Module* m) { LOG_INFO(Core_Linker, "tls virtual address ={:#x}", m->tls.image_virtual_addr); LOG_INFO(Core_Linker, "tls image size ={}", m->tls.image_size); break; + case PT_SCE_PROCPARAM: + m->proc_param_virtual_addr = elf_pheader[i].p_vaddr + m->base_virtual_addr; + break; default: LOG_ERROR(Core_Linker, "Unimplemented type {}", m->elf.ElfPheaderTypeStr(elf_pheader[i].p_type)); @@ -605,6 +608,16 @@ void Linker::Resolve(const std::string& name, Loader::SymbolType sym_type, Modul } } +u64 Linker::GetProcParam() { + // std::scoped_lock lock{m_mutex}; + + for (auto& m : m_modules) { + if (!m->elf.IsSharedLib()) { + return m->proc_param_virtual_addr; + } + } + return 0; +} using exit_func_t = PS4_SYSV_ABI void (*)(); using entry_func_t = PS4_SYSV_ABI void (*)(EntryParams* params, exit_func_t atexit_func); using module_ini_func_t = PS4_SYSV_ABI int (*)(size_t args, const void* argp, module_func_t func); @@ -662,7 +675,7 @@ void Linker::Execute() { } Core::Libraries::LibKernel::pthreadInitSelfMainThread(); - //relocate all modules + // relocate all modules for (const auto& m : m_modules) { Relocate(m.get()); } diff --git a/src/core/linker.h b/src/core/linker.h index de4048aa..62630395 100644 --- a/src/core/linker.h +++ b/src/core/linker.h @@ -106,6 +106,7 @@ struct Module { Loader::Elf elf; u64 aligned_base_size = 0; u64 base_virtual_addr = 0; + u64 proc_param_virtual_addr = 0; std::string file_name; @@ -137,6 +138,7 @@ public: Loader::SymbolRecord* return_info); void Execute(); void DebugDump(); + u64 GetProcParam(); private: const ModuleInfo* FindModule(const Module& m, const std::string& id);