mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
feat(libkernel): implement the sceKernelGetEvent* field accessors
sceKernelGetEventId, sceKernelGetEventFilter, sceKernelGetEventFflags, sceKernelGetEventData and sceKernelGetEventUserData return the matching field of the KernelEvent filled by sceKernelWaitEqueue and throw on a null event. sceKernelGetEventError still throws NotImplemented. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -164,6 +164,16 @@ if(BUILD_TESTING)
|
||||
set_tests_properties(guest_kernel_errors PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
add_test_executable(guest_equeue_event_tests ${LIBS_INCLUDE_DIR}/tests/GuestEqueueEvents.cpp)
|
||||
target_include_directories(guest_equeue_event_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_equeue_event_tests PRIVATE libkernel libc)
|
||||
configure_windows_unwind(guest_equeue_event_tests)
|
||||
add_test(NAME guest_equeue_events COMMAND guest_equeue_event_tests)
|
||||
set_tests_properties(guest_equeue_events PROPERTIES TIMEOUT 20)
|
||||
if(WIN32)
|
||||
set_tests_properties(guest_equeue_events PROPERTIES ENVIRONMENT_MODIFICATION
|
||||
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libkernel>")
|
||||
endif()
|
||||
add_test_executable(guest_system_configuration_tests ${LIBS_INCLUDE_DIR}/tests/GuestSystemConfiguration.cpp)
|
||||
target_include_directories(guest_system_configuration_tests PRIVATE ${LIBS_INCLUDE_DIR})
|
||||
target_link_libraries(guest_system_configuration_tests PRIVATE libkernel libc)
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include "SceTypes.hpp"
|
||||
#include "prx/libc/include/General.hpp"
|
||||
|
||||
static const KernelEvent& requireEvent(const KernelEvent* ev, const char* caller) {
|
||||
if (ev == nullptr) {
|
||||
throw std::runtime_error(std::string(caller) + ": null event");
|
||||
}
|
||||
return *ev;
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
intptr_t APS5_VABI sceKernelGetEventData(const KernelEvent* ev) {
|
||||
(void)ev;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return requireEvent(ev, __func__).data;
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelGetEventError(const KernelEvent* ev) {
|
||||
@@ -18,27 +25,19 @@ int APS5_VABI sceKernelGetEventError(const KernelEvent* ev) {
|
||||
}
|
||||
|
||||
intptr_t APS5_VABI sceKernelGetEventFflags(const KernelEvent* ev) {
|
||||
(void)ev;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return static_cast<intptr_t>(requireEvent(ev, __func__).fflags);
|
||||
}
|
||||
|
||||
int APS5_VABI sceKernelGetEventFilter(const KernelEvent* ev) {
|
||||
(void)ev;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return requireEvent(ev, __func__).filter;
|
||||
}
|
||||
|
||||
uintptr_t APS5_VABI sceKernelGetEventId(const KernelEvent* ev) {
|
||||
(void)ev;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return 0;
|
||||
return requireEvent(ev, __func__).ident;
|
||||
}
|
||||
|
||||
void* APS5_VABI sceKernelGetEventUserData(const KernelEvent* ev) {
|
||||
(void)ev;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return nullptr;
|
||||
return requireEvent(ev, __func__).udata;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "SceTypes.hpp"
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
|
||||
extern "C" {
|
||||
int APS5_VABI sceKernelCreateEqueue(KernelEqueue* eq, const char* name);
|
||||
int APS5_VABI sceKernelDeleteEqueue(KernelEqueue eq);
|
||||
int APS5_VABI sceKernelWaitEqueue(KernelEqueue eq, KernelEvent* ev, int num, int* out, const KernelUseconds* timo);
|
||||
int APS5_VABI sceKernelAddUserEvent(KernelEqueue eq, int id);
|
||||
int APS5_VABI sceKernelTriggerUserEvent(KernelEqueue eq, int id, void* udata);
|
||||
int APS5_VABI sceKernelDeleteUserEvent(KernelEqueue eq, int id);
|
||||
int APS5_VABI sceKernelAddHRTimerEvent(KernelEqueue eq, int id, const KernelTimespec* ts, void* udata);
|
||||
intptr_t APS5_VABI sceKernelGetEventData(const KernelEvent* ev);
|
||||
intptr_t APS5_VABI sceKernelGetEventFflags(const KernelEvent* ev);
|
||||
int APS5_VABI sceKernelGetEventFilter(const KernelEvent* ev);
|
||||
uintptr_t APS5_VABI sceKernelGetEventId(const KernelEvent* ev);
|
||||
void* APS5_VABI sceKernelGetEventUserData(const KernelEvent* ev);
|
||||
}
|
||||
|
||||
static constexpr int SCE_OK = 0;
|
||||
static constexpr int EVFILT_USER = -11;
|
||||
static constexpr int EVFILT_HRTIMER = -15;
|
||||
|
||||
static void Require(bool value) { if (!value) std::abort(); }
|
||||
|
||||
template <typename TResult>
|
||||
static bool RejectsNull(TResult (APS5_VABI *accessor)(const KernelEvent*)) {
|
||||
try {
|
||||
accessor(nullptr);
|
||||
} catch (const std::runtime_error&) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
KernelEqueue eq = 0;
|
||||
Require(sceKernelCreateEqueue(&eq, "events") == SCE_OK);
|
||||
const KernelUseconds timeout = 1000000;
|
||||
int payload = 0;
|
||||
int count = 0;
|
||||
|
||||
KernelEvent userEvent{};
|
||||
Require(sceKernelAddUserEvent(eq, 7) == SCE_OK);
|
||||
Require(sceKernelTriggerUserEvent(eq, 7, &payload) == SCE_OK);
|
||||
Require(sceKernelWaitEqueue(eq, &userEvent, 1, &count, &timeout) == SCE_OK);
|
||||
Require(count == 1);
|
||||
Require(sceKernelGetEventId(&userEvent) == 7);
|
||||
Require(sceKernelGetEventFilter(&userEvent) == EVFILT_USER);
|
||||
Require(sceKernelGetEventData(&userEvent) == reinterpret_cast<intptr_t>(&payload));
|
||||
Require(sceKernelGetEventUserData(&userEvent) == &payload);
|
||||
Require(sceKernelGetEventFflags(&userEvent) == 0);
|
||||
Require(sceKernelDeleteUserEvent(eq, 7) == SCE_OK);
|
||||
|
||||
KernelEvent timerEvent{};
|
||||
const KernelTimespec delay{0, 1000000};
|
||||
Require(sceKernelAddHRTimerEvent(eq, 9, &delay, &payload) == SCE_OK);
|
||||
Require(sceKernelWaitEqueue(eq, &timerEvent, 1, &count, &timeout) == SCE_OK);
|
||||
Require(count == 1);
|
||||
Require(sceKernelGetEventId(&timerEvent) == 9);
|
||||
Require(sceKernelGetEventFilter(&timerEvent) == EVFILT_HRTIMER);
|
||||
Require(sceKernelGetEventUserData(&timerEvent) == &payload);
|
||||
Require(sceKernelDeleteEqueue(eq) == SCE_OK);
|
||||
|
||||
KernelEvent rawEvent{};
|
||||
rawEvent.ident = UINTPTR_MAX;
|
||||
rawEvent.filter = INT16_MIN;
|
||||
rawEvent.fflags = 0x80000001u;
|
||||
rawEvent.data = -5;
|
||||
Require(sceKernelGetEventId(&rawEvent) == UINTPTR_MAX);
|
||||
Require(sceKernelGetEventFilter(&rawEvent) == INT16_MIN);
|
||||
Require(sceKernelGetEventFflags(&rawEvent) == static_cast<intptr_t>(0x80000001LL));
|
||||
Require(sceKernelGetEventData(&rawEvent) == -5);
|
||||
Require(sceKernelGetEventUserData(&rawEvent) == nullptr);
|
||||
|
||||
Require(RejectsNull(sceKernelGetEventData));
|
||||
Require(RejectsNull(sceKernelGetEventFflags));
|
||||
Require(RejectsNull(sceKernelGetEventFilter));
|
||||
Require(RejectsNull(sceKernelGetEventId));
|
||||
Require(RejectsNull(sceKernelGetEventUserData));
|
||||
}
|
||||
Reference in New Issue
Block a user