From 98090ae42f14165e433094e97ef3b6bb896c5002 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Fri, 8 Sep 2023 08:28:01 +0300 Subject: [PATCH] initial sceKernelWaitEqueue implementation (WIP) --- src/Core/PS4/HLE/ErrorCodes.h | 1 + src/Core/PS4/HLE/Kernel/Objects/event_queue.h | 4 +-- src/Core/PS4/HLE/Kernel/event_queues.cpp | 29 +++++++++++++++++++ src/Core/PS4/HLE/Kernel/event_queues.h | 4 +++ src/Core/PS4/HLE/LibKernel.cpp | 7 +---- src/Core/PS4/HLE/LibKernel.h | 2 -- 6 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/Core/PS4/HLE/ErrorCodes.h b/src/Core/PS4/HLE/ErrorCodes.h index f80a8e02..9b7d65b8 100644 --- a/src/Core/PS4/HLE/ErrorCodes.h +++ b/src/Core/PS4/HLE/ErrorCodes.h @@ -1,6 +1,7 @@ #pragma once constexpr int SCE_OK = 0; +constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009; constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c; // Insufficient memory constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address pointer constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; // null or invalid states diff --git a/src/Core/PS4/HLE/Kernel/Objects/event_queue.h b/src/Core/PS4/HLE/Kernel/Objects/event_queue.h index 6651107c..8e5bdd76 100644 --- a/src/Core/PS4/HLE/Kernel/Objects/event_queue.h +++ b/src/Core/PS4/HLE/Kernel/Objects/event_queue.h @@ -38,7 +38,7 @@ using TriggerFunc = void (*)(EqueueEvent* event, void* trigger_data); using ResetFunc = void (*)(EqueueEvent* event); using DeleteFunc = void (*)(SceKernelEqueue eq, EqueueEvent* event); -struct Event { +struct SceKernelEvent { u64 ident = 0; /* identifier for this event */ s16 filter = 0; /* filter for event */ u16 flags = 0; @@ -56,7 +56,7 @@ struct Filter { struct EqueueEvent { bool isTriggered = false; - Event event; + SceKernelEvent event; Filter filter; }; diff --git a/src/Core/PS4/HLE/Kernel/event_queues.cpp b/src/Core/PS4/HLE/Kernel/event_queues.cpp index 4af5bd6b..15940584 100644 --- a/src/Core/PS4/HLE/Kernel/event_queues.cpp +++ b/src/Core/PS4/HLE/Kernel/event_queues.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace HLE::Libs::LibKernel::EventQueues { constexpr bool log_file_equeues = true; // disable it to disable logging @@ -34,4 +35,32 @@ int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) { LOG_INFO_IF(log_file_equeues, "sceKernelCreateEqueue created with name \"{}\"\n", name); return SCE_OK; } + +int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, HLE::Kernel::Objects::SceKernelEvent* ev, int num, int* out, SceKernelUseconds* timo) { + PRINT_FUNCTION_NAME(); + + if (eq == nullptr) { + return SCE_KERNEL_ERROR_EBADF; + } + + if (ev == nullptr) { + return SCE_KERNEL_ERROR_EFAULT; + } + + if (num < 1) { + return SCE_KERNEL_ERROR_EINVAL; + } + if (timo == nullptr) { // wait until an event arrives without timing out + // BREAKPOINT();//NOT supported yet TODO + } + if (timo != nullptr) { + if (*timo == 0) {//only events that have already arrived at the time of this function call can be received + BREAKPOINT(); + } else { // wait until an event arrives with timing out + BREAKPOINT(); + } + } + return SCE_OK; +} + }; // namespace HLE::Libs::LibKernel::EventQueues \ No newline at end of file diff --git a/src/Core/PS4/HLE/Kernel/event_queues.h b/src/Core/PS4/HLE/Kernel/event_queues.h index 3072e4fd..97121540 100644 --- a/src/Core/PS4/HLE/Kernel/event_queues.h +++ b/src/Core/PS4/HLE/Kernel/event_queues.h @@ -1,10 +1,14 @@ #pragma once #include + #include "Objects/event_queue.h" namespace HLE::Libs::LibKernel::EventQueues { +using SceKernelUseconds = u32; using SceKernelEqueue = Kernel::Objects::EqueueInternal*; int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name); +int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, HLE::Kernel::Objects::SceKernelEvent* ev, int num, int* out, SceKernelUseconds *timo); + }; // namespace HLE::Libs::LibKernel::EventQueues \ No newline at end of file diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index caf74e32..a35fcb4b 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -18,11 +18,6 @@ namespace HLE::Libs::LibKernel { return 0; } - int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/) - { - PRINT_DUMMY_FUNCTION_NAME(); - return 0; - } static PS4_SYSV_ABI void stack_chk_fail() { BREAKPOINT(); } @@ -36,7 +31,7 @@ namespace HLE::Libs::LibKernel { LIB_FUNCTION("MBuItvba6z8", "libkernel", 1, "libkernel", 1, 1, sceKernelReleaseDirectMemory); //equeue LIB_FUNCTION("D0OdFMjp46I", "libkernel", 1, "libkernel", 1, 1, EventQueues::sceKernelCreateEqueue); - LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, sceKernelWaitEqueue); + LIB_FUNCTION("fzyMKs9kim0", "libkernel", 1, "libkernel", 1, 1, EventQueues::sceKernelWaitEqueue); //misc LIB_FUNCTION("WslcK1FQcGI", "libkernel", 1, "libkernel", 1, 1, CPUManagement::sceKernelIsNeoMode); LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); diff --git a/src/Core/PS4/HLE/LibKernel.h b/src/Core/PS4/HLE/LibKernel.h index cf38fcc0..4f4f851a 100644 --- a/src/Core/PS4/HLE/LibKernel.h +++ b/src/Core/PS4/HLE/LibKernel.h @@ -8,6 +8,4 @@ void LibKernel_Register(SymbolsResolver* sym); int32_t PS4_SYSV_ABI sceKernelReleaseDirectMemory(off_t start, size_t len); - -int PS4_SYSV_ABI sceKernelWaitEqueue(/*SceKernelEqueue eq, SceKernelEvent* ev,*/ int num, int* out /*, SceKernelUseconds* timo*/); }; // namespace HLE::Libs::LibKernel \ No newline at end of file