feat(libSceHttp): report a context's pool in sceHttpGetMemoryPoolStats #8357

Merged
MarrasFederico merged 3 commits from upstream-pr/8357 into main 2026-10-24 10:48:07 +00:00
MarrasFederico commented 2026-10-20 10:58:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-10-20T10:58:45Z.


What

sceHttpGetMemoryPoolStats threw not implemented, and its debt entry listed the signature as unknown. SharpProspero Http.cs documents it as int sceHttpGetMemoryPoolStats(int httpCtxId, SceHttpMemoryPoolStats* currentStat), which reads a context's pool use. The struct holds the pool size, the peak and current use, and a 32-bit reserved word. main has since declared the struct as those three 64-bit fields (24 bytes) in fix(http): recover request metadata and memory stats signatures, so only those 24 bytes are written and the reserved word is left to the caller.

sceHttpInit now keeps the pool size it is given for each context, and sceHttpTerm drops it. The call:

  • Live context: writes {pool size given to sceHttpInit, 0, 0} and returns 0. The library takes nothing from the guest pool, so both use figures are 0; Http2 and NpWebApi2 already report their pools this way.
  • No live context: returns ERROR_BEFORE_INIT (0x80431001) without writing.
  • Unknown or terminated id: returns ERROR_INVALID_ID (0x80431100) without writing. Both errors and their order follow sceHttpCookieFlush.
  • Null currentStat: throws, as the console's error for it is unknown. It is checked first, as Http2 does.

The debt entry records that nothing here is measured on a console and that a console already uses part of the pool for a live context.

Tested

Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, full build with BUILD_TESTING=ON. Windows was not compiled. No title was run.

  • guest_http:
    • Before any sceHttpInit, ids 0, -1 and a request id return ERROR_BEFORE_INIT.
    • With a live context, ids 0, -1, INT32_MAX and a request id return ERROR_INVALID_ID. Two live contexts report their own pool sizes (0x10000 and 0x23000), and a pool above 32 bits (0x123456000) and a pool of 0 are reported unchanged.
    • A terminated context returns ERROR_INVALID_ID while the other is unaffected, and ERROR_BEFORE_INIT comes back after the last sceHttpTerm.
    • A null pointer throws with a valid and with an invalid id. No error writes into the sentinel-filled output or the 16 bytes after it.
  • The test fails on main, where the call throws. Storing a constant pool size, not dropping it on sceHttpTerm, or skipping the ERROR_BEFORE_INIT check makes it fail.
  • All three tests matching http pass.
  • Updated to main 524398151f. The branch adopts main's declaration and 24-byte struct. The test now checks that nothing past those 24 bytes is written; writing a reserved word after them makes it fail. All 4 guest_http tests pass.
  • tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py finds no conflicting lines. It could not compare #6044 (test reorganization), which conflicts with main. The branch also merges cleanly with #8245, which reworks the HTTP options in the same file.

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: #9630
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4934743855 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8357). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-10-20T10:58:45Z. --- ### What `sceHttpGetMemoryPoolStats` threw `not implemented`, and its debt entry listed the signature as unknown. [SharpProspero `Http.cs`](https://github.com/SvenGDK/SharpProspero/blob/5dfdb4b0b166e83dc9ae275001afb695f12c7174/src/SharpProspero/Interop/Net/Http.cs#L744-L746) documents it as `int sceHttpGetMemoryPoolStats(int httpCtxId, SceHttpMemoryPoolStats* currentStat)`, which reads a context's pool use. The [struct](https://github.com/SvenGDK/SharpProspero/blob/5dfdb4b0b166e83dc9ae275001afb695f12c7174/src/SharpProspero/Interop/Net/Http.cs#L398-L413) holds the pool size, the peak and current use, and a 32-bit reserved word. `main` has since declared the struct as those three 64-bit fields (24 bytes) in `fix(http): recover request metadata and memory stats signatures`, so only those 24 bytes are written and the reserved word is left to the caller. `sceHttpInit` now keeps the pool size it is given for each context, and `sceHttpTerm` drops it. The call: - **Live context:** writes `{pool size given to sceHttpInit, 0, 0}` and returns 0. The library takes nothing from the guest pool, so both use figures are 0; Http2 and NpWebApi2 already report their pools this way. - **No live context:** returns `ERROR_BEFORE_INIT` (`0x80431001`) without writing. - **Unknown or terminated id:** returns `ERROR_INVALID_ID` (`0x80431100`) without writing. Both errors and their order follow `sceHttpCookieFlush`. - **Null `currentStat`:** throws, as the console's error for it is unknown. It is checked first, as Http2 does. The debt entry records that nothing here is measured on a console and that a console already uses part of the pool for a live context. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, full build with `BUILD_TESTING=ON`. Windows was not compiled. No title was run. - `guest_http`: - Before any `sceHttpInit`, ids 0, -1 and a request id return `ERROR_BEFORE_INIT`. - With a live context, ids 0, -1, `INT32_MAX` and a request id return `ERROR_INVALID_ID`. Two live contexts report their own pool sizes (0x10000 and 0x23000), and a pool above 32 bits (0x123456000) and a pool of 0 are reported unchanged. - A terminated context returns `ERROR_INVALID_ID` while the other is unaffected, and `ERROR_BEFORE_INIT` comes back after the last `sceHttpTerm`. - A null pointer throws with a valid and with an invalid id. No error writes into the sentinel-filled output or the 16 bytes after it. - The test fails on `main`, where the call throws. Storing a constant pool size, not dropping it on `sceHttpTerm`, or skipping the `ERROR_BEFORE_INIT` check makes it fail. - All three tests matching `http` pass. - **Updated to `main` `524398151f`.** The branch adopts `main`'s declaration and 24-byte struct. The test now checks that nothing past those 24 bytes is written; writing a reserved word after them makes it fail. All 4 `guest_http` tests pass. - `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py` finds no conflicting lines. It could not compare #6044 (test reorganization), which conflicts with `main`. The branch also merges cleanly with #8245, which reworks the HTTP options in the same file. ### 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: #9630 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
github-actions[bot] commented 2026-10-20 10:59:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T10:59:27Z.


