feat(libSceSaveData): deliver backup completions to a registered event callback #13551

Merged
EagleBearerYS merged 21 commits from upstream-pr/13551 into main 2026-11-02 22:35:49 +00:00
EagleBearerYS commented 2026-10-30 18:03:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-30T18:03:50Z.


What

sceSaveDataRegisterEventCallback and sceSaveDataUnregisterEventCallback were parameterless declarations that threw through NotImplemented_nid_no_patch. They now take shadPS4's signatures and follow its #5226 ("save_data: deliver backup completion callbacks"), as on its main 1d8004a22f. That covers registration, unregistration, and delivering each backup completion to the registered callback from a thread the library starts.

This PR is stacked on #12748, which adds the type-1 event of sceSaveDataUmountWithBackup.

export shadPS4 lines what it does
sceSaveDataRegisterEventCallback savedata.cpp L1345-L1358 Before initialization: SAVE_DATA_ERROR_NOT_INITIALIZED. A null callback: SAVE_DATA_ERROR_PARAMETER. Otherwise it stores the callback and userdata. A second registration replaces both.
sceSaveDataUnregisterEventCallback savedata.cpp L1763-L1768 No initialization check. It clears both.
  • Delivery, as in DispatchBackupEvent (L315-L339) and the backup thread (save_backup.cpp L140-L205).

    • What is delivered: every backup completion that queues an event for sceSaveDataGetEventResult also delivers the same event to the callback registered at that point. That's type 2 from sceSaveDataBackup and type 1 from #12748's sceSaveDataUmountWithBackup.
    • The order: the polled event is queued first and then delivered, as in shadPS4. The polling queue itself is unchanged.
    • Not delivered: sceSaveDataConvert's type-5 event isn't a backup completion, and shadPS4 doesn't deliver it either.
  • The thread: shadPS4 runs the callback on an emulated kernel thread, so that it has a guest TLS and stack (L82).

    • Here the library starts a guest thread with scePthreadCreate at the first successful sceSaveDataRegisterEventCallback of an initialization, as libSceUsbStorage does for its monitor callbacks. A title that never registers gets no thread, and sceSaveDataInitialize3 only counts, as on main.
    • The thread waits on a condition variable. The last terminate wakes it and joins it outside the library's lock, if one was started.
  • Registration against the last terminate: Register takes callbacks.calling, then g_slots_mutex, before it checks the initialization count and stores the callback. The last terminate holds g_slots_mutex from its check through the detach. So a registration racing the last terminate either completes first and is cleared by it, or gets NOT_INITIALIZED. Callback reentrancy is kept, and the join stays outside the lock.

  • Terminate:

    • From inside the callback: SAVE_DATA_ERROR_BUSY, before any other check, as in shadPS4's sceSaveDataTerminate (L1704-L1726). It never joins the delivery thread from that thread.
    • The last terminate drops the registration and the queued deliveries, as shadPS4's terminate unregisters.
  • Unregister also drops completions not yet delivered, so no callback runs after it returns.

  • Not measured on a console. The debt entry lists what is unknown there:

    • the delivering thread, its priority and when it runs relative to the call;
    • whether unregistering drops undelivered completions;
    • what a terminate from the callback returns.

    It also says PS5's signatures are assumed to be PS4's.

