fix(libSceSaveData.native): back up and deliver event in sceSaveDataUmount2 #23789

Merged
birdmarty merged 1 commit from upstream-pr/23789 into main 2026-11-20 04:58:10 +00:00
birdmarty commented 2026-11-19 16:54:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by birdmarty on 2026-11-19T16:54:17Z.


What

sceSaveDataUmount2 ignored its mode. A title that unmounts with 0x10000 (back up on unmount) receives a SAVE_DATA_EVENT_TYPE_UMOUNT_BACKUP event once the backup is written, and may wait for it through sceSaveDataGetEventResult. AnyPS5 unmounted without a backup and without the event, so such a title waited forever.

Lies of P (PPSA10621 01.012) does this on a cold first run:

  1. TaskGraphThreadHP creates Account1 and OptionSlot.
  2. It unmounts them with sceSaveDataUmount2(0x10000, ...) while holding the game's save mutex.
  3. It polls for the event in a sleep loop, while GameThread waits for that mutex.

The game stalls on the loading screen before the main menu, and again when New Game creates its slots. A run that finds both slots on disk mounts them read-only and unmounts with mode 0, so it reaches the menu; that is why only runs that had to create the slots stalled.

#5983 is the same stall on another release of the game, PPSA10261 01.005.001, which freezes on "Now Lying...". With this change a cold PPSA10261 run with no save data reached the menu and played a New Game. The WAIT_REG_MEM timeouts discussed there are not the cause: that run still logged nine of them and carried on.

sceSaveDataUmount2 now handles each mode as follows:

  • 0: unmounts without a backup or an event, as before.
  • 0x10000 (SAVE_DATA_UMOUNT_MODE_BACKUP) and 0x10001 (with SAVE_DATA_UMOUNT_MODE_BACKUP_FORCE): unmounts and copies the backup. It queues SAVE_DATA_EVENT_TYPE_UMOUNT_BACKUP, with SAVE_DATA_ERROR_INTERNAL if the copy fails, and delivers it to a registered callback. This is what sceSaveDataUmountWithBackup already does; both now share one function.
  • Any other mode: throws, since its behaviour is not known.

What stays the same:

  • Mode 0, which every other caller in the tree passes (including sceSaveDataUmount), unmounts exactly as before.
  • sceSaveDataUmountWithBackup runs the same steps in the same order, now through the shared function.
  • 0x10001 was already used by an upstream test (CheckPreparedCreate2 in GuestSaveDataIcon.cpp), where it only unmounted. It now backs up, and the backup event carries the title ID, so that test now provides a param.json, as sceSaveDataUmountWithBackup already requires.

Changes

  • libSceSaveData.native/SaveData.hpp: SAVE_DATA_UMOUNT_MODE_BACKUP (0x10000) and SAVE_DATA_UMOUNT_MODE_BACKUP_FORCE (0x1).
  • libSceSaveData.native/Export.cpp: unmountMountPoint, shared by sceSaveDataUmount2 and sceSaveDataUmountWithBackup, and the mode handling above.
  • Tests:
    • GuestSaveDataMountStatus.cpp: 0x10000, 0x10001 and 0; a failing backup copy, which still unmounts and returns 0 but reports INTERNAL in the event; an unknown mode throws.
    • GuestSaveDataEventCallback.cpp: the 0x10000 event reaches the callback once.
    • GuestSaveDataIcon.cpp: param.json for the existing 0x10001 case.
  • docs/dev/debt/changes/fix-savedata-umount2-backup.md: forced and ordinary backups are not told apart, and an unchanged save is still copied. Not measured on a console.

Tested

Windows 11 Pro (build 26300), MinGW-w64 GCC 15.3.0, Release build with tests.

