Kernel Fixes (#1605)

* scePthreadSetprio Changes

FindThread uses posix error codes, so the function export should apply the ORBIS wrapper to convert these. Since it uses posix codes, I've also renamed the function to align with other posix functions. Lastly, this fixes a compile warning about ret sometimes not getting initialized.

* Implement posix_munmap

Used by Hatsune Miku Project Diva X during intros. May help with stability on Linux, probably won't change anything on Windows.

* Exports

Some missing function exports I've seen in my tests.
sceKernelAvailableFlexibleMemorySize export is used in Final Fantasy XV Episode Duscae
posix_pthread_setprio and posix_pthread_getschedparam are used by Spider-Man Miles Morales
scePthreadKeyDelete is used in UE4 games.

I've also added in a typo fix related to my previous PR.

* libScePosix export for posix_pthread_attr_setguardsize

Used in Hatsune Miku Project Diva X v1.02
This commit is contained in:
Stephen Miller 2024-11-30 02:28:31 -06:00 committed by GitHub
parent 2d7766b70b
commit 666b0609f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 25 additions and 7 deletions

View file

@ -502,7 +502,7 @@ s32 PS4_SYSV_ABI sceKernelFsync(int fd) {
s32 PS4_SYSV_ABI posix_fsync(int fd) { s32 PS4_SYSV_ABI posix_fsync(int fd) {
s32 result = sceKernelFsync(fd); s32 result = sceKernelFsync(fd);
if (result < 0) { if (result < 0) {
LOG_ERROR(Kernel_Pthread, "posix_fstat: error = {}", result); LOG_ERROR(Kernel_Pthread, "posix_fsync: error = {}", result);
ErrSceToPosix(result); ErrSceToPosix(result);
return -1; return -1;
} }

View file

@ -10,6 +10,7 @@
#include "common/singleton.h" #include "common/singleton.h"
#include "core/file_sys/fs.h" #include "core/file_sys/fs.h"
#include "core/libraries/error_codes.h" #include "core/libraries/error_codes.h"
#include "core/libraries/kernel/kernel.h"
#include "core/libraries/kernel/memory.h" #include "core/libraries/kernel/memory.h"
#include "core/libraries/libs.h" #include "core/libraries/libs.h"
#include "core/linker.h" #include "core/linker.h"
@ -495,6 +496,16 @@ int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len) {
return SCE_OK; return SCE_OK;
} }
int PS4_SYSV_ABI posix_munmap(void* addr, size_t len) {
int result = sceKernelMunmap(addr, len);
if (result < 0) {
LOG_ERROR(Kernel_Pthread, "posix_munmap: error = {}", result);
ErrSceToPosix(result);
return -1;
}
return result;
}
void RegisterMemory(Core::Loader::SymbolsResolver* sym) { void RegisterMemory(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory); LIB_FUNCTION("rTXw65xmLIA", "libkernel", 1, "libkernel", 1, 1, sceKernelAllocateDirectMemory);
LIB_FUNCTION("B+vc2AO2Zrc", "libkernel", 1, "libkernel", 1, 1, LIB_FUNCTION("B+vc2AO2Zrc", "libkernel", 1, "libkernel", 1, 1,
@ -517,6 +528,8 @@ void RegisterMemory(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("mL8NDH86iQI", "libkernel", 1, "libkernel", 1, 1, sceKernelMapNamedFlexibleMemory); LIB_FUNCTION("mL8NDH86iQI", "libkernel", 1, "libkernel", 1, 1, sceKernelMapNamedFlexibleMemory);
LIB_FUNCTION("aNz11fnnzi4", "libkernel", 1, "libkernel", 1, 1, LIB_FUNCTION("aNz11fnnzi4", "libkernel", 1, "libkernel", 1, 1,
sceKernelAvailableFlexibleMemorySize); sceKernelAvailableFlexibleMemorySize);
LIB_FUNCTION("aNz11fnnzi4", "libkernel_avlfmem", 1, "libkernel", 1, 1,
sceKernelAvailableFlexibleMemorySize);
LIB_FUNCTION("IWIBBdTHit4", "libkernel", 1, "libkernel", 1, 1, sceKernelMapFlexibleMemory); LIB_FUNCTION("IWIBBdTHit4", "libkernel", 1, "libkernel", 1, 1, sceKernelMapFlexibleMemory);
LIB_FUNCTION("p5EcQeEeJAE", "libkernel", 1, "libkernel", 1, 1, LIB_FUNCTION("p5EcQeEeJAE", "libkernel", 1, "libkernel", 1, 1,
_sceKernelRtldSetApplicationHeapAPI); _sceKernelRtldSetApplicationHeapAPI);
@ -537,6 +550,8 @@ void RegisterMemory(Core::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("BPE9s9vQQXo", "libScePosix", 1, "libkernel", 1, 1, posix_mmap); LIB_FUNCTION("BPE9s9vQQXo", "libScePosix", 1, "libkernel", 1, 1, posix_mmap);
LIB_FUNCTION("UqDGjXA5yUM", "libkernel", 1, "libkernel", 1, 1, posix_munmap);
LIB_FUNCTION("UqDGjXA5yUM", "libScePosix", 1, "libkernel", 1, 1, posix_munmap);
} }
} // namespace Libraries::Kernel } // namespace Libraries::Kernel

View file

@ -421,29 +421,27 @@ int PS4_SYSV_ABI scePthreadGetprio(PthreadT thread, int* priority) {
return 0; return 0;
} }
int PS4_SYSV_ABI scePthreadSetprio(PthreadT thread, int prio) { int PS4_SYSV_ABI posix_pthread_setprio(PthreadT thread, int prio) {
SchedParam param; SchedParam param;
int ret;
param.sched_priority = prio; param.sched_priority = prio;
auto* thread_state = ThrState::Instance(); auto* thread_state = ThrState::Instance();
if (thread == g_curthread) { if (thread == g_curthread) {
g_curthread->lock.lock(); g_curthread->lock.lock();
} else if (int ret = thread_state->FindThread(thread, /*include dead*/ 0)) { } else if (int ret = thread_state->FindThread(thread, /*include dead*/ 0); ret != 0) {
return ret; return ret;
} }
if (thread->attr.sched_policy == SchedPolicy::Other || thread->attr.prio == prio) { if (thread->attr.sched_policy == SchedPolicy::Other || thread->attr.prio == prio) {
thread->attr.prio = prio; thread->attr.prio = prio;
ret = 0;
} else { } else {
// TODO: _thr_setscheduler // TODO: _thr_setscheduler
thread->attr.prio = prio; thread->attr.prio = prio;
} }
thread->lock.unlock(); thread->lock.unlock();
return ret; return 0;
} }
enum class PthreadCancelState : u32 { enum class PthreadCancelState : u32 {
@ -495,6 +493,8 @@ void RegisterThread(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("OxhIB8LB-PQ", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_create); LIB_FUNCTION("OxhIB8LB-PQ", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_create);
LIB_FUNCTION("Jmi+9w9u0E4", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_create_name_np); LIB_FUNCTION("Jmi+9w9u0E4", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_create_name_np);
LIB_FUNCTION("lZzFeSxPl08", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_setcancelstate); LIB_FUNCTION("lZzFeSxPl08", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_setcancelstate);
LIB_FUNCTION("a2P9wYGeZvc", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_setprio);
LIB_FUNCTION("FIs3-UQT9sg", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_getschedparam);
LIB_FUNCTION("6XG4B33N09g", "libScePosix", 1, "libkernel", 1, 1, sched_yield); LIB_FUNCTION("6XG4B33N09g", "libScePosix", 1, "libkernel", 1, 1, sched_yield);
// Posix-Kernel // Posix-Kernel
@ -517,7 +517,7 @@ void RegisterThread(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("T72hz6ffq08", "libkernel", 1, "libkernel", 1, 1, posix_pthread_yield); LIB_FUNCTION("T72hz6ffq08", "libkernel", 1, "libkernel", 1, 1, posix_pthread_yield);
LIB_FUNCTION("EI-5-jlq2dE", "libkernel", 1, "libkernel", 1, 1, posix_pthread_getthreadid_np); LIB_FUNCTION("EI-5-jlq2dE", "libkernel", 1, "libkernel", 1, 1, posix_pthread_getthreadid_np);
LIB_FUNCTION("1tKyG7RlMJo", "libkernel", 1, "libkernel", 1, 1, scePthreadGetprio); LIB_FUNCTION("1tKyG7RlMJo", "libkernel", 1, "libkernel", 1, 1, scePthreadGetprio);
LIB_FUNCTION("W0Hpm2X0uPE", "libkernel", 1, "libkernel", 1, 1, scePthreadSetprio); LIB_FUNCTION("W0Hpm2X0uPE", "libkernel", 1, "libkernel", 1, 1, ORBIS(posix_pthread_setprio));
LIB_FUNCTION("rNhWz+lvOMU", "libkernel", 1, "libkernel", 1, 1, _sceKernelSetThreadDtors); LIB_FUNCTION("rNhWz+lvOMU", "libkernel", 1, "libkernel", 1, 1, _sceKernelSetThreadDtors);
LIB_FUNCTION("6XG4B33N09g", "libkernel", 1, "libkernel", 1, 1, sched_yield); LIB_FUNCTION("6XG4B33N09g", "libkernel", 1, "libkernel", 1, 1, sched_yield);
} }

View file

@ -303,6 +303,8 @@ void RegisterThreadAttr(Core::Loader::SymbolsResolver* sym) {
posix_pthread_attr_getstacksize); posix_pthread_attr_getstacksize);
LIB_FUNCTION("VUT1ZSrHT0I", "libScePosix", 1, "libkernel", 1, 1, LIB_FUNCTION("VUT1ZSrHT0I", "libScePosix", 1, "libkernel", 1, 1,
posix_pthread_attr_getdetachstate); posix_pthread_attr_getdetachstate);
LIB_FUNCTION("JKyG3SWyA10", "libScePosix", 1, "libkernel", 1, 1,
posix_pthread_attr_setguardsize);
// Orbis // Orbis
LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1, LIB_FUNCTION("4+h9EzwKF4I", "libkernel", 1, "libkernel", 1, 1,

View file

@ -150,6 +150,7 @@ void RegisterSpec(Core::Loader::SymbolsResolver* sym) {
// Orbis // Orbis
LIB_FUNCTION("geDaqgH9lTg", "libkernel", 1, "libkernel", 1, 1, ORBIS(posix_pthread_key_create)); LIB_FUNCTION("geDaqgH9lTg", "libkernel", 1, "libkernel", 1, 1, ORBIS(posix_pthread_key_create));
LIB_FUNCTION("PrdHuuDekhY", "libkernel", 1, "libkernel", 1, 1, ORBIS(posix_pthread_key_delete));
LIB_FUNCTION("eoht7mQOCmo", "libkernel", 1, "libkernel", 1, 1, posix_pthread_getspecific); LIB_FUNCTION("eoht7mQOCmo", "libkernel", 1, "libkernel", 1, 1, posix_pthread_getspecific);
LIB_FUNCTION("+BzXYkqYeLE", "libkernel", 1, "libkernel", 1, 1, LIB_FUNCTION("+BzXYkqYeLE", "libkernel", 1, "libkernel", 1, 1,
ORBIS(posix_pthread_setspecific)); ORBIS(posix_pthread_setspecific));