Tested

  • guest_savedata_event_callback (new) runs in its own process. Every wait is bounded at 5 s on a condition variable, with no sleeps.
    • Registration:
      • Register before sceSaveDataInitialize3 gives NOT_INITIALIZED;
      • Unregister before it gives 0;
      • a null callback gives PARAMETER.
    • sceSaveDataBackup: the callback gets exactly one event:
      • type 2, error 0, with the user, title and directory of the backup, and the registered userdata;
      • on a thread other than the caller's;
      • identical to the polled event. A second poll gives NOT_FOUND.
    • sceSaveDataUmountWithBackup: exactly one type-1 event, with the same checks.
    • Unregister: register A, unregister, back up, register B, back up again. A gets nothing, and B gets exactly the second event.
    • Replacement: a second registration's callback and userdata receive the next event.
    • Terminate:
      • from inside the callback it returns BUSY;
      • with the thread idle it returns 0, and Register then gives NOT_INITIALIZED;
      • both run under a 10 s watchdog.
    • Restart: initializing again delivers nothing until a callback is registered, then exactly once.
  • Red, with the two bodies put back to NotImplemented_nid_no_patch and the rest of this change kept (run): guest_savedata_event_callback fails on both runners, aborting at its first case with "sceSaveDataRegisterEventCallback not implemented".
    • Linux: 8 guest_savedata* tests, 1 failed, 0 skipped.
    • Windows: 8 tests, 1 failed, 0 skipped.
  • Green, ×10 on both runners (run):
    • Linux and Windows: 8 guest_savedata* tests each, all 10 runs passed, 0 skipped.
    • Suites: libc and libkernel pass: 197 and 294 tests on Linux, 224 and 318 on Windows.
  • Linux (Ubuntu 24.04, GCC 13.3, Release, CI's flags, as an unprivileged user):
    • the new test --repeat until-fail:20: 20 of 20 passed;
    • ctest -R 'savedata|save_data' once: 14 tests, 14 passed. At 629477b800 every guest_savedata* test started and stopped the delivery thread with its initializations; since 0d0abe09c1 only a registration starts it.
  • Checks:
    • check_test_registration.py passes. check_conventions.py passes with one warning, [debt-length] on the pending-declarations line, which #12748 already has at a longer length (5,607 characters there, 5,415 here).
    • MinGW-w64 -fsyntax-only: no new diagnostic.
    • No comment lines added.
  • bc6b4d76f9, the registration race (MarcZX10's review, oneandonlydean's point 2):
    • CheckRegisterRacingFinalTerminate: 200 iterations of a registration against the final terminate on two guest threads.
      • In the 100 held iterations, a callback keeps the delivery thread inside calling, so the registration waits there while the last terminate runs. The other 100 are a plain race.
      • Each iteration then initializes again and backs up behind a Fence callback, and asserts that the raced callback ran 0 times.
    • Red, on Linux: 629477b800's code with only the new test fails 20 of 20 runs, at the first held iteration: "the callback whose registration returned 0 beside the final terminate is called after Initialize3, 1 time(s)".
    • Green: --repeat until-fail:50 on Linux, and ×10 on GitHub's runners (run): 13 guest_savedata* tests each on Linux and Windows, all passing, 0 skipped.
  • 0d0abe09c1, the delivery thread at the first registration (oneandonlydean's point 1):
    • CheckSessionsWithoutRegistration: two initialize/terminate sessions with no registration, each call returning 0.
    • CheckDeliveryThreadStartsAtRegistration: it counts the process's threads in /proc/self/task, as GuestPthreadStack.cpp does. Initialize3 and a refused registration add none, the first registration adds one, later ones reuse it, and the final terminate joins it.
      • It runs on Linux only: on Windows, thread counts include loader and thread-pool threads that come and go on their own.
      • No test hook was added to the library.
    • Red: on bc6b4d76f9's code the new cases fail 10 of 10 runs, since the thread count there is 2 where the change gives 1.
    • Green, ×10 on GitHub's runners at this head (run):
      • 13 guest_savedata* tests each on Linux and Windows, all passing, 0 skipped.
      • The libc and libkernel suites pass: 197 and 294 tests on Linux, 224 and 318 on Windows. The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • 36b5e96eb1, a merge of #12748's 842f75d7e0, which brings #12748's merge of main 7fcab08f71 and with it JJenkx's #13324 (run).
    • What it carries: #12748's two isMountedDirectory calls, in Check and Restore, take #13324's new std::error_code parameter and return SAVE_DATA_ERROR_INTERNAL on a host filesystem error instead of throwing, consistent with #13324. CheckBackups now writes param.json at the resolved /app0 path, since #13324's test fixes the guest root in a subdirectory first.
    • This PR's own diff changes only at those two calls and those three test lines. The merge itself is clean.
    • ×10: ^guest_savedata_ and ^savedata_ with guest_savedata_event_callback, guest_savedata_mount_status among them.
      • Linux: 14 run, 14 pass, 0 skip, 0 fail.
      • Windows: 15 run, 15 pass, 0 skip, 0 fail.
      • The libc and libkernel suites run 199 and 307 tests on Linux and 226 and 329 on Windows, with 0 failed. The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.

Claim check (rerun 2026-10-30 17:49-17:53Z):

  • No open pull request, and none closed since 10-15, implements either export.
  • The SaveData PRs updated since (#13324, #13218), and the open ones before them (#12625, #13027, #8285, #8630, #10674), keep both as throwing declarations.
  • fable-void's fork has them as stubs.

Overlap: git merge-tree of this head:

  • with main, clean;
  • with #13027, clean;
  • with #12625, #10674, #8285 and #8630, one hunk each. #12748's own head has exactly the same hunks with them, so this commit adds no conflict.
  • 62ab6243cb, a merge of #12748's 9b9e850d90, oneandonlydean's merge of main d8b60b46ed into #12748. It brings #12748's resolution of the one conflict with main: in libSceSaveData.native/Export.cpp's include block, #8285's <string_view> sits beside this branch's includes, and both are kept. It merged without conflicts, and this PR's own diff is unchanged.
    • ×10 (run, on 6f4d3813e5, which has the same tree): the nine guest_savedata_* tests, guest_savedata_event_callback among them. Linux: 9 run, 9 pass, 0 skip, 0 fail. Windows: 9 run, 9 pass, 0 skip, 0 fail. The libc and libkernel suites run 208 and 309 tests on Linux and 235 and 330 on Windows, with 0 failed. The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • df0b6d335c, a merge of main 3c3b3cda73 (run). The one conflict was the pending-declarations list in docs/dev/debt/libSceSaveData.native.md: MarcZX10's #10674 moves sceSaveDataGetProgress out of it into its own entry, and the merge keeps that with this branch's removal of the five calls it and #12748 implement. This PR's diff over #12748 is unchanged. The ^guest_save tests, with guest_savedata_event_callback and guest_savedata_mount_status, pass 10 runs in a row. Linux: 9 run, 9 pass, 0 skip, 0 fail. Windows: 9 run, 9 pass, 0 skip, 0 fail. Suites: libc and libkernel pass on Linux (214 and 316) and on Windows (241 and 337). The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.
  • 4de3c5975a, a merge of #12748's 02af078a35, oneandonlydean's merge of main b28bb77217 into #12748 (run). The one conflict was the pending-declarations list in docs/dev/debt/libSceSaveData.native.md, next to main's sceSaveDataGetProgress entry, which xecedemon's #15077 extends. The merge keeps that entry with this branch's removal of the five calls it and #12748 implement. This PR's diff over #12748 is unchanged. The ^guest_save tests, with guest_savedata_event_callback and guest_savedata_mount_status, pass 10 runs in a row. Linux: 9 run, 9 pass, 0 skip, 0 fail. Windows: 9 run, 9 pass, 0 skip, 0 fail. Suites: libc and libkernel pass on Linux (217 and 319) and on Windows (244 and 340). The suites ran with APS5_SKIP_TIMING_TESTS=1, which relaxes precise_wait's median bounds on GitHub's hosted runners.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #12748. Any order with fogydes's #15042, for merge order only, which copies the guest parameters in before reading them. Besides #12748's hunk in convert (see #12748), it conflicts in sceSaveDataBackup, where this PR builds the backup event and calls DeliverEvent after the scoped g_state_mutex lock. Whichever lands second keeps #15042's copied-in title_id and directory name, with this PR's scoped lock and the DeliverEvent call after it.
  • Fixes: none
  • Unblocks: none
  • GPUs tested: none needed (no GPU code)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5088877991 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13551). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-30T18:03:50Z. --- ### What `sceSaveDataRegisterEventCallback` and `sceSaveDataUnregisterEventCallback` were parameterless declarations that threw through `NotImplemented_nid_no_patch`. They now take shadPS4's signatures and follow its [#5226](https://github.com/shadps4-emu/shadPS4/pull/5226) ("save_data: deliver backup completion callbacks"), as on its `main` [1d8004a22f](https://github.com/shadps4-emu/shadPS4/tree/1d8004a22feb). That covers registration, unregistration, and delivering each backup completion to the registered callback from a thread the library starts. This PR is stacked on #12748, which adds the type-1 event of `sceSaveDataUmountWithBackup`. | export | shadPS4 lines | what it does | |---|---|---| | `sceSaveDataRegisterEventCallback` | `savedata.cpp` [L1345-L1358](https://github.com/shadps4-emu/shadPS4/blob/1d8004a22feb/src/core/libraries/save_data/savedata.cpp#L1345-L1358) | Before initialization: `SAVE_DATA_ERROR_NOT_INITIALIZED`. A null callback: `SAVE_DATA_ERROR_PARAMETER`. Otherwise it stores the callback and userdata. A second registration replaces both. | | `sceSaveDataUnregisterEventCallback` | `savedata.cpp` [L1763-L1768](https://github.com/shadps4-emu/shadPS4/blob/1d8004a22feb/src/core/libraries/save_data/savedata.cpp#L1763-L1768) | No initialization check. It clears both. | - **Delivery,** as in `DispatchBackupEvent` ([L315-L339](https://github.com/shadps4-emu/shadPS4/blob/1d8004a22feb/src/core/libraries/save_data/savedata.cpp#L315-L339)) and the backup thread ([`save_backup.cpp` L140-L205](https://github.com/shadps4-emu/shadPS4/blob/1d8004a22feb/src/core/libraries/save_data/save_backup.cpp#L140-L205)). - **What is delivered:** every backup completion that queues an event for `sceSaveDataGetEventResult` also delivers the same event to the callback registered at that point. That's type 2 from `sceSaveDataBackup` and type 1 from #12748's `sceSaveDataUmountWithBackup`. - **The order:** the polled event is queued first and then delivered, as in shadPS4. The polling queue itself is unchanged. - **Not delivered:** `sceSaveDataConvert`'s type-5 event isn't a backup completion, and shadPS4 doesn't deliver it either. - **The thread:** shadPS4 runs the callback on an emulated kernel thread, so that it has a guest TLS and stack ([L82](https://github.com/shadps4-emu/shadPS4/blob/1d8004a22feb/src/core/libraries/save_data/save_backup.cpp#L82)). - Here the library starts a guest thread with `scePthreadCreate` at the first successful `sceSaveDataRegisterEventCallback` of an initialization, as `libSceUsbStorage` does for its monitor callbacks. A title that never registers gets no thread, and `sceSaveDataInitialize3` only counts, as on `main`. - The thread waits on a condition variable. The last terminate wakes it and joins it outside the library's lock, if one was started. - **Registration against the last terminate:** Register takes `callbacks.calling`, then `g_slots_mutex`, before it checks the initialization count and stores the callback. The last terminate holds `g_slots_mutex` from its check through the detach. So a registration racing the last terminate either completes first and is cleared by it, or gets `NOT_INITIALIZED`. Callback reentrancy is kept, and the join stays outside the lock. - **Terminate:** - **From inside the callback:** `SAVE_DATA_ERROR_BUSY`, before any other check, as in shadPS4's `sceSaveDataTerminate` ([L1704-L1726](https://github.com/shadps4-emu/shadPS4/blob/1d8004a22feb/src/core/libraries/save_data/savedata.cpp#L1704-L1726)). It never joins the delivery thread from that thread. - **The last terminate** drops the registration and the queued deliveries, as shadPS4's terminate unregisters. - **Unregister** also drops completions not yet delivered, so no callback runs after it returns. - **Not measured on a console.** The debt entry lists what is unknown there: - the delivering thread, its priority and when it runs relative to the call; - whether unregistering drops undelivered completions; - what a terminate from the callback returns. It also says PS5's signatures are assumed to be PS4's. ### Tested - **`guest_savedata_event_callback` (new)** runs in its own process. Every wait is bounded at 5 s on a condition variable, with no sleeps. - **Registration:** - Register before `sceSaveDataInitialize3` gives `NOT_INITIALIZED`; - Unregister before it gives 0; - a null callback gives `PARAMETER`. - **`sceSaveDataBackup`:** the callback gets exactly one event: - type 2, error 0, with the user, title and directory of the backup, and the registered userdata; - on a thread other than the caller's; - identical to the polled event. A second poll gives `NOT_FOUND`. - **`sceSaveDataUmountWithBackup`:** exactly one type-1 event, with the same checks. - **Unregister:** register A, unregister, back up, register B, back up again. A gets nothing, and B gets exactly the second event. - **Replacement:** a second registration's callback and userdata receive the next event. - **Terminate:** - from inside the callback it returns `BUSY`; - with the thread idle it returns 0, and Register then gives `NOT_INITIALIZED`; - both run under a 10 s watchdog. - **Restart:** initializing again delivers nothing until a callback is registered, then exactly once. - **Red,** with the two bodies put back to `NotImplemented_nid_no_patch` and the rest of this change kept ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41049288057)): `guest_savedata_event_callback` fails on both runners, aborting at its first case with "sceSaveDataRegisterEventCallback not implemented". - **Linux:** 8 `guest_savedata*` tests, 1 failed, 0 skipped. - **Windows:** 8 tests, 1 failed, 0 skipped. - **Green, ×10 on both runners** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41049487645)): - **Linux and Windows:** 8 `guest_savedata*` tests each, all 10 runs passed, 0 skipped. - **Suites:** libc and libkernel pass: 197 and 294 tests on Linux, 224 and 318 on Windows. - **Linux** (Ubuntu 24.04, GCC 13.3, Release, CI's flags, as an unprivileged user): - the new test `--repeat until-fail:20`: 20 of 20 passed; - `ctest -R 'savedata|save_data'` once: 14 tests, 14 passed. At 629477b800 every `guest_savedata*` test started and stopped the delivery thread with its initializations; since `0d0abe09c1` only a registration starts it. - **Checks:** - `check_test_registration.py` passes. `check_conventions.py` passes with one warning, `[debt-length]` on the pending-declarations line, which #12748 already has at a longer length (5,607 characters there, 5,415 here). - MinGW-w64 `-fsyntax-only`: no new diagnostic. - No comment lines added. - **`bc6b4d76f9`, the registration race** ([MarcZX10's review](https://github.com/boykopovar/AnyPS5/pull/13551#pullrequestreview-5716776526), [oneandonlydean's point 2](https://github.com/boykopovar/AnyPS5/pull/13551#issuecomment-6531738605)): - **`CheckRegisterRacingFinalTerminate`:** 200 iterations of a registration against the final terminate on two guest threads. - In the 100 held iterations, a callback keeps the delivery thread inside `calling`, so the registration waits there while the last terminate runs. The other 100 are a plain race. - Each iteration then initializes again and backs up behind a `Fence` callback, and asserts that the raced callback ran 0 times. - **Red,** on Linux: 629477b800's code with only the new test fails 20 of 20 runs, at the first held iteration: "the callback whose registration returned 0 beside the final terminate is called after Initialize3, 1 time(s)". - **Green:** `--repeat until-fail:50` on Linux, and ×10 on GitHub's runners ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41112754487)): 13 `guest_savedata*` tests each on Linux and Windows, all passing, 0 skipped. - **`0d0abe09c1`, the delivery thread at the first registration** ([oneandonlydean's point 1](https://github.com/boykopovar/AnyPS5/pull/13551#issuecomment-6531738605)): - **`CheckSessionsWithoutRegistration`:** two initialize/terminate sessions with no registration, each call returning 0. - **`CheckDeliveryThreadStartsAtRegistration`:** it counts the process's threads in `/proc/self/task`, as `GuestPthreadStack.cpp` does. Initialize3 and a refused registration add none, the first registration adds one, later ones reuse it, and the final terminate joins it. - It runs on Linux only: on Windows, thread counts include loader and thread-pool threads that come and go on their own. - No test hook was added to the library. - **Red:** on `bc6b4d76f9`'s code the new cases fail 10 of 10 runs, since the thread count there is 2 where the change gives 1. - **Green, ×10 on GitHub's runners at this head** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41121043549)): - 13 `guest_savedata*` tests each on Linux and Windows, all passing, 0 skipped. - The libc and libkernel suites pass: 197 and 294 tests on Linux, 224 and 318 on Windows. The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **36b5e96eb1, a merge of #12748's 842f75d7e0**, which brings #12748's merge of `main` 7fcab08f71 and with it JJenkx's #13324 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41142779552)). - **What it carries:** #12748's two `isMountedDirectory` calls, in Check and Restore, take #13324's new `std::error_code` parameter and return `SAVE_DATA_ERROR_INTERNAL` on a host filesystem error instead of throwing, consistent with #13324. `CheckBackups` now writes param.json at the resolved `/app0` path, since #13324's test fixes the guest root in a subdirectory first. - **This PR's own diff** changes only at those two calls and those three test lines. The merge itself is clean. - **×10:** `^guest_savedata_` and `^savedata_` with `guest_savedata_event_callback`, `guest_savedata_mount_status` among them. - Linux: 14 run, 14 pass, 0 skip, 0 fail. - Windows: 15 run, 15 pass, 0 skip, 0 fail. - The libc and libkernel suites run 199 and 307 tests on Linux and 226 and 329 on Windows, with 0 failed. The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. **Claim check** (rerun 2026-10-30 17:49-17:53Z): - No open pull request, and none closed since 10-15, implements either export. - The SaveData PRs updated since (#13324, #13218), and the open ones before them (#12625, #13027, #8285, #8630, #10674), keep both as throwing declarations. - fable-void's fork has them as stubs. **Overlap:** `git merge-tree` of this head: - with `main`, clean; - with #13027, clean; - with #12625, #10674, #8285 and #8630, one hunk each. #12748's own head has exactly the same hunks with them, so this commit adds no conflict. - **62ab6243cb, a merge of #12748's 9b9e850d90**, oneandonlydean's merge of `main` d8b60b46ed into #12748. It brings #12748's resolution of the one conflict with `main`: in `libSceSaveData.native/Export.cpp`'s include block, #8285's `<string_view>` sits beside this branch's includes, and both are kept. It merged without conflicts, and this PR's own diff is unchanged. - **×10** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41316872808), on 6f4d3813e5, which has the same tree): the nine `guest_savedata_*` tests, `guest_savedata_event_callback` among them. Linux: 9 run, 9 pass, 0 skip, 0 fail. Windows: 9 run, 9 pass, 0 skip, 0 fail. The libc and libkernel suites run 208 and 309 tests on Linux and 235 and 330 on Windows, with 0 failed. The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **df0b6d335c, a merge of `main` 3c3b3cda73** ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41434161092)). The one conflict was the pending-declarations list in `docs/dev/debt/libSceSaveData.native.md`: MarcZX10's #10674 moves `sceSaveDataGetProgress` out of it into its own entry, and the merge keeps that with this branch's removal of the five calls it and #12748 implement. This PR's diff over #12748 is unchanged. The `^guest_save` tests, with `guest_savedata_event_callback` and `guest_savedata_mount_status`, pass 10 runs in a row. Linux: 9 run, 9 pass, 0 skip, 0 fail. Windows: 9 run, 9 pass, 0 skip, 0 fail. Suites: libc and libkernel pass on Linux (214 and 316) and on Windows (241 and 337). The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. - **4de3c5975a, a merge of #12748's 02af078a35**, oneandonlydean's merge of `main` b28bb77217 into #12748 ([run](https://github.com/EagleBearerYS/AnyPS5/actions/runs/41482579712)). The one conflict was the pending-declarations list in `docs/dev/debt/libSceSaveData.native.md`, next to `main`'s `sceSaveDataGetProgress` entry, which xecedemon's #15077 extends. The merge keeps that entry with this branch's removal of the five calls it and #12748 implement. This PR's diff over #12748 is unchanged. The `^guest_save` tests, with `guest_savedata_event_callback` and `guest_savedata_mount_status`, pass 10 runs in a row. Linux: 9 run, 9 pass, 0 skip, 0 fail. Windows: 9 run, 9 pass, 0 skip, 0 fail. Suites: libc and libkernel pass on Linux (217 and 319) and on Windows (244 and 340). The suites ran with `APS5_SKIP_TIMING_TESTS=1`, which relaxes `precise_wait`'s median bounds on GitHub's hosted runners. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #12748. Any order with fogydes's #15042, for merge order only, which copies the guest parameters in before reading them. Besides #12748's hunk in `convert` (see #12748), it conflicts in `sceSaveDataBackup`, where this PR builds the backup event and calls `DeliverEvent` after the scoped `g_state_mutex` lock. Whichever lands second keeps #15042's copied-in `title_id` and directory name, with this PR's scoped lock and the `DeliverEvent` call after it. - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: none needed (no GPU code) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-30 18:19:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T18:19:25Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The event callback registration can race with final termination, leaving a callback registered after shutdown and allowing it to be reused after reinitialization without a new registration.

What I ran

Reviewed head 629477b800f75f29aac25fb104616d189e8a265b against PR base 4bc9e779aa7abb2109c65ee3bca19e1b85df3be8; the individual merge preview against that base was clean. The declared order-only dependency chain is #10674 → #12748 → #13551; #12748 and #13551 preview cleanly against current main, while #10674 currently conflicts with it. Environment: Linux x86-64, Python 3.11.2, GCC 12.2.0.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13551
python3 tools/pr_stack_check.py 13551 --repo boykopovar/AnyPS5 --output-dir /tmp/stack-13551-new
git diff --check 4bc9e779aa7abb2109c65ee3bca19e1b85df3be8...629477b800f75f29aac25fb104616d189e8a265b
git diff --check refs/pr/12748...refs/review/13551
python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base refs/review/main-latest --head refs/review/13551 --json
python3 tools/pr_test_quality.py --root /tmp/anyps5-13551-head.0eti4f --json core/libs/tests/GuestSaveDataEventCallback.cpp core/libs/tests/GuestSaveDataMountStatus.cpp
gh pr view 13551 --repo boykopovar/AnyPS5

Results

Check Result
Diff and conventions Precheck passed diff and convention checks; it reported the repository's existing long technical-debt-line warning. Both direct diff checks exited 0 with no output.
Dependency/mergeability #13551 and #12748 preview cleanly against current main; #10674 has a conflict and is declared order-only by #12748. The precheck could not invoke its isolated stack helper, so I reran the stack check directly.
Export ABI lexical audit passed_with_warnings: 15 heuristic findings. Seven refer to save-data exports from the current base absent from the PR branch tree, but the merge preview is clean; one is the new internal worker function in an anonymous namespace. The audit is not a C++ parser or binary ABI test.
Test-quality heuristic Two possible-unregistered-cpp-test warnings are false positives: CMake explicitly builds both files and registers CTest entries.
Hosted CI At refresh, eligibility, conventions, portability, intake, labels, and report were queued. The PR description reports prior repeated Linux/Windows runs, but I did not reproduce them for this head.
Local build/tests Not run; the initial review is no-build, and no exact-head test binary was available.
Unedited output from focused checks

The convention check emitted this warning and exit summary:

docs/dev/debt/libSceSaveData.native.md:21: warning: [debt-length] Technical debt entry over 1000 characters: state the gap first (what differs from the console, what is unverified, what throws) and keep only the behaviour it needs: 5415 characters
1 findings, 0 errors; GitHub shows at most 10 error annotations, the job summary lists all

The ABI-audit summary command emitted:

status: passed_with_warnings
symbols: 119
findings: 15
kinds: {'public-declaration-not-found': 1, 'definition-not-found': 7, 'export-removed': 7}
{
  "findings": [
    {
      "path": "core/libs/tests/GuestSaveDataEventCallback.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    },
    {
      "path": "core/libs/tests/GuestSaveDataMountStatus.cpp",
      "line": 1,
      "kind": "possible-unregistered-cpp-test",
      "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage."
    }
  ],
  "negative_control_candidates": [],
  "limits": [
    "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.",
    "A test that passes against base is not by itself proof that the PR test is inadequate.",
    "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error."
  ]
}

The diff checks exited 0 and emitted no output. The precheck's isolated checkout did not contain the workspace-local ABI, stack, or test-quality helper scripts; I ran those helpers from the workspace against the exact fetched head.

Findings

Blocking

  • In sceSaveDataRegisterEventCallback, the g_initializations check happens before taking the callback locks and is not synchronized with the final sceSaveDataTerminate transition. If registration reads a nonzero count, then final termination sets it to zero and DetachEventDelivery clears the callback, registration can subsequently store the callback and return success with no worker. A later Initialize3 starts a worker without clearing that callback, so events may call it after reinitialization even though it was unregistered by termination. Serialize the initialized-state check and callback installation with the final-termination transition, and add a regression test that races registration with final termination and verifies no callback survives a subsequent initialization without registering again.

Non-blocking

The declared order-only dependency chain includes #10674, whose branch currently conflicts with main; this is an integration-order issue, not a request to rebase the dependent PR before its dependency is resolved.

Sources

Not verified

I did not compile the change or run its C++ tests locally. Current hosted checks were queued at the final refresh; PR-description test results are author-reported. I did not verify console behavior or the dependency's eventual merge order.

To get this to a good state

Synchronize registration with the final termination lifecycle and add the concurrent regression case. I will rerun the same no-build checks on the new head; build-dependent CI evidence should also be checked before approval.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5716776526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13551#pullrequestreview-5716776526). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-30T18:19:25Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The event callback registration can race with final termination, leaving a callback registered after shutdown and allowing it to be reused after reinitialization without a new registration. ## What I ran Reviewed head `629477b800f75f29aac25fb104616d189e8a265b` against PR base `4bc9e779aa7abb2109c65ee3bca19e1b85df3be8`; the individual merge preview against that base was clean. The declared order-only dependency chain is #10674 → #12748 → #13551; #12748 and #13551 preview cleanly against current `main`, while #10674 currently conflicts with it. Environment: Linux x86-64, Python 3.11.2, GCC 12.2.0. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13551 python3 tools/pr_stack_check.py 13551 --repo boykopovar/AnyPS5 --output-dir /tmp/stack-13551-new git diff --check 4bc9e779aa7abb2109c65ee3bca19e1b85df3be8...629477b800f75f29aac25fb104616d189e8a265b git diff --check refs/pr/12748...refs/review/13551 python3 tools/pr_abi_audit.py --repo /marc/AnyPS5 --base refs/review/main-latest --head refs/review/13551 --json python3 tools/pr_test_quality.py --root /tmp/anyps5-13551-head.0eti4f --json core/libs/tests/GuestSaveDataEventCallback.cpp core/libs/tests/GuestSaveDataMountStatus.cpp gh pr view 13551 --repo boykopovar/AnyPS5 ``` ## Results | Check | Result | |---|---| | Diff and conventions | Precheck passed diff and convention checks; it reported the repository's existing long technical-debt-line warning. Both direct diff checks exited 0 with no output. | | Dependency/mergeability | #13551 and #12748 preview cleanly against current `main`; #10674 has a conflict and is declared order-only by #12748. The precheck could not invoke its isolated stack helper, so I reran the stack check directly. | | Export ABI lexical audit | `passed_with_warnings`: 15 heuristic findings. Seven refer to save-data exports from the current base absent from the PR branch tree, but the merge preview is clean; one is the new internal worker function in an anonymous namespace. The audit is not a C++ parser or binary ABI test. | | Test-quality heuristic | Two `possible-unregistered-cpp-test` warnings are false positives: CMake explicitly builds both files and registers CTest entries. | | Hosted CI | At refresh, eligibility, conventions, portability, intake, labels, and report were queued. The PR description reports prior repeated Linux/Windows runs, but I did not reproduce them for this head. | | Local build/tests | Not run; the initial review is no-build, and no exact-head test binary was available. | <details><summary>Unedited output from focused checks</summary> The convention check emitted this warning and exit summary: ```text docs/dev/debt/libSceSaveData.native.md:21: warning: [debt-length] Technical debt entry over 1000 characters: state the gap first (what differs from the console, what is unverified, what throws) and keep only the behaviour it needs: 5415 characters 1 findings, 0 errors; GitHub shows at most 10 error annotations, the job summary lists all ``` The ABI-audit summary command emitted: ```text status: passed_with_warnings symbols: 119 findings: 15 kinds: {'public-declaration-not-found': 1, 'definition-not-found': 7, 'export-removed': 7} ``` ```json { "findings": [ { "path": "core/libs/tests/GuestSaveDataEventCallback.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." }, { "path": "core/libs/tests/GuestSaveDataMountStatus.cpp", "line": 1, "kind": "possible-unregistered-cpp-test", "message": "Changed C++ test source path was not found literally in CMake files; inspect registration, generated source lists, and workflow coverage." } ], "negative_control_candidates": [], "limits": [ "Heuristics can miss weak assertions and can flag valid tests; inspect every finding.", "A test that passes against base is not by itself proof that the PR test is inadequate.", "Negative controls are only candidates until the test actually runs against base and fails by assertion rather than import/setup error." ] } ``` The diff checks exited 0 and emitted no output. The precheck's isolated checkout did not contain the workspace-local ABI, stack, or test-quality helper scripts; I ran those helpers from the workspace against the exact fetched head. </details> ## Findings ### Blocking - In `sceSaveDataRegisterEventCallback`, the `g_initializations` check happens before taking the callback locks and is not synchronized with the final `sceSaveDataTerminate` transition. If registration reads a nonzero count, then final termination sets it to zero and `DetachEventDelivery` clears the callback, registration can subsequently store the callback and return success with no worker. A later `Initialize3` starts a worker without clearing that callback, so events may call it after reinitialization even though it was unregistered by termination. Serialize the initialized-state check and callback installation with the final-termination transition, and add a regression test that races registration with final termination and verifies no callback survives a subsequent initialization without registering again. ### Non-blocking The declared order-only dependency chain includes #10674, whose branch currently conflicts with `main`; this is an integration-order issue, not a request to rebase the dependent PR before its dependency is resolved. ## Sources - [Registration and initialization check at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/629477b800f75f29aac25fb104616d189e8a265b/core/libs/prx/libSceSaveData.native/Export.cpp#L1763-L1775) - [Final termination and callback detach at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/629477b800f75f29aac25fb104616d189e8a265b/core/libs/prx/libSceSaveData.native/Export.cpp#L1292-L1311) - [Callback test registration in CMake at the reviewed head](https://github.com/boykopovar/AnyPS5/blob/629477b800f75f29aac25fb104616d189e8a265b/core/libs/prx/libSceSaveData.native/CMakeLists.txt#L52-L62) ## Not verified I did not compile the change or run its C++ tests locally. Current hosted checks were queued at the final refresh; PR-description test results are author-reported. I did not verify console behavior or the dependency's eventual merge order. ## To get this to a good state Synchronize registration with the final termination lifecycle and add the concurrent regression case. I will rerun the same no-build checks on the new head; build-dependent CI evidence should also be checked before approval.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13551
No description provided.