implemented sceKernelGetProcParam

This commit is contained in:
georgemoralis 2024-03-26 18:48:26 +02:00
parent 683a0d55bf
commit da7b4df1c3
4 changed files with 29 additions and 1 deletions

View File

@ -85,6 +85,9 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl
GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess; GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess;
switch (prot) { switch (prot) {
case 0x03:
cpu_mode = VirtualMemory::MemoryMode::ReadWrite;
break;
case 0x32: case 0x32:
case 0x33: // SCE_KERNEL_PROT_CPU_READ|SCE_KERNEL_PROT_CPU_WRITE|SCE_KERNEL_PROT_GPU_READ|SCE_KERNEL_PROT_GPU_ALL 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; cpu_mode = VirtualMemory::MemoryMode::ReadWrite;

View File

@ -19,11 +19,20 @@
#else #else
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
#include <common/singleton.h>
#include <core/linker.h>
namespace Core::Libraries::LibKernel { namespace Core::Libraries::LibKernel {
static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return static u64 g_stack_chk_guard = 0xDEADBEEF54321ABC; // dummy return
static void* PS4_SYSV_ABI sceKernelGetProcParam() {
auto* linker = Common::Singleton<Core::Linker>::Instance();
return reinterpret_cast<void*>(linker->GetProcParam());
}
int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) { int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len) {
UNREACHABLE(); UNREACHABLE();
return 0; return 0;
@ -139,6 +148,7 @@ void LibKernel_Register(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("BPE9s9vQQXo", "libkernel", 1, "libkernel", 1, 1, posix_mmap); LIB_FUNCTION("BPE9s9vQQXo", "libkernel", 1, "libkernel", 1, 1, posix_mmap);
LIB_FUNCTION("1jfXLRVzisc", "libkernel", 1, "libkernel", 1, 1, sceKernelUsleep); LIB_FUNCTION("1jfXLRVzisc", "libkernel", 1, "libkernel", 1, 1, sceKernelUsleep);
LIB_FUNCTION("YSHRBRLn2pI", "libkernel", 1, "libkernel", 1, 1, _writev); 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::fileSystemSymbolsRegister(sym);
Core::Libraries::LibKernel::timeSymbolsRegister(sym); Core::Libraries::LibKernel::timeSymbolsRegister(sym);

View File

@ -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 virtual address ={:#x}", m->tls.image_virtual_addr);
LOG_INFO(Core_Linker, "tls image size ={}", m->tls.image_size); LOG_INFO(Core_Linker, "tls image size ={}", m->tls.image_size);
break; break;
case PT_SCE_PROCPARAM:
m->proc_param_virtual_addr = elf_pheader[i].p_vaddr + m->base_virtual_addr;
break;
default: default:
LOG_ERROR(Core_Linker, "Unimplemented type {}", LOG_ERROR(Core_Linker, "Unimplemented type {}",
m->elf.ElfPheaderTypeStr(elf_pheader[i].p_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 exit_func_t = PS4_SYSV_ABI void (*)();
using entry_func_t = PS4_SYSV_ABI void (*)(EntryParams* params, exit_func_t atexit_func); 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); using module_ini_func_t = PS4_SYSV_ABI int (*)(size_t args, const void* argp, module_func_t func);

View File

@ -106,6 +106,7 @@ struct Module {
Loader::Elf elf; Loader::Elf elf;
u64 aligned_base_size = 0; u64 aligned_base_size = 0;
u64 base_virtual_addr = 0; u64 base_virtual_addr = 0;
u64 proc_param_virtual_addr = 0;
std::string file_name; std::string file_name;
@ -137,6 +138,7 @@ public:
Loader::SymbolRecord* return_info); Loader::SymbolRecord* return_info);
void Execute(); void Execute();
void DebugDump(); void DebugDump();
u64 GetProcParam();
private: private:
const ModuleInfo* FindModule(const Module& m, const std::string& id); const ModuleInfo* FindModule(const Module& m, const std::string& id);