feat(libSceCompanionHttpd): keep the server state with no companion device #8112

Merged
savvaniss merged 1 commit from upstream-pr/8112 into main 2026-10-23 06:23:36 +00:00
savvaniss commented 2026-10-19 22:08:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T22:08:37Z.


What

libSceCompanionHttpd on main is an empty placeholder. A PS4 title that imports it does not load. Monopoly Plus from CUSA03312 (Hasbro Family Fun Pack) sets up the companion-app server while it starts, and gives up on a failed setup only as far as its own companion feature goes.

The library now keeps the server's state, with no companion device ever connecting:

  • sceCompanionHttpdOptParamInitialize zeroes the 0x60-byte option block. Titles fill work memory at +0x08 and +0x10 and a temporary data mount point at +0x58 after this call. The console's defaults for the other fields are unknown, and nothing reads them.
  • Initialize and Terminate, RegisterRequestCallback and UnregisterRequestCallback, and Start and Stop track the state and return the library's errors:
    • INVALID_PARAM for null arguments;
    • ALREADY_INITIALIZED and NOT_INITIALIZED;
    • ALREADY_REGISTERED;
    • ALREADY_STARTED and NOT_STARTED.
  • GetEvent returns NO_EVENT without writing the event, and the request callback is never called. No HTTP server listens, so no device can connect.
  • Two cases throw because the console's answer is unknown: unregistering when no callback is registered, and terminating a started server.
  • The other nine exports are declared and throw: the response builders AddHeader, SetStatus and SetBody, which are only reachable from a request, and the six the title does not import. With them, the file has all 17 of the library's exports.

The error values are shadPS4's companion_error.h. ALREADY_REGISTERED is written there as 0x80E4000, one digit short; this uses 0x80E4000C, the value between NOT_STARTED and NOT_CONNECTED. The debt file records each choice.

#7840 declares the same 17 exports as placeholders. This PR implements eight of them and declares the rest, so #7840's libSceCompanionHttpd part is no longer needed once this lands.

Tested

Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release.

  • guest_companion_httpd (new) passes. It covers:
    • the option block: zeroed over 0x60 bytes, nothing past it;
    • each state error before and after initialization;
    • NO_EVENT before and after the start, with the event untouched;
    • a request callback that aborts if it is ever called;
    • the two throwing cases and the nine declared exports.
  • Monopoly Plus (CUSA03312): run through the PS4 path of #6977 with this state machine, on an RX 9070 XT. It goes through OptParamInitialize, Initialize and RegisterRequestCallback, polls GetEvent without a device, and reaches its loading screen at 60 fps.
  • tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py lists #7840 as above.

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: CUSA03312 #7198
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4928079802 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8112). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-19T22:08:37Z. --- ### What `libSceCompanionHttpd` on `main` is an empty placeholder. A PS4 title that imports it does not load. Monopoly Plus from CUSA03312 (Hasbro Family Fun Pack) sets up the companion-app server while it starts, and gives up on a failed setup only as far as its own companion feature goes. The library now keeps the server's state, with no companion device ever connecting: - `sceCompanionHttpdOptParamInitialize` zeroes the 0x60-byte option block. Titles fill work memory at +0x08 and +0x10 and a temporary data mount point at +0x58 after this call. The console's defaults for the other fields are unknown, and nothing reads them. - `Initialize` and `Terminate`, `RegisterRequestCallback` and `UnregisterRequestCallback`, and `Start` and `Stop` track the state and return the library's errors: - `INVALID_PARAM` for null arguments; - `ALREADY_INITIALIZED` and `NOT_INITIALIZED`; - `ALREADY_REGISTERED`; - `ALREADY_STARTED` and `NOT_STARTED`. - `GetEvent` returns `NO_EVENT` without writing the event, and the request callback is never called. No HTTP server listens, so no device can connect. - Two cases throw because the console's answer is unknown: unregistering when no callback is registered, and terminating a started server. - The other nine exports are declared and throw: the response builders `AddHeader`, `SetStatus` and `SetBody`, which are only reachable from a request, and the six the title does not import. With them, the file has all 17 of the library's exports. The error values are shadPS4's `companion_error.h`. `ALREADY_REGISTERED` is written there as 0x80E4000, one digit short; this uses 0x80E4000C, the value between `NOT_STARTED` and `NOT_CONNECTED`. The debt file records each choice. #7840 declares the same 17 exports as placeholders. This PR implements eight of them and declares the rest, so #7840's `libSceCompanionHttpd` part is no longer needed once this lands. ### Tested Windows 11 Pro 26300, WinLibs GCC 15.2.0, Release. - `guest_companion_httpd` (new) passes. It covers: - the option block: zeroed over 0x60 bytes, nothing past it; - each state error before and after initialization; - `NO_EVENT` before and after the start, with the event untouched; - a request callback that aborts if it is ever called; - the two throwing cases and the nine declared exports. - **Monopoly Plus (CUSA03312):** run through the PS4 path of #6977 with this state machine, on an RX 9070 XT. It goes through `OptParamInitialize`, `Initialize` and `RegisterRequestCallback`, polls `GetEvent` without a device, and reaches its loading screen at 60 fps. - `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py` lists #7840 as above. ### 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: CUSA03312 #7198 - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-19 22:09:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T22:09:22Z.


Progress report (56b299c → 346cafd)

📈 System libraries: 64.42% (+0.09%, +6 implemented functions)

