diff --git a/core/libs/prx/libSceSaveData.native/Export.cpp b/core/libs/prx/libSceSaveData.native/Export.cpp index f0b798f5d..aba825cf2 100644 --- a/core/libs/prx/libSceSaveData.native/Export.cpp +++ b/core/libs/prx/libSceSaveData.native/Export.cpp @@ -24,7 +24,7 @@ static constexpr char SAVE_DIR[] = "_sd"; static std::atomic g_transaction_counter{1}; -static bool g_initialized = false; +static int g_initializations = 0; static std::string save_root() { return std::string(SAVE_DIR); @@ -351,7 +351,7 @@ static int getSaveDataMemory2(SaveDataMemoryGet2* get_param) { if (get_param == nullptr) { return SAVE_DATA_ERROR_PARAMETER; } - if (!g_initialized) { + if (g_initializations == 0) { return SAVE_DATA_ERROR_NOT_INITIALIZED; } std::lock_guard lk(g_mem_mutex); @@ -393,10 +393,7 @@ int APS5_VABI sceSaveDataGetSaveDataMemory2(SaveDataMemoryGet2* get_param) { int APS5_VABI sceSaveDataInitialize3(const void* init) { (void)init; - if (g_initialized) { - return SAVE_DATA_ERROR_ALREADY_INITIALIZED; - } - g_initialized = true; + ++g_initializations; return SAVE_DATA_OK; } @@ -536,7 +533,7 @@ static int setSaveDataMemory2(const SaveDataMemorySet2* set_param) { if (set_param == nullptr) { return SAVE_DATA_ERROR_PARAMETER; } - if (!g_initialized) { + if (g_initializations == 0) { return SAVE_DATA_ERROR_NOT_INITIALIZED; } std::lock_guard lk(g_mem_mutex); @@ -594,7 +591,7 @@ static int setupSaveDataMemory2(const SaveDataMemorySetup2* setup_param, SaveDat if (setup_param == nullptr) { return SAVE_DATA_ERROR_PARAMETER; } - if (!g_initialized) { + if (g_initializations == 0) { return SAVE_DATA_ERROR_NOT_INITIALIZED; } if (setup_param->memory_size == 0 || setup_param->memory_size > MEM_MAX_SIZE) { @@ -654,13 +651,13 @@ int APS5_VABI sceSaveDataSyncSaveDataMemory(const void* sync_param) { } int APS5_VABI sceSaveDataTerminate(void) { - if (!g_initialized) { + if (g_initializations == 0) { return SAVE_DATA_ERROR_NOT_INITIALIZED; } - if (any_slot_used()) { + if (g_initializations == 1 && any_slot_used()) { return SAVE_DATA_ERROR_BUSY; } - g_initialized = false; + --g_initializations; return SAVE_DATA_OK; } diff --git a/core/libs/tests/SaveDataMemoryMetadata.cpp b/core/libs/tests/SaveDataMemoryMetadata.cpp index e3b960ee9..5c75de021 100644 --- a/core/libs/tests/SaveDataMemoryMetadata.cpp +++ b/core/libs/tests/SaveDataMemoryMetadata.cpp @@ -34,6 +34,8 @@ int main() { std::filesystem::create_directories(path.parent_path()); { std::ofstream file("_sd_mem/u7531/slot0.bin"); file << "save"; Require(static_cast(file)); } Require(sceSaveDataInitialize3(nullptr) == 0); + Require(sceSaveDataInitialize3(nullptr) == 0); + Require(sceSaveDataTerminate() == 0); SaveDataParam param{}; SaveDataMemorySet2 set{}; set.user_id = 7531; diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index 417838353..686e64571 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -123,6 +123,7 @@ Throughout the project, every function at every stage either **does exactly what - [sceSystemServiceReenableMediaPlay](../../core/libs/prx/libSceSystemService/Export.cpp) (libSceSystemService) - unknown signature - [sceSystemServiceParamGetString](../../core/libs/prx/libSceSystemService/Export.cpp) (libSceSystemService) - the system name (parameter 6) is the fixed `PS5`, not the console's name; other parameters and buffers of 1 to 64 bytes throw - [sceNgs2SystemSetSampleRate, sceNgs2SystemSetUserData, sceNgs2SystemGetUserData, sceNgs2SystemLock, sceNgs2SystemUnlock](../../core/libs/prx/libSceNgs2.native/src/System.cpp) (libSceNgs2.native) - shadPS4 only checks the system handle (`INVALID_SYSTEM_HANDLE`) and SharpProspero names what each call does; neither gives the other limits. A sample rate of 0 and a null user data pointer throw, any other rate is accepted, and changing the rate while a sampler filter is enabled throws because the filter coefficients were computed for the old rate. Lock and unlock take the same lock as `sceNgs2RackLock` +- [sceSaveDataInitialize3](../../core/libs/prx/libSceSaveData.native/Export.cpp) (libSceSaveData.native) - a repeated initialize succeeds: PPSA12544's executable and its Unity SaveData plugin both initialize, and the plugin fails on any error. Initializations are counted and `sceSaveDataTerminate` ends the session at the last one; how the console pairs them is unknown - [sceVoiceSetMuteFlag](../../core/libs/prx/libSceVoice/Export.cpp) (libSceVoice) - unknown signature - [sceRtcFormatRFC2822, sceRtcFormatRFC2822LocalTime, sceRtcFormatRFC3339LocalTime](../../core/libs/prx/libSceRtc/Export.cpp) (libSceRtc) - only shadPS4 (PS4) has bodies. A null tick returns `INVALID_POINTER` like the existing `sceRtcFormatRFC3339`, where shadPS4 formats the current time instead; offsets outside ±1439 minutes return `INVALID_VALUE` like `sceRtcFormatRFC3339`; the local-time variants use the host's offset at the given instant (shadPS4 uses `sceKernelGettimezone`, the current offset) - [snwprintf_s](../../core/libs/prx/libc/src/FormattingWide.cpp) (libc) - follows C11 K.3.9.1.3 with `RSIZE_MAX` assumed to be `SIZE_MAX >> 1`. A runtime-constraint violation only returns a negative value: `set_constraint_handler_s` is not exported and the console's default handler is unknown. An invalid multibyte `%s` argument is copied byte by byte instead of being reported as an encoding error, as in `vswprintf`