fix(savedata): accept a repeated sceSaveDataInitialize3

A second sceSaveDataInitialize3 returned SAVE_DATA_ERROR_ALREADY_INITIALIZED.
PPSA12544's executable and its Unity SaveData plugin both initialize, and
the plugin raises Unity.SaveData.PS5.Core.SaveDataException on any error,
so the console must accept the second call. Initializations are now
counted; sceSaveDataTerminate ends the session at the last one and only
then checks for mounted slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Merijn
2026-10-05 23:48:18 +02:00
parent 481c85e7c9
commit d1d98a8261
3 changed files with 11 additions and 11 deletions
+8 -11
View File
@@ -24,7 +24,7 @@
static constexpr char SAVE_DIR[] = "_sd";
static std::atomic<std::int32_t> 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<std::mutex> 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<std::mutex> 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;
}
@@ -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<bool>(file)); }
Require(sceSaveDataInitialize3(nullptr) == 0);
Require(sceSaveDataInitialize3(nullptr) == 0);
Require(sceSaveDataTerminate() == 0);
SaveDataParam param{};
SaveDataMemorySet2 set{};
set.user_id = 7531;
+1
View File
@@ -118,6 +118,7 @@ Throughout the project, every function at every stage either **does exactly what
- [sceSystemServiceDisableMediaPlay](../../core/libs/prx/libSceSystemService/Export.cpp) (libSceSystemService) - unknown signature
- [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
- [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
- [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`
- [libSceUlt queues](../../core/libs/prx/libSceUlt/Export.cpp) - the added `sceUltQueuePop`, `sceUltQueueTryPush`, `sceUltQueueDestroy` and `sceUltQueueDataResourcePoolDestroy` signatures are inferred from the existing push/pop and object APIs. Queue destruction is assumed to reject blocked callers with `ULT_ERROR_BUSY` and otherwise discard queued data; pool exhaustion returns `ULT_ERROR_AGAIN`. These rules, alignment checks and shared slot limits have not been confirmed on PS5 hardware or a title. Non-null queue and data-pool option parameters throw because their layouts are unknown.