From f88648c5a2962553f8168326d97ead0da1773647 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Apr 2021 17:10:35 -0700 Subject: [PATCH 1/3] Kernel: Define most reported missing kernel funcs. Kernel plugins and patches are still often not going to work, but might as well define these. --- Core/HLE/sceKernel.cpp | 26 ++++++++++++++++++++++++++ Core/HLE/sceKernelInterrupt.cpp | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 5907848036..d4b4619878 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -913,6 +913,32 @@ const HLEFunction ThreadManForKernel[] = {0x616403ba, &WrapI_I, "sceKernelTerminateThread", 'i', "i" ,HLE_KERNEL_SYSCALL }, {0x383f7bcc, &WrapI_I, "sceKernelTerminateDeleteThread", 'i', "i" ,HLE_KERNEL_SYSCALL }, {0x57cf62dd, &WrapU_U, "sceKernelGetThreadmanIdType", 'x', "x" ,HLE_KERNEL_SYSCALL }, + {0x94aa61ee, &WrapI_V, "sceKernelGetThreadCurrentPriority", 'i', "", HLE_KERNEL_SYSCALL }, + {0x293B45B8, &WrapI_V, "sceKernelGetThreadId", 'i', "", HLE_KERNEL_SYSCALL | HLE_NOT_IN_INTERRUPT }, + {0x3B183E26, &WrapI_I, "sceKernelGetThreadExitStatus", 'i', "i", HLE_KERNEL_SYSCALL }, + {0x82BC5777, &WrapU64_V, "sceKernelGetSystemTimeWide", 'X', "", HLE_KERNEL_SYSCALL }, + {0xDB738F35, &WrapI_U, "sceKernelGetSystemTime", 'i', "x", HLE_KERNEL_SYSCALL }, + {0x369ED59D, &WrapU_V, "sceKernelGetSystemTimeLow", 'x', "", HLE_KERNEL_SYSCALL }, + {0x6652B8CA, &WrapI_UUU, "sceKernelSetAlarm", 'i', "xxx", HLE_KERNEL_SYSCALL }, + {0xB2C25152, &WrapI_UUU, "sceKernelSetSysClockAlarm", 'i', "xxx", HLE_KERNEL_SYSCALL }, + {0x7E65B999, &WrapI_I, "sceKernelCancelAlarm", 'i', "i", HLE_KERNEL_SYSCALL }, + {0xDAA3F564, &WrapI_IU, "sceKernelReferAlarmStatus", 'i', "ix", HLE_KERNEL_SYSCALL }, + {0x8125221D, &WrapI_CUU, "sceKernelCreateMbx", 'i', "sxx", HLE_KERNEL_SYSCALL }, + {0x86255ADA, &WrapI_I, "sceKernelDeleteMbx", 'i', "i", HLE_KERNEL_SYSCALL }, + {0xE9B3061E, &WrapI_IU, "sceKernelSendMbx", 'i', "ix", HLE_KERNEL_SYSCALL }, + {0x18260574, &WrapI_IUU, "sceKernelReceiveMbx", 'i', "ixx", HLE_KERNEL_SYSCALL | HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED }, + {0xF3986382, &WrapI_IUU, "sceKernelReceiveMbxCB", 'i', "ixx", HLE_KERNEL_SYSCALL | HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED }, + {0x0D81716A, &WrapI_IU, "sceKernelPollMbx", 'i', "ix", HLE_KERNEL_SYSCALL }, + {0x87D4DD36, &WrapI_IU, "sceKernelCancelReceiveMbx", 'i', "ix", HLE_KERNEL_SYSCALL }, + {0xA8E8C846, &WrapI_IU, "sceKernelReferMbxStatus", 'i', "ix", HLE_KERNEL_SYSCALL }, + {0x56C039B5, &WrapI_CIUUU, "sceKernelCreateVpl", 'i', "sixxx", HLE_KERNEL_SYSCALL }, + {0x89B3D48C, &WrapI_I, "sceKernelDeleteVpl", 'i', "i", HLE_KERNEL_SYSCALL }, + {0xBED27435, &WrapI_IUUU, "sceKernelAllocateVpl", 'i', "ixxx", HLE_KERNEL_SYSCALL | HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED }, + {0xEC0A693F, &WrapI_IUUU, "sceKernelAllocateVplCB", 'i', "ixxx", HLE_KERNEL_SYSCALL | HLE_NOT_IN_INTERRUPT | HLE_NOT_DISPATCH_SUSPENDED }, + {0xAF36D708, &WrapI_IUU, "sceKernelTryAllocateVpl", 'i', "ixx", HLE_KERNEL_SYSCALL }, + {0xB736E9FF, &WrapI_IU, "sceKernelFreeVpl", 'i', "ix", HLE_KERNEL_SYSCALL }, + {0x1D371B8A, &WrapI_IU, "sceKernelCancelVpl", 'i', "ix", HLE_KERNEL_SYSCALL }, + {0x39810265, &WrapI_IU, "sceKernelReferVplStatus", 'i', "ix", HLE_KERNEL_SYSCALL }, }; void Register_ThreadManForUser() diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index 161979a353..88a3848be5 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -15,9 +15,10 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. -#include +#include #include #include +#include #include "Common/Serialize/Serializer.h" #include "Common/Serialize/SerializeFuncs.h" @@ -798,6 +799,31 @@ static u32 sysclib_memmove(u32 dst, u32 src, u32 size) { return 0; } +static u32 sysclib_strncpy(u32 dest, u32 src, u32 size) { + if (!Memory::IsValidAddress(dest) || Memory::IsValidAddress(src)) { + return hleLogError(SCEKERNEL, 0, "invalid address"); + } + + // This is just regular strncpy, but being explicit to avoid warnings/safety fixes on missing null. + u32 i = 0; + u32 srcSize = Memory::ValidSize(src, size); + const u8 *srcp = Memory::GetPointer(src); + u8 *destp = Memory::GetPointer(dest); + for (i = 0; i < srcSize; ++i) { + u8 c = *srcp++; + if (c == 0) + break; + *destp++ = c; + } + + u32 destSize = Memory::ValidSize(dest, size); + for (; i < destSize; ++i) { + *destp++ = 0; + } + + return hleLogSuccessX(SCEKERNEL, dest); +} + const HLEFunction SysclibForKernel[] = { {0xAB7592FF, &WrapU_UUU, "memcpy", 'x', "xxx", HLE_KERNEL_SYSCALL }, @@ -809,8 +835,9 @@ const HLEFunction SysclibForKernel[] = {0x7661E728, &WrapI_UU, "sprintf", 'i', "xx", HLE_KERNEL_SYSCALL }, {0x10F3BB61, &WrapU_UII, "memset", 'x', "xii", HLE_KERNEL_SYSCALL }, {0x0D188658, &WrapI_UU, "strstr", 'i', "xx", HLE_KERNEL_SYSCALL }, - {0x7AB35214, &WrapI_UUU, "strncmp", 'i', "xxx", HLE_KERNEL_SYSCALL }, - {0xA48D2592, &WrapU_UUU, "memmove", 'x', "xxx", HLE_KERNEL_SYSCALL }, + {0x7AB35214, &WrapI_UUU, "strncmp", 'i', "xxx", HLE_KERNEL_SYSCALL }, + {0xA48D2592, &WrapU_UUU, "memmove", 'x', "xxx", HLE_KERNEL_SYSCALL }, + {0xB49A7697, &WrapU_UUU, "strncpy", 'x', "xxi", HLE_KERNEL_SYSCALL }, }; void Register_Kernel_Library() From eedd0b32ddf369d1f42770cbac858591b77951c7 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Apr 2021 15:18:09 -0700 Subject: [PATCH 2/3] Module: Add a missing error return case. --- Core/HLE/sceKernelModule.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index b6d73cc023..59d23607ad 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -1184,6 +1184,8 @@ static PSPModule *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 load *error_string = StringFromFormat("ELF/PRX truncated: %d > %d", (int)size, (int)elfSize); module->Cleanup(); kernelObjects.Destroy(module->GetUID()); + // TODO: Might be the wrong error code. + error = SCE_KERNEL_ERROR_FILEERR; return nullptr; } const auto maxElfSize = std::max(head->elf_size, head->psp_size); From ffd468c3ae3f6be7b47411cd64bc590b1bb57589 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Apr 2021 18:33:44 -0700 Subject: [PATCH 3/3] Reporting: Add more info to libstubend error. --- Core/HLE/sceKernelModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 59d23607ad..1501681784 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -986,7 +986,7 @@ static bool KernelImportModuleFuncs(PSPModule *module, u32 *firstImportStubAddr, return false; } if (!Memory::IsValidRange(module->libstub, module->libstubend - module->libstub)) { - ERROR_LOG_REPORT(LOADER, "Garbage libstub address or end"); + ERROR_LOG_REPORT(LOADER, "Garbage libstub address %08x or end %08x", module->libstub, module->libstubend); return false; }