fix(libSceNpSnsFacebookDialog): keep a terminated dialog terminated during Open and Close #12893

Merged
XairRrR merged 1 commit from upstream-pr/12893 into main 2026-11-05 08:50:56 +00:00
XairRrR commented 2026-10-29 13:31:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T13:31:34Z.


What

sceNpSnsFacebookDialogOpen and sceNpSnsFacebookDialogClose read the dialog status, check it, and then store FINISHED in a separate step. If another thread calls sceNpSnsFacebookDialogTerminate between the read and the store, Terminate returns 0 and sets the status to NONE, and then Open or Close overwrites it with FINISHED. Example: the dialog is initialized, thread A calls Open with a valid param while thread B calls Terminate. Both return 0, but afterwards sceNpSnsFacebookDialogGetStatus returns FINISHED (3) instead of NONE (0), and the next sceNpSnsFacebookDialogInitialize fails with ALREADY_INITIALIZED (0x80B80004). The library stays stuck looking initialized after it was terminated. Close has the same race.

Open and Close now set FINISHED with a compare-exchange loop that re-runs the checks on the value being replaced. A concurrent Terminate then either goes first, so the call returns NOT_INITIALIZED, or goes after, so the status ends at NONE. Open still offers the PSN feature notice only after a successful transition. Single-threaded results are unchanged.

Tested

Rebased onto main 1c8c0efc8c, Linux, Release, Ninja.

  • guest_np_sns_facebook_dialog gets two new cases. Each runs 200000 rounds of Initialize, then Open (or Close) on the main thread racing Terminate on a second thread, and requires the status to be NONE after each round. They run after the existing RequireNotices case, which leaves the notice mode on Silent.
  • cmake --build build --target libs guest_np_sns_facebook_dialog_tests -j32 built.
  • ctest --test-dir build -R '^guest_np_sns_facebook_dialog$' --repeat until-fail:50: 1/1 passed on all 50 runs.
  • Negative control: with Export.cpp from 1c8c0efc8c and this PR's test kept, the test aborted on 10 of 11 runs.
  • python3 tools/check_conventions.py --base 1c8c0efc8c41314402e6966da5bef6ea3d639d10: All conventions checks passed. git diff --check: clean.
  • Before the rebase: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF: 50/50 passed; negative control aborted 10 of 10 (Open race) and 5 of 5 (Close race only).

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5068937468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12893). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-29T13:31:34Z. --- ### What `sceNpSnsFacebookDialogOpen` and `sceNpSnsFacebookDialogClose` read the dialog status, check it, and then store `FINISHED` in a separate step. If another thread calls `sceNpSnsFacebookDialogTerminate` between the read and the store, Terminate returns 0 and sets the status to `NONE`, and then Open or Close overwrites it with `FINISHED`. Example: the dialog is initialized, thread A calls Open with a valid param while thread B calls Terminate. Both return 0, but afterwards `sceNpSnsFacebookDialogGetStatus` returns `FINISHED` (3) instead of `NONE` (0), and the next `sceNpSnsFacebookDialogInitialize` fails with `ALREADY_INITIALIZED` (0x80B80004). The library stays stuck looking initialized after it was terminated. Close has the same race. Open and Close now set `FINISHED` with a compare-exchange loop that re-runs the checks on the value being replaced. A concurrent Terminate then either goes first, so the call returns `NOT_INITIALIZED`, or goes after, so the status ends at `NONE`. Open still offers the PSN feature notice only after a successful transition. Single-threaded results are unchanged. ### Tested Rebased onto `main` `1c8c0efc8c`, Linux, Release, Ninja. - `guest_np_sns_facebook_dialog` gets two new cases. Each runs 200000 rounds of Initialize, then Open (or Close) on the main thread racing Terminate on a second thread, and requires the status to be `NONE` after each round. They run after the existing `RequireNotices` case, which leaves the notice mode on Silent. - `cmake --build build --target libs guest_np_sns_facebook_dialog_tests -j32` built. - `ctest --test-dir build -R '^guest_np_sns_facebook_dialog$' --repeat until-fail:50`: 1/1 passed on all 50 runs. - Negative control: with `Export.cpp` from `1c8c0efc8c` and this PR's test kept, the test aborted on 10 of 11 runs. - `python3 tools/check_conventions.py --base 1c8c0efc8c41314402e6966da5bef6ea3d639d10`: All conventions checks passed. `git diff --check`: clean. - Before the rebase: Arch Linux 7.2.11-zen, GCC 16.2.1, Intel Core i9-14900KF: 50/50 passed; negative control aborted 10 of 10 (Open race) and 5 of 5 (Close race only). ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!12893
No description provided.