Progress report (8b3e398 → 73822f3)

📈 System libraries: 43.24% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libSceHttp sceHttpGetMemoryPoolStats
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289347564 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8357#issuecomment-6289347564). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T10:59:27Z. --- <!-- progress-report --> ### Progress report (8b3e398 → 73822f3) 📈 **System libraries**: 43.24% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libSceHttp | `sceHttpGetMemoryPoolStats` | </details>
xXPBSXx commented 2026-10-20 23:33:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T23:33:07Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main 339217ebc9 is clean. I built only guest_http_tests; ctest -N -R guest_http lists exactly one test.

Results (3 runs each):

  • PR head: guest_http passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libSceHttp/Export.cpp with the version from the PR's merge base (777bd0f4b2), then rebuilt. The test fails 3/3 (exit 0xc0000409, a failed Require). I restored the PR's Export.cpp afterwards.

Not run: other platforms, the other Http tests, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6304183220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8357#issuecomment-6304183220). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T23:33:07Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` 339217ebc9 is clean. I built only `guest_http_tests`; `ctest -N -R guest_http` lists exactly one test. **Results (3 runs each):** - PR head: `guest_http` passes 3/3. - Baseline: I kept the PR's test and replaced only `core/libs/prx/libSceHttp/Export.cpp` with the version from the PR's merge base (`777bd0f4b2`), then rebuilt. The test fails 3/3 (exit 0xc0000409, a failed `Require`). I restored the PR's `Export.cpp` afterwards. **Not run:** other platforms, the other Http tests, the full repository CTest, and any title or console run. AI-assisted (Claude Code).
Ondra97 commented 2026-10-22 05:12:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-22T05:12:09Z.


I opened #9630 to fix allocation-failure ownership in HTTP initialization, epoll creation and final-context teardown. Your pool-size registry also adds work to initialization and termination. I propose merging #9630 first, then rebasing this PR and retaining rollback across every context registry. #9630 has no dependency on the pool-stat implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333270396 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8357#issuecomment-6333270396). Originally posted by [Ondra97](https://github.com/Ondra97) on 2026-10-22T05:12:09Z. --- I opened #9630 to fix allocation-failure ownership in HTTP initialization, epoll creation and final-context teardown. Your pool-size registry also adds work to initialization and termination. I propose merging #9630 first, then rebasing this PR and retaining rollback across every context registry. #9630 has no dependency on the pool-stat implementation.
MarrasFederico commented 2026-10-22 08:28:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-10-22T08:28:40Z.


@Ondra97 agreed: #9630 first, then I'll rebase this PR onto it.

You're right about the registry. This PR inserts the pool size before g_contexts.insert, so a later allocation failure in sceHttpInit would leave a stale entry. When I rebase, the pool-size insertion will move inside your rollback: on failure it is erased together with the context and its options. sceHttpTerm keeps erasing it with the context.

I'll note the dependency here once #9630 is merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336321964 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8357#issuecomment-6336321964). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-10-22T08:28:40Z. --- @Ondra97 agreed: #9630 first, then I'll rebase this PR onto it. You're right about the registry. This PR inserts the pool size before `g_contexts.insert`, so a later allocation failure in `sceHttpInit` would leave a stale entry. When I rebase, the pool-size insertion will move inside your rollback: on failure it is erased together with the context and its options. `sceHttpTerm` keeps erasing it with the context. I'll note the dependency here once #9630 is merged.
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!8357
No description provided.