Files
RTGG 81a0b9b8af fix(libSceCommonDialog): require system initialization before acquiring common dialog
CommonDialogAcquire_nid_no_patch only checked g_used atomics and permitted acquiring the shared common dialog lock before sceCommonDialogInitialize had been called to initialize the subsystem. Any dialog library calling Acquire before Initialize would silently mark the system as used. Add a g_initialized guard that returns false when the system has not been initialized.

Add a regression test verifying that CommonDialogAcquire_nid_no_patch returns false and leaves sceCommonDialogIsUsed false prior to sceCommonDialogInitialize.
2026-11-16 18:03:00 +01:00

42 lines
1.0 KiB
C++

#include "prx/libSceCommonDialog/include/Api.hpp"
#include "prx/libSceCommonDialog/include/DialogUse.hpp"
#include <atomic>
#include <cstdint>
#include <cstddef>
#include "SceTypes.hpp"
#include "prx/libSceCommonDialog/CommonDialog.hpp"
#include "prx/libc/include/General.hpp"
static std::atomic<bool> g_initialized{false};
static std::atomic<bool> g_used{false};
extern "C" {
int APS5_VABI sceCommonDialogInitialize(void) {
bool expected = false;
if (!g_initialized.compare_exchange_strong(expected, true)) {
return COMMON_DIALOG_ERROR_ALREADY_SYSTEM_INITIALIZED;
}
return COMMON_DIALOG_OK;
}
bool APS5_VABI sceCommonDialogIsUsed(void) {
return g_used.load();
}
bool CommonDialogSystemInitialized_nid_no_patch() {
return g_initialized.load();
}
bool CommonDialogAcquire_nid_no_patch() {
if (!g_initialized.load()) return false;
bool expected = false;
return g_used.compare_exchange_strong(expected, true);
}
void CommonDialogRelease_nid_no_patch() {
g_used.store(false);
}
}