Skip to content

Commit

Permalink
Minor Kernel Fixes (shadps4-emu#1529)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
StevenMiller123 authored Nov 14, 2024
1 parent 7be35c3 commit ce15829
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/core/libraries/kernel/file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<Core::FileSys::HandleTable>::Instance();
auto* file = h->GetFile(fd);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/core/libraries/kernel/libkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/core/libraries/kernel/thread_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ce15829

Please sign in to comment.