The 22 SaveData test programs, on main d7be67833e and on this change, same machine:

  • main: 38 tests, all passed. This change: the same 38, all passed. The new cases are inside guest_savedata_mount_status, guest_savedata_event_callback and guest_savedata_icon.
  • With main's Export.cpp under these tests, guest_savedata_mount_status fails (umount2(65536) posts an event) and guest_savedata_event_callback fails (umount2(0x10000)'s completion reaches the callback within 5 s).
  • public_headers: 65/65 passed.
  • tools/check_conventions.py --base origin/main and tools/debt_fold.py --check: passed.
  • tools/pr_overlap.py: no open pull request implements sceSaveDataUmount2 or sceSaveDataUmountWithBackup, or changes the same lines. #15650 and #18674 conflict with main and share files; neither touches the unmount code.

Lies of P (PPSA10621 01.012), #22009, on an earlier main (d31916ed37) with #16053 reverted so the picture is upright (#20827 does this on main now):

  • Before: every run that had to create the two slots stalled on the loading screen before the menu. That held cold and warm, with and without APS5_PLAYGO_UNLISTED_CHUNKS=installed and APS5_GPU_WAIT_TIMEOUT_MS=60000: seven runs in all. With both slots already on disk the menu came up, and New Game then stalled.
  • With this change:
    • A cold run, with no save data and no shader cache, reached the main menu: sceSaveDataUmount2(0x10000) for Account1 and OptionSlot backed both up and delivered the event.
    • New Game loaded into gameplay. Over three more runs the game was played through Krat Central Station and past the first miniboss, with the save slots written and backed up.
    • Two of those runs ended on an unrelated AGC abort in storage images, which #23790 fixes.

Lies of P (PPSA10261 01.005.001), #5983, same machine and base, with #23790 as well (neither touches SaveData):

  • A cold run with no save data and no shader cache reached the menu, started a New Game and played for about 16 minutes: 1154 s, clean exit.
  • All five save slots the game made were backed up, the last less than a minute before the window was closed.

