From ce158290fbd7871a3f890323501e6fe3e8bec832 Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:00:57 -0600 Subject: [PATCH] Minor Kernel Fixes (#1529) * Skip destruction of adaptive mutex initializers Based around similar behaviors implemented in the more-kernel branch. Hatsune Miku Project Diva X needs this. * Fix posix_lseek result overflow Seen when testing Spider-Man Miles Morales on more-kernel. * Add posix_fsync Used by Spider-Man Miles Morales. I've added the normal posix error handling to this function, though I'm aware sceKernelFsync doesn't return any errors currently. This is for future proofing and accuracy, as the actual libkernel does the usual error handling too. * Properly handle VirtualQuery calls on PoolReserved memory. * Export posix_getpagesize under libkernel Bloons TD 5 needs this. * Clang --- src/core/libraries/kernel/file_system.cpp | 14 +++++++++++++- src/core/libraries/kernel/libkernel.cpp | 1 + src/core/libraries/kernel/thread_management.cpp | 4 ++++ src/core/memory.cpp | 3 ++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index 7f86ee54..e6b657c3 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -237,7 +237,7 @@ s64 PS4_SYSV_ABI sceKernelLseek(int d, s64 offset, int whence) { } s64 PS4_SYSV_ABI posix_lseek(int d, s64 offset, int whence) { - int result = sceKernelLseek(d, offset, whence); + s64 result = sceKernelLseek(d, offset, whence); if (result < 0) { LOG_ERROR(Kernel_Pthread, "posix_lseek: error = {}", result); ErrSceToPosix(result); @@ -490,6 +490,16 @@ s32 PS4_SYSV_ABI sceKernelFsync(int fd) { return ORBIS_OK; } +s32 PS4_SYSV_ABI posix_fsync(int fd) { + s32 result = sceKernelFsync(fd); + if (result < 0) { + LOG_ERROR(Kernel_Pthread, "posix_fstat: error = {}", result); + ErrSceToPosix(result); + return -1; + } + return result; +} + int PS4_SYSV_ABI sceKernelFtruncate(int fd, s64 length) { auto* h = Common::Singleton::Instance(); auto* file = h->GetFile(fd); @@ -642,6 +652,8 @@ void fileSystemSymbolsRegister(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("+r3rMFwItV4", "libkernel", 1, "libkernel", 1, 1, sceKernelPread); LIB_FUNCTION("uWyW3v98sU4", "libkernel", 1, "libkernel", 1, 1, sceKernelCheckReachability); LIB_FUNCTION("fTx66l5iWIA", "libkernel", 1, "libkernel", 1, 1, sceKernelFsync); + LIB_FUNCTION("juWbTNM+8hw", "libkernel", 1, "libkernel", 1, 1, posix_fsync); + LIB_FUNCTION("juWbTNM+8hw", "libScePosix", 1, "libkernel", 1, 1, posix_fsync); LIB_FUNCTION("j2AIqSqJP0w", "libkernel", 1, "libkernel", 1, 1, sceKernelGetdents); LIB_FUNCTION("taRWhTJFTgE", "libkernel", 1, "libkernel", 1, 1, sceKernelGetdirentries); LIB_FUNCTION("nKWi-N2HBV4", "libkernel", 1, "libkernel", 1, 1, sceKernelPwrite); diff --git a/src/core/libraries/kernel/libkernel.cpp b/src/core/libraries/kernel/libkernel.cpp index c621b4bc..b3eb81ec 100644 --- a/src/core/libraries/kernel/libkernel.cpp +++ b/src/core/libraries/kernel/libkernel.cpp @@ -491,6 +491,7 @@ void LibKernel_Register(Core::Loader::SymbolsResolver* sym) { LIB_FUNCTION("-o5uEDpN+oY", "libkernel", 1, "libkernel", 1, 1, sceKernelConvertUtcToLocaltime); LIB_FUNCTION("WB66evu8bsU", "libkernel", 1, "libkernel", 1, 1, sceKernelGetCompiledSdkVersion); LIB_FUNCTION("DRuBt2pvICk", "libkernel", 1, "libkernel", 1, 1, ps4__read); + LIB_FUNCTION("k+AXqu2-eBc", "libkernel", 1, "libkernel", 1, 1, posix_getpagesize); LIB_FUNCTION("k+AXqu2-eBc", "libScePosix", 1, "libkernel", 1, 1, posix_getpagesize); Libraries::Kernel::fileSystemSymbolsRegister(sym); diff --git a/src/core/libraries/kernel/thread_management.cpp b/src/core/libraries/kernel/thread_management.cpp index 39c0eaf8..85f61809 100644 --- a/src/core/libraries/kernel/thread_management.cpp +++ b/src/core/libraries/kernel/thread_management.cpp @@ -477,6 +477,10 @@ int PS4_SYSV_ABI scePthreadMutexDestroy(ScePthreadMutex* mutex) { return SCE_KERNEL_ERROR_EINVAL; } + if (*mutex == ORBIS_PTHREAD_MUTEX_ADAPTIVE_INITIALIZER) { + return ORBIS_OK; + } + int result = pthread_mutex_destroy(&(*mutex)->pth_mutex); LOG_DEBUG(Kernel_Pthread, "name={}, result={}", (*mutex)->name, result); diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 031b7b13..61eb421e 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -514,7 +514,8 @@ int MemoryManager::VirtualQuery(VAddr addr, int flags, info->is_direct.Assign(vma.type == VMAType::Direct); info->is_stack.Assign(vma.type == VMAType::Stack); info->is_pooled.Assign(vma.type == VMAType::Pooled); - info->is_committed.Assign(vma.type != VMAType::Free && vma.type != VMAType::Reserved); + info->is_committed.Assign(vma.type != VMAType::Free && vma.type != VMAType::Reserved && + vma.type != VMAType::PoolReserved); vma.name.copy(info->name.data(), std::min(info->name.size(), vma.name.size())); if (vma.type == VMAType::Direct) { const auto dmem_it = FindDmemArea(vma.phys_base);