feat(libSceHttp2): bind cookie boxes to templates and requests #11950
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11950"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-10-27T13:46:51Z.
What
On
main,sceHttp2GetCookieBoxthrows for every call, and since #10167sceHttp2SetCookieBoxthrows for any nonzero box (the second negative control below). Ball X Pit (PPSA31872) binds a cookie box at start-up and stops about 10 s in withsceHttp2SetCookieBox not implemented(runs below). Before #10167 the call returned 0 and the title reached gameplay onmain(#8966).This binds cookie boxes as an emulator run of firmware 13.42's
libSceHttp2.sprxdoes:sceHttp2SetCookieBox(id, box)accepts a template or a request and a live box or 0 (unbind). Contexts, unused ids and unknown, deleted or other-kind boxes return 0x817B1100.sceHttp2GetCookieBox(id, int*)returns 0x817B1225 for a null output (before checking the id), otherwise writes 0 and returns 0x817B1100 for an invalid id, 0x817B1025 when no box is bound, or 0 and the box id. It writes 4 bytes.A request with a bound box now sends the box's matching cookies in a
cookiefield and stores eachSet-Cookieof the response in the box, using the store's existing matching and parsing (shared withsceHttp2GetCookieandsceHttp2AddCookie). That part is not measured: the run cannot reach the network, so it is recorded in the debt entry.The HTTP/1.x path of #11611 does the same. This part is JJenkx's work: their commit a73753f129 is
d6a8038853here, with JJenkx as its author. B-Howell found the gap (comment) and tested JJenkx's commit on Windows and Linux (report). Thank you both. Box cookies are chosen by the request URL's scheme, sent together with any added withsceHttp2AddRequestHeaderin oneCookiefield as RFC 6265 section 5.4 describes, and each responseSet-Cookieis stored in the box. Before it, an HTTP/1.x request on a template with a bound box sent and stored no cookies. This is not measured on a console either; thelibSceHttp2 cookie transportdebt entry records it.The transport reads and stores those cookies while it holds the request's state mutex, and deleting a request holds the handles mutex while it waits for that state mutex. To avoid that deadlock, the cookie module keeps its own record of live boxes (added by
sceHttp2CreateCookieBox, removed bysceHttp2DeleteCookieBox), and a box lookup no longer takes the handles mutex. The third negative control below shows the delete hanging without it.Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release,
BUILD_TESTING=ON, onmain2ee8e9751a:guest_http2,guest_http2_cookies,guest_http2_options,guest_http2_transport,guest_http2_early_response,guest_http2_dns_firstandguest_http2_teardownpass, three runs each.guest_http2covers the binding cases above. Two newguest_http2_transportscenarios: one binds a box holding one cookie, checks that the loopback server receives it, and that the server'sSet-Cookielands in the box; in the other the server answers with 1500Set-Cookiefields, and once the first is in the box another thread deletes the request, which must return within 2 s.guest_http2_transportalone also passes ten runs out of ten, 3.1 s each.Transport.cpp,Cookies.cppandCookies.hppput back tomain's version andExport.cppto this PR's first commit (tests kept),guest_http2_transportfails in all three runs atbox cookie sent. With onlymain'ssceHttp2SetCookieBoxbody put back,guest_http2andguest_http2_transportfail in all three runs withsceHttp2SetCookieBox not implemented. With the library files of this PR's first commit, where a box lookup took the handles mutex (tests kept), the delete does not return in all three runs.tools/check_conventions.py --base upstream/mainpasses.d6a8038853(with JJenkx's HTTP/1.x commit), Windows 11, WinLibs GCC, Release:ctest -R '^(guest_http2.*|public_headers)$' --repeat until-fail:3passes 13 of 13, including the newguest_http2_http1_cookies. WithTransport.cppfrom the previous head760eba6585and the tests kept,guest_http2_http1_cookiesfails atHTTP1 exactly one cookie header.check_conventions.py --base upstream/mainpasses on the committed head. Results: comment.Ball X Pit (PPSA31872 01.301.000), RX 9070 XT, two runs each:
main62b3ba2522: stops 6 and 10 s in withsceHttp2SetCookieBox not implemented.62b3ba2522: passessceHttp2SetCookieBoxand stops 7 and 13 s in atsceHttp2SetRedirectCallback not implemented, which #11575 implements.8ff4baf534with #11611 (which contains #11575 and #11586) and #11134 merged, plus a local change of #11611'ssceNetRecv/sceNetSendcalls tosceNetRecvfrom/sceNetSendtoso its library builds on Windows (and two diagnostic prints in its TLS path): both 300 s runs reach the in-game base screen (tutorial prompt), about 35 presents per second. The title's request goes toscript.google.com(its translation download).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-29T04:09:27Z.
Review: APPROVED
Reviewed — approved
On Linux the change merges cleanly and builds, all
guest_http2*tests pass in 5 of 5 runs, and three negative controls (the binding, the transport cookie path, and the lock-order fix) each makeguest_http2_transportfail at the expected check.What I ran
Head
bbef95bb6827e55fd2abe6c9305bbf6da9f51c47merged with--no-ffontomainb433c40f2f46aa2e59e19806010a839ac8572d64(clean) in a clean worktree. Arch Linux 7.2.11-zen, GCC 16.2.1, Release, Ninja,BUILD_TESTING=ON, Intel Core i9-14900KF.Results
maingit diff --checktools/check_conventions.py --base origin/mainAll conventions checks passed.libSceHttp2--target libsguest_http2,guest_http2_cookies,guest_http2_options,guest_http2_transport,guest_http2_early_response,guest_http2_system_roots,guest_http2_teardownguest_http2_transportdurationctest, merged tree, 5 repeats
guest_http2_dns_firstis only registered on Windows, so it did not run here.Negative control
All three controls keep the PR's tests and change only library files:
libSceHttp2sources frommain.guest_http2_testsdoes not compile (too many arguments to function 'int sceHttp2GetCookieBox()'), as B-Howell reported.guest_http2_transport_testsdoes compile, and fails in the new scenario atHTTP2 cookie box scenario/what(): sceHttp2SetCookieBox not implemented.Transport.cppfrommain. Fails atHTTP2: box cookie sent, so the test covers the request-sidecookiefield.Cookies.cpp,Cookies.hppandExport.cppfrom the first commit96603d9851, whereFindBoxstill went throughHttp2CookieBoxExistsandg_handlesMutex. Fails atHTTP2: delete returns while the transport stores response cookies. This confirms the lock-order inversion that oneandonlydean reported and shows the newCookieBoxDeletescenario catches it on this host. With the head's files restored, the scenario passes in every run above.Findings
Blocking
None.
Non-blocking
None.
Notes from reading the code:
g_cookiesMutexwhile it holds the request state mutex (Transport.cpp L413, L490). The delete paths holdg_handlesMutexand wait for the state mutex. No path now takes another lock while it holdsg_cookiesMutex:FindBoxonly readsg_cookieBoxes.sceHttp2CreateCookieBoxandsceHttp2DeleteCookieBoxcallHttp2AddCookieBoxandHttp2ForgetCookiesoutside the handles lock (Export.cpp L348-L374). The resulting order (handles, then state, then cookies) has no cycle.Address()buildshttps://+ authority + path, and the path includes the query. The cookie module'sParseUrldrops?/#and the port, so default paths and domain matching use the bare host and path.Updatethrows once a transport exists. So the box the transport sees cannot change during a send. A box deleted while a request still holds its id is no longer ing_cookieBoxes, and handle ids are never reused, so that request sends and stores nothing.Not verified
guest_http2match the description.main.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T20:15:59Z.
Review: APPROVED
Re-checked — approved
Since my last review the branch only gained merges of
main(77c3d1d379,8a5f9e2706,cbbf248943). The two feature commits did not change. The merged tree passes the checks and the focused tests, and the negative control still fails where it should.What changed since my last review
96603d9851andbbef95bb68are unchanged. The new commits are three merges ofmain. In those merges the author resolved conflicts inTransport.cpp(theCookies.hppinclude and theset-cookieline next tocontent-encoding) and inGuestHttp2Transport.cpp(theModeenum).mainnow follows redirects (guest_http2_redirects). The cookie code works with it:Address()is rebuilt fromstate->url, which is replaced for each hop (Transport.cpp L748-L760). So each hop sends the box's cookies for its own URL (L619-L621), and stores the redirect response'sSet-Cookieunder the URL that answered (L536). The PR's tests do not combine a bound box with a redirect.What I ran
Head
cbbf2489436ffbd22510b4a8a763a141cb3b3779merged with--no-ffontomain096c45570f516de76a43bbe1b97781381c84f55f(merged tree8cc1d94dce13aaa0fefd2d7280f0d9fb33ba9674) in a clean worktree. Debian 13 VM (32 vCPU, Xeon Gold 6136), GCC 14.2.0, Release, Ninja,BUILD_TESTING=ON.git diff --checkcheck_conventions.pyAll conventions checks passed.libs, selected tests (793)unwrap_selfalso fails onmain. Twomain_sync_renames_*tests fail on the baseline and now pass; they are unrelated to this PR.guest_http2,_cookies,_options,_transport,_early_response,_system_roots,_redirects,_teardownguest_http2_transporttakes about 8 s andguest_http2_redirectsabout 13 s, both under the 30 s limit.Transport.cppfrommain)HTTP2: box cookie sent, as expected.guest_http2_transportpasses, andgit status --porcelainis empty.Previous findings
My previous review had no blocking or non-blocking findings.
mainhas no HTTP/1 transport inlibSceHttp2/Transport.cpp, so this PR has no HTTP/1 path to cover yet. The gap would appear when this PR and #11611 are both merged. As B-Howell suggested, whichever of the two lands second should carry the bound box intoSendHttp1. JJenkx's follow-up commit is aimed at that case. I did not review that commit.New findings
Blocking
None.
Non-blocking
None.
Not verified