2024-02-23 22:32:32 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2024-02-27 23:10:34 +01:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/logging/log.h"
|
2023-11-06 00:11:54 +01:00
|
|
|
#include "core/hle/error_codes.h"
|
2024-02-23 21:57:57 +01:00
|
|
|
#include "core/hle/kernel/event_queues.h"
|
2023-11-06 00:11:54 +01:00
|
|
|
|
|
|
|
namespace Core::Kernel {
|
2023-08-17 09:10:13 +02:00
|
|
|
|
|
|
|
int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name) {
|
|
|
|
if (eq == nullptr) {
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_ERROR(Kernel_Event, "Event queue is null!");
|
2023-08-17 09:10:13 +02:00
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
|
|
|
if (name == nullptr) {
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_ERROR(Kernel_Event, "Event queue name is invalid!");
|
2023-08-17 09:10:13 +02:00
|
|
|
return SCE_KERNEL_ERROR_EFAULT;
|
|
|
|
}
|
|
|
|
if (name == NULL) {
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_ERROR(Kernel_Event, "Event queue name is null!");
|
2023-08-17 09:10:13 +02:00
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
2023-08-17 09:11:50 +02:00
|
|
|
|
2024-02-27 23:10:34 +01:00
|
|
|
// Maximum is 32 including null terminator
|
|
|
|
static constexpr size_t MaxEventQueueNameSize = 32;
|
|
|
|
if (std::strlen(name) > MaxEventQueueNameSize) {
|
|
|
|
LOG_ERROR(Kernel_Event, "Event queue name exceeds 32 bytes!");
|
2023-08-17 09:10:13 +02:00
|
|
|
return SCE_KERNEL_ERROR_ENAMETOOLONG;
|
|
|
|
}
|
2024-02-27 23:10:34 +01:00
|
|
|
|
|
|
|
LOG_INFO(Kernel_Event, "name = {}", name);
|
|
|
|
|
2023-11-06 00:11:54 +01:00
|
|
|
*eq = new EqueueInternal;
|
2023-08-17 09:10:13 +02:00
|
|
|
(*eq)->setName(std::string(name));
|
|
|
|
return SCE_OK;
|
|
|
|
}
|
2023-09-08 07:28:01 +02:00
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, SceKernelEvent* ev, int num, int* out,
|
|
|
|
SceKernelUseconds* timo) {
|
2024-02-27 23:10:34 +01:00
|
|
|
LOG_INFO(Kernel_Event, "num = {}", num);
|
2023-09-08 07:28:01 +02:00
|
|
|
|
|
|
|
if (eq == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EBADF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ev == nullptr) {
|
|
|
|
return SCE_KERNEL_ERROR_EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num < 1) {
|
|
|
|
return SCE_KERNEL_ERROR_EINVAL;
|
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2024-02-23 21:57:57 +01:00
|
|
|
if (timo == nullptr) { // wait until an event arrives without timing out
|
2023-09-10 00:06:14 +02:00
|
|
|
*out = eq->waitForEvents(ev, num, 0);
|
2023-09-08 07:28:01 +02:00
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2023-09-08 07:28:01 +02:00
|
|
|
if (timo != nullptr) {
|
2023-11-06 00:11:54 +01:00
|
|
|
// Only events that have already arrived at the time of this function call can be received
|
|
|
|
if (*timo == 0) {
|
2024-02-27 23:10:34 +01:00
|
|
|
UNREACHABLE();
|
2023-11-06 00:11:54 +01:00
|
|
|
} else {
|
|
|
|
// Wait until an event arrives with timing out
|
2024-02-27 23:10:34 +01:00
|
|
|
UNREACHABLE();
|
2023-09-08 07:28:01 +02:00
|
|
|
}
|
|
|
|
}
|
2023-11-06 00:11:54 +01:00
|
|
|
|
2023-09-08 07:28:01 +02:00
|
|
|
return SCE_OK;
|
|
|
|
}
|
|
|
|
|
2023-11-06 00:11:54 +01:00
|
|
|
} // namespace Core::Kernel
|