Lies of P: past the loading screen, New Game, Krat Central Station

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • Fixes: Fixes #5983
  • Unblocks: PPSA10621 #22009
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5399254855 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23789). Originally posted by [birdmarty](https://github.com/birdmarty) on 2026-11-19T16:54:17Z. --- ### What `sceSaveDataUmount2` ignored its `mode`. A title that unmounts with `0x10000` (back up on unmount) receives a `SAVE_DATA_EVENT_TYPE_UMOUNT_BACKUP` event once the backup is written, and may wait for it through `sceSaveDataGetEventResult`. AnyPS5 unmounted without a backup and without the event, so such a title waited forever. Lies of P (PPSA10621 01.012) does this on a cold first run: 1. `TaskGraphThreadHP` creates `Account1` and `OptionSlot`. 2. It unmounts them with `sceSaveDataUmount2(0x10000, ...)` while holding the game's save mutex. 3. It polls for the event in a sleep loop, while `GameThread` waits for that mutex. The game stalls on the loading screen before the main menu, and again when New Game creates its slots. A run that finds both slots on disk mounts them read-only and unmounts with mode 0, so it reaches the menu; that is why only runs that had to create the slots stalled. #5983 is the same stall on another release of the game, PPSA10261 01.005.001, which freezes on "Now Lying...". With this change a cold PPSA10261 run with no save data reached the menu and played a New Game. The `WAIT_REG_MEM` timeouts discussed there are not the cause: that run still logged nine of them and carried on. `sceSaveDataUmount2` now handles each mode as follows: - **`0`:** unmounts without a backup or an event, as before. - **`0x10000` (`SAVE_DATA_UMOUNT_MODE_BACKUP`) and `0x10001` (with `SAVE_DATA_UMOUNT_MODE_BACKUP_FORCE`):** unmounts and copies the backup. It queues `SAVE_DATA_EVENT_TYPE_UMOUNT_BACKUP`, with `SAVE_DATA_ERROR_INTERNAL` if the copy fails, and delivers it to a registered callback. This is what `sceSaveDataUmountWithBackup` already does; both now share one function. - **Any other mode:** throws, since its behaviour is not known. What stays the same: - Mode 0, which every other caller in the tree passes (including `sceSaveDataUmount`), unmounts exactly as before. - `sceSaveDataUmountWithBackup` runs the same steps in the same order, now through the shared function. - `0x10001` was already used by an upstream test (`CheckPreparedCreate2` in `GuestSaveDataIcon.cpp`), where it only unmounted. It now backs up, and the backup event carries the title ID, so that test now provides a `param.json`, as `sceSaveDataUmountWithBackup` already requires. #### Changes - `libSceSaveData.native/SaveData.hpp`: `SAVE_DATA_UMOUNT_MODE_BACKUP` (`0x10000`) and `SAVE_DATA_UMOUNT_MODE_BACKUP_FORCE` (`0x1`). - `libSceSaveData.native/Export.cpp`: `unmountMountPoint`, shared by `sceSaveDataUmount2` and `sceSaveDataUmountWithBackup`, and the mode handling above. - Tests: - `GuestSaveDataMountStatus.cpp`: `0x10000`, `0x10001` and `0`; a failing backup copy, which still unmounts and returns 0 but reports `INTERNAL` in the event; an unknown mode throws. - `GuestSaveDataEventCallback.cpp`: the `0x10000` event reaches the callback once. - `GuestSaveDataIcon.cpp`: `param.json` for the existing `0x10001` case. - `docs/dev/debt/changes/fix-savedata-umount2-backup.md`: forced and ordinary backups are not told apart, and an unchanged save is still copied. Not measured on a console. ### Tested Windows 11 Pro (build 26300), MinGW-w64 GCC 15.3.0, Release build with tests. The 22 SaveData test programs, on `main` `d7be67833e` and on this change, same machine: - `main`: 38 tests, all passed. This change: the same 38, all passed. The new cases are inside `guest_savedata_mount_status`, `guest_savedata_event_callback` and `guest_savedata_icon`. - With `main`'s `Export.cpp` under these tests, `guest_savedata_mount_status` fails (`umount2(65536) posts an event`) and `guest_savedata_event_callback` fails (`umount2(0x10000)'s completion reaches the callback within 5 s`). - `public_headers`: 65/65 passed. - `tools/check_conventions.py --base origin/main` and `tools/debt_fold.py --check`: passed. - `tools/pr_overlap.py`: no open pull request implements `sceSaveDataUmount2` or `sceSaveDataUmountWithBackup`, or changes the same lines. #15650 and #18674 conflict with `main` and share files; neither touches the unmount code. Lies of P (PPSA10621 01.012), [#22009](https://github.com/boykopovar/AnyPS5/discussions/22009), on an earlier `main` (`d31916ed37`) with #16053 reverted so the picture is upright (#20827 does this on `main` now): - **Before:** every run that had to create the two slots stalled on the loading screen before the menu. That held cold and warm, with and without `APS5_PLAYGO_UNLISTED_CHUNKS=installed` and `APS5_GPU_WAIT_TIMEOUT_MS=60000`: seven runs in all. With both slots already on disk the menu came up, and New Game then stalled. - **With this change:** - A cold run, with no save data and no shader cache, reached the main menu: `sceSaveDataUmount2(0x10000)` for `Account1` and `OptionSlot` backed both up and delivered the event. - New Game loaded into gameplay. Over three more runs the game was played through Krat Central Station and past the first miniboss, with the save slots written and backed up. - Two of those runs ended on an unrelated AGC abort in storage images, which #23790 fixes. Lies of P (PPSA10261 01.005.001), #5983, same machine and base, with #23790 as well (neither touches SaveData): - A cold run with no save data and no shader cache reached the menu, started a New Game and played for about 16 minutes: 1154 s, clean exit. - All five save slots the game made were backed up, the last less than a minute before the window was closed. ![Lies of P: past the loading screen, New Game, Krat Central Station](https://raw.githubusercontent.com/birdmarty/AnyPS5/pr-assets/fix-savedata-umount2-backup/1-lies-of-p-past-the-loading-screen.png) ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none - [x] Fixes: Fixes #5983 - [x] Unblocks: PPSA10621 #22009 - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-19 17:17:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T17:17:06Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 290d2f46b1:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_savedata_event_callback_tests, guest_savedata_icon_tests, guest_savedata_mount_status_tests built cleanly.
  • CTest (guest_savedata_mount_status, guest_savedata_event_callback, guest_savedata_icon_roundtrip, guest_savedata_icon_bounds, guest_savedata_icon_readonly, guest_savedata_icon_prepared_create2, guest_savedata_icon_arguments, guest_savedata_icon_io):
    1/8 Test #5105: guest_savedata_icon_bounds .............   Passed    0.06 sec
    2/8 Test #5104: guest_savedata_icon_roundtrip ..........   Passed    0.06 sec
    3/8 Test #5106: guest_savedata_icon_readonly ...........   Passed    0.04 sec
    4/8 Test #5109: guest_savedata_icon_io .................   Passed    0.04 sec
    5/8 Test #5107: guest_savedata_icon_prepared_create2 ...   Passed    0.15 sec
    6/8 Test #5108: guest_savedata_icon_arguments ..........   Passed    0.05 sec
    7/8 Test #5099: guest_savedata_mount_status ............   Passed    0.99 sec
    8/8 Test #5100: guest_savedata_event_callback ..........   Passed    0.78 sec
    100% tests passed, 0 tests failed out of 8
    
  • Negative control: with core/libs/prx/libSceSaveData.native/Export.cpp, core/libs/prx/libSceSaveData.native/SaveData.hpp reverted to main and the new tests kept, the suite fails:
    2/8 Test #5105: guest_savedata_icon_bounds .............   Passed    0.03 sec
    3/8 Test #5104: guest_savedata_icon_roundtrip ..........   Passed    0.03 sec
    4/8 Test #5107: guest_savedata_icon_prepared_create2 ...   Passed    0.03 sec
    5/8 Test #5106: guest_savedata_icon_readonly ...........   Passed    0.02 sec
    6/8 Test #5109: guest_savedata_icon_io .................   Passed    0.02 sec
    7/8 Test #5108: guest_savedata_icon_arguments ..........   Passed    0.02 sec
    8/8 Test #5100: guest_savedata_event_callback ..........***Failed    5.74 sec
    75% tests passed, 2 tests failed out of 8
    
    Restoring the change makes it pass again.
  • Code reading:
    • Export.cpp: sceSaveDataUmount2 correctly validates mode against 0, SAVE_DATA_UMOUNT_MODE_BACKUP (0x10000), and SAVE_DATA_UMOUNT_MODE_BACKUP | SAVE_DATA_UMOUNT_MODE_BACKUP_FORCE (0x10001), throwing std::runtime_error on unknown modes per technical debt specifications.
    • Export.cpp: unmountMountPoint safely copies mount_point using copy_mount_point, properly checks slot validity returning SAVE_DATA_ERROR_NOT_MOUNTED, and atomically removes alias and clears slot while holding g_slots_mutex.
    • Export.cpp: backup execution and event delivery accurately replicate sceSaveDataUmountWithBackup behavior, catching std::exception and setting event.error_code to SAVE_DATA_ERROR_INTERNAL on backup failure while protecting g_events under g_state_mutex.
    • Export.cpp: refactored sceSaveDataUmountWithBackup cleanly delegates to unmountMountPoint(mount_point, tracePoint, true) while preserving the g_initializations check.
    • docs/dev/debt/changes/fix-savedata-umount2-backup.md: technical debt fragment correctly documents the mode handling, event queueing, and behavior differences in compliance with AGENTS.md.
    • core/libs/tests: GuestSaveDataMountStatus.cpp and GuestSaveDataEventCallback.cpp thoroughly test valid modes, unknown modes throwing, copy failures, unmounted error cases, and event queueing/delivery without leaving dirty state.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5979873652 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/23789#pullrequestreview-5979873652). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-19T17:17:06Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `290d2f46b1`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_savedata_event_callback_tests`, `guest_savedata_icon_tests`, `guest_savedata_mount_status_tests` built cleanly. - **CTest** (`guest_savedata_mount_status`, `guest_savedata_event_callback`, `guest_savedata_icon_roundtrip`, `guest_savedata_icon_bounds`, `guest_savedata_icon_readonly`, `guest_savedata_icon_prepared_create2`, `guest_savedata_icon_arguments`, `guest_savedata_icon_io`): ``` 1/8 Test #5105: guest_savedata_icon_bounds ............. Passed 0.06 sec 2/8 Test #5104: guest_savedata_icon_roundtrip .......... Passed 0.06 sec 3/8 Test #5106: guest_savedata_icon_readonly ........... Passed 0.04 sec 4/8 Test #5109: guest_savedata_icon_io ................. Passed 0.04 sec 5/8 Test #5107: guest_savedata_icon_prepared_create2 ... Passed 0.15 sec 6/8 Test #5108: guest_savedata_icon_arguments .......... Passed 0.05 sec 7/8 Test #5099: guest_savedata_mount_status ............ Passed 0.99 sec 8/8 Test #5100: guest_savedata_event_callback .......... Passed 0.78 sec 100% tests passed, 0 tests failed out of 8 ``` - **Negative control**: with `core/libs/prx/libSceSaveData.native/Export.cpp`, `core/libs/prx/libSceSaveData.native/SaveData.hpp` reverted to `main` and the new tests kept, the suite fails: ``` 2/8 Test #5105: guest_savedata_icon_bounds ............. Passed 0.03 sec 3/8 Test #5104: guest_savedata_icon_roundtrip .......... Passed 0.03 sec 4/8 Test #5107: guest_savedata_icon_prepared_create2 ... Passed 0.03 sec 5/8 Test #5106: guest_savedata_icon_readonly ........... Passed 0.02 sec 6/8 Test #5109: guest_savedata_icon_io ................. Passed 0.02 sec 7/8 Test #5108: guest_savedata_icon_arguments .......... Passed 0.02 sec 8/8 Test #5100: guest_savedata_event_callback ..........***Failed 5.74 sec 75% tests passed, 2 tests failed out of 8 ``` Restoring the change makes it pass again. - **Code reading**: - Export.cpp: sceSaveDataUmount2 correctly validates mode against 0, SAVE_DATA_UMOUNT_MODE_BACKUP (0x10000), and SAVE_DATA_UMOUNT_MODE_BACKUP | SAVE_DATA_UMOUNT_MODE_BACKUP_FORCE (0x10001), throwing std::runtime_error on unknown modes per technical debt specifications. - Export.cpp: unmountMountPoint safely copies mount_point using copy_mount_point, properly checks slot validity returning SAVE_DATA_ERROR_NOT_MOUNTED, and atomically removes alias and clears slot while holding g_slots_mutex. - Export.cpp: backup execution and event delivery accurately replicate sceSaveDataUmountWithBackup behavior, catching std::exception and setting event.error_code to SAVE_DATA_ERROR_INTERNAL on backup failure while protecting g_events under g_state_mutex. - Export.cpp: refactored sceSaveDataUmountWithBackup cleanly delegates to unmountMountPoint(mount_point, tracePoint, true) while preserving the g_initializations check. - docs/dev/debt/changes/fix-savedata-umount2-backup.md: technical debt fragment correctly documents the mode handling, event queueing, and behavior differences in compliance with AGENTS.md. - core/libs/tests: GuestSaveDataMountStatus.cpp and GuestSaveDataEventCallback.cpp thoroughly test valid modes, unknown modes throwing, copy failures, unmounted error cases, and event queueing/delivery without leaving dirty state. Looks Good To Me
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!23789
No description provided.