From c152afb1cdce3a73e7b9b5df3b9f8935260fb1bc Mon Sep 17 00:00:00 2001 From: MajorP93 Date: Tue, 10 Dec 2024 14:36:27 +0100 Subject: [PATCH] Revert "semaphore: Use handles to properly handle semaphore double-delete. (#1728)" This reverts commit 41fd1c84cf51fbb8b3784e038c72d4bb37b8f406. --- .../libraries/kernel/threads/semaphore.cpp | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/core/libraries/kernel/threads/semaphore.cpp b/src/core/libraries/kernel/threads/semaphore.cpp index f25a76c2b0..39c1a0233d 100644 --- a/src/core/libraries/kernel/threads/semaphore.cpp +++ b/src/core/libraries/kernel/threads/semaphore.cpp @@ -9,7 +9,6 @@ #include "core/libraries/kernel/sync/semaphore.h" #include "common/logging/log.h" -#include "common/slot_vector.h" #include "core/libraries/kernel/kernel.h" #include "core/libraries/kernel/orbis_error.h" #include "core/libraries/kernel/posix_error.h" @@ -189,9 +188,7 @@ class OrbisSem { bool is_fifo; }; -using OrbisKernelSema = Common::SlotId; - -static Common::SlotVector> orbis_sems; +using OrbisKernelSema = OrbisSem*; s32 PS4_SYSV_ABI sceKernelCreateSema(OrbisKernelSema* sem, const char* pName, u32 attr, s32 initCount, s32 maxCount, const void* pOptParam) { @@ -199,48 +196,47 @@ s32 PS4_SYSV_ABI sceKernelCreateSema(OrbisKernelSema* sem, const char* pName, u3 LOG_ERROR(Lib_Kernel, "Semaphore creation parameters are invalid!"); return ORBIS_KERNEL_ERROR_EINVAL; } - *sem = orbis_sems.insert( - std::move(std::make_unique(initCount, maxCount, pName, attr == 1))); + *sem = new OrbisSem(initCount, maxCount, pName, attr == 1); return ORBIS_OK; } s32 PS4_SYSV_ABI sceKernelWaitSema(OrbisKernelSema sem, s32 needCount, u32* pTimeout) { - if (!orbis_sems.is_allocated(sem)) { + if (!sem) { return ORBIS_KERNEL_ERROR_ESRCH; } - return orbis_sems[sem]->Wait(true, needCount, pTimeout); + return sem->Wait(true, needCount, pTimeout); } s32 PS4_SYSV_ABI sceKernelSignalSema(OrbisKernelSema sem, s32 signalCount) { - if (!orbis_sems.is_allocated(sem)) { + if (!sem) { return ORBIS_KERNEL_ERROR_ESRCH; } - if (!orbis_sems[sem]->Signal(signalCount)) { + if (!sem->Signal(signalCount)) { return ORBIS_KERNEL_ERROR_EINVAL; } return ORBIS_OK; } s32 PS4_SYSV_ABI sceKernelPollSema(OrbisKernelSema sem, s32 needCount) { - if (!orbis_sems.is_allocated(sem)) { + if (!sem) { return ORBIS_KERNEL_ERROR_ESRCH; } - return orbis_sems[sem]->Wait(false, needCount, nullptr); + return sem->Wait(false, needCount, nullptr); } int PS4_SYSV_ABI sceKernelCancelSema(OrbisKernelSema sem, s32 setCount, s32* pNumWaitThreads) { - if (!orbis_sems.is_allocated(sem)) { + if (!sem) { return ORBIS_KERNEL_ERROR_ESRCH; } - return orbis_sems[sem]->Cancel(setCount, pNumWaitThreads); + return sem->Cancel(setCount, pNumWaitThreads); } int PS4_SYSV_ABI sceKernelDeleteSema(OrbisKernelSema sem) { - if (!orbis_sems.is_allocated(sem)) { + if (!sem) { return ORBIS_KERNEL_ERROR_ESRCH; } - orbis_sems[sem]->Delete(); - orbis_sems.erase(sem); + sem->Delete(); + delete sem; return ORBIS_OK; }