✅ 6 implemented
Library Name
libSceCompanionHttpd sceCompanionHttpdGetEvent
libSceCompanionHttpd sceCompanionHttpdInitialize
libSceCompanionHttpd sceCompanionHttpdOptParamInitialize
libSceCompanionHttpd sceCompanionHttpdRegisterRequestCallback
libSceCompanionHttpd sceCompanionHttpdStart
libSceCompanionHttpd sceCompanionHttpdStop
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278468286 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8112#issuecomment-6278468286). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T22:09:22Z. --- <!-- progress-report --> ### Progress report (56b299c → 346cafd) 📈 **System libraries**: 64.42% (+0.09%, +6 implemented functions) <details> <summary>✅ 6 implemented</summary> | Library | Name | | - | - | | libSceCompanionHttpd | `sceCompanionHttpdGetEvent` | | libSceCompanionHttpd | `sceCompanionHttpdInitialize` | | libSceCompanionHttpd | `sceCompanionHttpdOptParamInitialize` | | libSceCompanionHttpd | `sceCompanionHttpdRegisterRequestCallback` | | libSceCompanionHttpd | `sceCompanionHttpdStart` | | libSceCompanionHttpd | `sceCompanionHttpdStop` | </details>
blawesom commented 2026-10-20 07:44:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-20T07:44:09Z.


Rebase handoff — rebased onto current main (3fd1cc393, authorship unchanged). main's parameter-less NotImplemented stubs for this library conflicted with your rework at ten points; resolved throughout in favour of your implementation (the result is byte-identical to your own Export.cpp), and your split debt entries replace main's single stub-list entry.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; guest_companion_httpd passes; 1672/1675 — green apart from the three known main failures (#7584 BDA, #7784 guest-memory, and the tessellation segfault — #5444's Mesa 26.2.6 fix isn't in my 26.2.4), none from this PR; conventions pass.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/8112
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is 346cafdb8.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6286003829 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8112#issuecomment-6286003829). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-20T07:44:09Z. --- **Rebase handoff** — rebased onto current `main` (`3fd1cc393`, authorship unchanged). `main`'s parameter-less `NotImplemented` stubs for this library conflicted with your rework at ten points; resolved throughout in favour of your implementation (the result is byte-identical to your own `Export.cpp`), and your split debt entries replace `main`'s single stub-list entry. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; `guest_companion_httpd` passes; **1672/1675 — green apart from the three known `main` failures** (#7584 BDA, #7784 guest-memory, and the tessellation segfault — #5444's Mesa 26.2.6 fix isn't in my 26.2.4), none from this PR; conventions pass. **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/8112 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `346cafdb8`.
savvaniss commented 2026-10-20 12:21:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-20T12:21:06Z.


@blawesom thank you for the rebase and the Linux run. I took your branch as it is: the head is now 346cafdb8. Before pushing I checked it against my previous head 8674754b6:

  • All four files are byte-identical to mine.
  • The library's 17 exports match main's list, so the conflict resolution drops none of them.
  • It still merges cleanly into today's main (56b299c3a), and tools/check_conventions.py --base origin/main passes.

I did not rebuild it on Windows; your Linux result (guest_companion_httpd passes, 1672/1675 with only main's known failures) covers this head.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290710869 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8112#issuecomment-6290710869). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-20T12:21:06Z. --- @blawesom thank you for the rebase and the Linux run. I took your branch as it is: the head is now `346cafdb8`. Before pushing I checked it against my previous head `8674754b6`: - All four files are byte-identical to mine. - The library's 17 exports match `main`'s list, so the conflict resolution drops none of them. - It still merges cleanly into today's `main` (`56b299c3a`), and `tools/check_conventions.py --base origin/main` passes. I did not rebuild it on Windows; your Linux result (`guest_companion_httpd` passes, 1672/1675 with only `main`'s known failures) covers this head. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-21 23:43:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:43:43Z.

Review: APPROVED


The implementation keeps the described no-device state machine internally consistent: initialization clears the callback on termination, repeated state transitions return explicit errors, GetEvent leaves the output untouched, and request callbacks cannot run without a connected device. The 0x60-byte option layout has a size assertion, and the tests cover its bounds plus the state/error paths and throwing exports. The ALREADY_REGISTERED value is correctly corrected to 0x80E4000C; the cited shadPS4 header contains the one-digit-short value 0x80E4000. The title discussion link in Unblocks resolves to the CUSA03312 Game bring-up thread. The former #7840 overlap is now merged into main; current tools/pr_overlap.py reports no overlap with open PRs. Eligibility, conventions, labels and report pass; hosted build jobs are skipped, and the reported Linux/Windows title/library runs remain author-reported. No blocking issue found; approved.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607576207 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8112#pullrequestreview-5607576207). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:43:43Z. **Review:** APPROVED --- The implementation keeps the described no-device state machine internally consistent: initialization clears the callback on termination, repeated state transitions return explicit errors, `GetEvent` leaves the output untouched, and request callbacks cannot run without a connected device. The 0x60-byte option layout has a size assertion, and the tests cover its bounds plus the state/error paths and throwing exports. The `ALREADY_REGISTERED` value is correctly corrected to `0x80E4000C`; the cited shadPS4 header contains the one-digit-short value `0x80E4000`. The title discussion link in `Unblocks` resolves to the CUSA03312 Game bring-up thread. The former #7840 overlap is now merged into main; current `tools/pr_overlap.py` reports no overlap with open PRs. Eligibility, conventions, labels and report pass; hosted build jobs are skipped, and the reported Linux/Windows title/library runs remain author-reported. No blocking issue found; approved.
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!8112
No description provided.