implemented sceKernelGetProcParam for module loading

This commit is contained in:
georgemoralis 2024-01-05 17:57:12 +02:00
parent 1e0bbb06b3
commit b660a84a78
3 changed files with 27 additions and 0 deletions

View File

@ -11,6 +11,7 @@
#include "core/hle/libraries/libkernel/time_management.h" #include "core/hle/libraries/libkernel/time_management.h"
#include "core/hle/libraries/libs.h" #include "core/hle/libraries/libs.h"
#include "core/loader/elf.h" #include "core/loader/elf.h"
#include "core/linker.h"
#ifdef _WIN64 #ifdef _WIN64
#include <windows.h> #include <windows.h>
@ -33,6 +34,14 @@ int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) { BREAKPOINT(); }
static thread_local int libc_error; static thread_local int libc_error;
int* PS4_SYSV_ABI __Error() { return &libc_error; } int* PS4_SYSV_ABI __Error() { return &libc_error; }
static void* PS4_SYSV_ABI sceKernelGetProcParam() {
PRINT_FUNCTION_NAME();
auto* linker = Common::Singleton<Core::Linker>::Instance();
return reinterpret_cast<void*>(linker->GetProcParam());
}
void LibKernel_Register(Loader::SymbolsResolver* sym) { void LibKernel_Register(Loader::SymbolsResolver* sym) {
// obj // obj
LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &g_stack_chk_guard); LIB_OBJ("f7uOxY9mM1U", "libkernel", 1, "libkernel", 1, 1, &g_stack_chk_guard);
@ -49,6 +58,8 @@ void LibKernel_Register(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelIsNeoMode); LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, Kernel::sceKernelIsNeoMode);
LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail);
LIB_FUNCTION("9BcDykPmo1I", "libkernel", 1, "libkernel", 1, 1, __Error); LIB_FUNCTION("9BcDykPmo1I", "libkernel", 1, "libkernel", 1, 1, __Error);
LIB_FUNCTION("959qrazPIrg", "libkernel", 1, "libkernel", 1, 1, sceKernelGetProcParam);
Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym); Core::Libraries::LibKernel::fileSystemSymbolsRegister(sym);
Core::Libraries::LibKernel::timeSymbolsRegister(sym); Core::Libraries::LibKernel::timeSymbolsRegister(sym);

View File

@ -130,6 +130,7 @@ void Linker::LoadModuleToMemory(Module* m) {
LOG_ERROR_IF(debug_loader, "p_filesz==0 in type {}\n", m->elf.ElfPheaderTypeStr(elf_pheader[i].p_type)); LOG_ERROR_IF(debug_loader, "p_filesz==0 in type {}\n", m->elf.ElfPheaderTypeStr(elf_pheader[i].p_type));
} }
break; break;
case PT_SCE_PROCPARAM: m->proc_param_virtual_addr = elf_pheader[i].p_vaddr + m->base_virtual_addr; break;
default: LOG_ERROR_IF(debug_loader, "Unimplemented type {}\n", m->elf.ElfPheaderTypeStr(elf_pheader[i].p_type)); default: LOG_ERROR_IF(debug_loader, "Unimplemented type {}\n", m->elf.ElfPheaderTypeStr(elf_pheader[i].p_type));
} }
} }
@ -607,6 +608,17 @@ void Linker::StartAllModules() {
} }
} }
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;
}
static PS4_SYSV_ABI void ProgramExitFunc() { fmt::print("exit function called\n"); } static PS4_SYSV_ABI void ProgramExitFunc() { fmt::print("exit function called\n"); }
static void run_main_entry(u64 addr, EntryParams* params, exit_func_t exit_func) { static void run_main_entry(u64 addr, EntryParams* params, exit_func_t exit_func) {

View File

@ -93,6 +93,7 @@ struct DynamicModuleInfo {
std::vector<LibraryInfo> export_libs; std::vector<LibraryInfo> export_libs;
std::string filename; // Filename with absolute path std::string filename; // Filename with absolute path
}; };
// This struct keeps neccesary info about loaded modules. Main executeable is included too as well // This struct keeps neccesary info about loaded modules. Main executeable is included too as well
@ -109,6 +110,8 @@ struct Module {
Loader::SymbolsResolver export_sym; Loader::SymbolsResolver export_sym;
Loader::SymbolsResolver import_sym; Loader::SymbolsResolver import_sym;
u64 proc_param_virtual_addr = 0;
}; };
class Linker { class Linker {
@ -127,6 +130,7 @@ public:
void RelocateAll(); void RelocateAll();
int StartModule(Module* m, size_t args, const void* argp, module_func_t func); int StartModule(Module* m, size_t args, const void* argp, module_func_t func);
void StartAllModules(); void StartAllModules();
u64 GetProcParam();
private: private:
const ModuleInfo* FindModule(const Module& m, const std::string& id); const ModuleInfo* FindModule(const Module& m, const std::string& id);