Skip to content

refactor(libs): share the remaining compiled SDK version reads - #26370

Open
Buraddomoon wants to merge 1 commit into
boykopovar:mainfrom
Buraddomoon:refactor/compiled-sdk-version
Open

Buraddomoon wants to merge 1 commit into
boykopovar:mainfrom
Buraddomoon:refactor/compiled-sdk-version

Conversation

@Buraddomoon

@Buraddomoon Buraddomoon commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Route the six remaining read sites enumerated in #26276 through the helper introduced by #26296. AppContent, GnmDriverForNeoMode, Hmd2, Http and Http2 now use ApplicationCompiledSdkVersion() for the 32-bit process-parameter field at offset 0x10. Http2 uses the host helper instead of a guest export, removing its 0x99900000 fallback and unused kernel API include.

Keep the existing local helper names as forwarding functions: in-flight changes such as #24528 call them too. This centralizes the read without renaming their call sites or requiring those PRs first. The SDK field and normal SDK-dependent results are preserved.

Http2 previously substituted 0x99900000 when sceKernelGetCompiledSdkVersion(&version) returned an error, although its destination was a local host-stack variable. The direct helper returns the actual field without that guest-output fallback policy. Parameter discovery can throw for missing or invalid process metadata in both implementations; the helper is not a fabricated-success fallback.

Together with #26296, this completes the 16 readers listed in #26276. The additional readers identified in review in Json2, Ngs2.native, Rtc, Ssl, UsbStorageDialog and kernel Coredump are follow-up scope.

Tested

Linux x86-64, Debian 13 container on Fedora 44, GCC 14.2.0, CMake 3.31.6, Ninja, Release with -O1 -DNDEBUG. Full runtime configuration (BUILD_TESTING=ON), all five affected libraries and the selected test executables built successfully.

  • Exact head 3aec109413b7a30a3db672cc09e90dd71dfb74f0: 74/74 CTests passed, zero skips, in 23.58 s. Selection: guest_appcontent|guest_hmd2|guest_gnm_neo|^guest_http|application_?heap|process_?param.
  • Existing tests exercise AppContent SDK-dependent checks, GNM Neo context-state sizes before/from SDK 4.00, Hmd2 initialization/error paths, HTTP URI rules before/from SDK 1.00, the HTTP socket callback boundary at SDK 1.50, and HTTP/2 gzip content lengths on older/newer SDKs. The HTTP transports use local loopback servers.
  • Coverage limit confirmed in review: the two Hmd2 SDK branches are unreachable at this head. sceHmd2Initialize always returns UnsupportedFeature, and initialized is never set to true. The passing Hmd2 tests validate the available error paths, not those SDK branches.
  • Optimization review: rebuilt the changed C++ paths with -O3, including the Http2 transport archive, while leaving unchanged dependency builds at -O1. The same 74/74 CTests passed with zero skips on the unchanged head.
  • Compiled all six changed translation units with GCC 14.2.0 at -O3 and compared them with a variant removing the local forwarding functions and calling ApplicationCompiledSdkVersion() directly. objdump -drC instruction and relocation listings match for all six, after normalizing only the temporary object filename and the generated initializer filename. The forwarding functions disappear at this optimization level; retaining their names adds no extra call in this compiler/configuration.
  • The shared reader caches the process-parameter pointer and still loads the SDK field on each call. Caching the SDK value itself would change the existing behavior exercised by the version-switching tests. This code inspection is not a frame-rate measurement.
  • python3 tools/check_conventions.py --base origin/main and git diff --check origin/main...HEAD passed.
  • The author's local runs did not include native Windows/macOS, a console, a GPU or a title. No performance claim.
  • Independent validation reported by Helldiverr: Windows 11 Pro 26300, WinLibs GCC 15.2, Release; 73 selected tests passed on main f784587f30 and on three runs of merge 5952756a06. The reviewer also checked SDK changes between calls and used negative-control/mutation cases for the reachable readers. These are the reviewer's runs, separate from the author's Linux results.

The pre-submission branch overlap check examined 2,541 open PRs and 13 shared-file candidates. It returned exit 2 for #17711, #19525 and the then-current #24528 because they already conflicted with the checked base. After the bot listed 13 unverified comparisons, I manually compared the current heads of all 13 reported PRs against base 2b09db6f11 and this head 3aec109413: #11630, #12056, #16231, #17711, #18954, #19525, #20805, #24528, #24634, #25677, #25731, #25756 and #26229. Eleven merge cleanly with this head. #17711 and #19525 have exactly the same conflict paths and conflict blocks on the base and on this branch. The updated #24528 (81b4bc374f) merges cleanly; retaining the local helper names preserves its added calls. This records manual comparison of the bot warnings, not a clean checker exit or combined runtime qualification of the other PRs.

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 refactor: one helper for the title's compiled SDK version (16 copies in 16 libraries) #26276
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions github-actions Bot added prx fix error Closes an issue (Fixes #N) labels Nov 23, 2026
@Helldiverr

Copy link
Copy Markdown
Contributor

Windows run of 3aec109413. The refactor keeps behaviour: every changed reader still loads the 32-bit field at offset 0x10 on each call, and the 73 selected tests pass three times on the merge. Nothing blocks this. Three notes below, none about a defect in this PR:

Existing runs:

  • the author, Buraddomoon: Linux (Debian 13 container, GCC 14.2.0, Release), 74/74 CTests at the head with the same selection, plus an -O3 rebuild of the changed paths and check_conventions.py --base origin/main.

No reviews or other runs yet, and no Windows run before this one.

What this run adds.

  • A Windows build and run of the author's selection on main and the merge.
  • A check that the cached pointer still sees SDK-version changes between calls.
  • A negative control and 13 mutations of the six call sites and the shared helper.

Code. Line numbers are at 3aec109413 unless marked.

  • The shared helper is ApplicationCompiledSdkVersion() in core/libs/prx/libc/include/ApplicationHeap.hpp:31-36 on main f784587f30. It caches the process-parameter pointer and copies the field at 0x10 (line 34) on every call.
  • The six replaced readers:
    • core/libs/prx/libSceAppContent/Export.cpp:42;
    • core/libs/prx/libSceGnmDriverForNeoMode/Export.cpp:61;
    • core/libs/prx/libSceHmd2/Export.cpp:97;
    • core/libs/prx/libSceHttp/src/Options.cpp:20;
    • core/libs/prx/libSceHttp/src/Uri.cpp:328;
    • core/libs/prx/libSceHttp2/Transport.cpp:91.
  • AppContent, GnmDriverForNeoMode, Http options and Http URI previously looked the pointer up on each call (for example Options.cpp:19-24 on main f784587f30). Caching it is safe:
    • on Windows, ApplicationProcessParameters_nid_no_patch returns a pointer into the main image found through its .procpar section (core/libs/prx/libc/src/ApplicationProcessParameters.cpp:60-90 on main f784587f30), so it does not change for the life of the process;
    • Hmd2 already cached it (Export.cpp:97 on main f784587f30), as does sceKernelGetCompiledSdkVersion.
  • The value is still read on each call. core/libs/tests/GuestHttp.cpp:472-486 on main f784587f30 rewrites the SDK field between sceHttpUriUnescape calls for versions 0, 0xffffff and 0x1000000, and guest_http passes on the merge.
  • Http2 used to call sceKernelGetCompiledSdkVersion(&version) on a local and fall back to 0x99900000 on failure (Transport.cpp:90-93 on main f784587f30). That export fails only for a null pointer or a failed guest copy-out (core/libs/prx/libkernel/SysExports.cpp:38-43 on main f784587f30), and neither can happen for a host stack variable. The fallback was dead code, as the PR body says. Transport.cpp:17 now includes ApplicationHeap.hpp in place of the kernel API header, and the merge builds cleanly.
  • Hmd2's two SDK checks (lines 118 and 252) sit behind initialized. That flag starts false (line 83), is only ever set back to false (line 183), and sceHmd2Initialize returns UnsupportedFeature unconditionally (lines 157-160). Neither check can run until Hmd2 gains a real initialization path. The same holds on main.
  • GnmDriverForNeoMode is a CPU-side SDK version read, not an AGC, shader recompiler or VideoOut change, so I ran no GPU tests.
  • With refactor(libc): read the title's compiled SDK version through one helper #26296, this completes the 16 copies listed in refactor: one helper for the title's compiled SDK version (16 copies in 16 libraries) #26276.

Optional, outside this PR: six more libraries read the same field directly, on main f784587f30:

  • core/libs/prx/libSceJson2/Export.cpp:388-389, behind a null check;
  • core/libs/prx/libSceNgs2.native/src/Render.cpp:396-398;
  • core/libs/prx/libSceRtc/Export.cpp:126-128;
  • core/libs/prx/libSceSsl/Export.cpp:828-830;
  • core/libs/prx/libSceUsbStorageDialog/Export.cpp:25-27;
  • core/libs/prx/libkernel/System/src/Coredump.cpp:36-38.

They could move to the helper in a follow-up. The kernel exports that copy the field out to the guest (sceKernelGetCompiledSdkVersion and sceKernelGetPs4CompiledSdkVersion) should stay as they are.

Negative control and mutation.
Each change was applied to the merge. I rebuilt the affected test executables and ran the matching tests. The tests report failures through fail-fast aborts (0xc0000409) without a line number.

Change Tests run Result
neg-stub-gnm: NotImplemented_nid_no_patch(__func__) before the GnmDriverForNeoMode read guest_gnm_neo (6) caught by guest_gnm_neo_context_state_internal
shared-offset: the helper reads 0x14 instead of 0x10 full selection (73) caught by 10: guest_gnm_neo_context_state_internal, guest_appcontent, guest_appcontent_license, guest_http, guest_http_options, guest_http2_gzip_members, guest_http2_transport, guest_http2_http1_gzip, guest_http2_http1, guest_http2_gzip_content_length
gnm-zero: GnmDriverForNeoMode returns 0 guest_gnm_neo (6) caught by guest_gnm_neo_context_state_internal
gnm-max: GnmDriverForNeoMode returns 0xffffffff guest_gnm_neo (6) caught by guest_gnm_neo_context_state_internal
appcontent-zero guest_appcontent (8) caught by guest_appcontent and guest_appcontent_license
appcontent-max guest_appcontent (8) caught by guest_appcontent and guest_appcontent_license
httpoptions-zero ^guest_http_ (19) caught by guest_http_options
httpoptions-max ^guest_http_ (19) caught by guest_http_options
httpuri-zero ^guest_http$ caught by guest_http
httpuri-max ^guest_http$ caught by guest_http
http2-zero ^guest_http2 (24) caught by 5: guest_http2_gzip_members, guest_http2_transport, guest_http2_http1_gzip, guest_http2_http1, guest_http2_gzip_content_length
http2-max ^guest_http2 (24) caught by guest_http2_gzip_content_length
hmd2-zero guest_hmd2 (3) passes: equivalent, the SDK checks cannot run (see Code)
hmd2-max guest_hmd2 (3) passes: equivalent, the SDK checks cannot run (see Code)

Every reachable call site is pinned by at least one test in both directions, and shared-offset shows that the shared helper is the one actually read.

Tests.

Run Tests Result
main 73 73 passed
merge 1 73 73 passed
merge 2 73 73 passed
merge 3 73 73 passed
merge, check_conventions.py --base main passed
merge, debt_fold.py --check passed

The selection is the author's: guest_appcontent|guest_hmd2|guest_gnm_neo|^guest_http|application_?heap|process_?param. The set differs by platform: for example, the three application_heap_guest_sdk* tests are registered only on Linux (core/libs/prx/libc/CMakeLists.txt:2426 on main f784587f30). The only compiler warning in the merge build is a -Wc++23-extensions warning in libSceAgcDriver, which the main build also prints.

Host:

  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release
  • Commits: head 3aec109413, merged onto main f784587f30 as 5952756a06

AI-assisted: yes

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally (Linux x86-64, GCC 11): libSceAppContent and libSceHttp build cleanly from this branch.

The change replaces six local copies of "read the compiled SDK version from the process parameters at +0x10" with the existing shared helper ApplicationCompiledSdkVersion() from prx/libc/include/ApplicationHeap.hpp, which does exactly the same read. Five of the six sites are behavior-neutral.

One note on libSceHttp2/Transport.cpp: the old code went through sceKernelGetCompiledSdkVersion and fell back to 0x99900000 on error; the new code reads the process parameters directly and has no fallback. Since ApplicationCompiledSdkVersion() is the same source of truth and cannot fail, this is arguably more consistent, but it is a small behavioral difference worth being aware of (the 0x99900000 sentinel path is gone). Not a blocker.

Deduplicating onto the shared helper is the right direction. LGTM from my side.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 11630 core/libs/prx/libSceHttp2/Transport.cpp
PR 12056 core/libs/prx/libSceHttp/src/Uri.cpp
PR 16231 core/libs/prx/libSceHttp2/Transport.cpp
PR 19525 core/libs/prx/libSceHmd2/Export.cpp
PR 20805 core/libs/prx/libSceHttp/src/Uri.cpp
PR 24528 core/libs/prx/libSceHttp/src/Options.cpp
PR 27611 core/libs/prx/libSceHttp2/Transport.cpp
PR 27638 core/libs/prx/libSceHttp2/Transport.cpp

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 24, 2026
@Buraddomoon

Copy link
Copy Markdown
Contributor Author

@Helldiverr, following up on the six additional SDK readers you identified: the remaining Json2 and kernel coredump readers are in #26637 (head ca4412dd99). Ngs2.native, Rtc and Ssl already landed in #26590, and UsbStorageDialog in #26576.

The follow-up preserves Json2's UINT32_MAX fallback and failure latch, and coredump's SDK snapshot at handler registration. Its fixture updates the SDK field in the parameter buffer directly while keeping independent SDK 5/6 expectations and every existing assertion.

Validation: 210/210 focused CTests passed on the base and again with the changed production paths at -O3, with zero skips. Conventions and whitespace passed; the branch overlap check reported no overlap across 2,518 open PRs.

I also checked GCC 14.2.0/Linux -O3 output: the shared reader is inlined at both changed sites, and the initialized read has no extra helper call, memcpy call or repeated process-image lookup. The lazy-cache guard flag is still checked; guard acquisition/release is confined to initialization. A temporary instrumented copy of the SDK 5/6 kernel-initialization fixture passed against both original and updated readers, recording 128 parameter-discovery calls for the original and 1 for the follow-up. The field is still read afresh, rather than caching the SDK value. This is code-generation and lookup-reuse validation, not a title performance claim.

AI-assisted: yes.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; its six reader paths now delegate to the shared SDK-version helper while preserving the existing helper names and SDK-dependent call sites.

What I ran

Reviewed head 3aec109413b7a30a3db672cc09e90dd71dfb74f0 using the prepared diff and pinned repository reader. No build or test commands were run by me; the test results below are author-reported.

Files read: description.md, commits.md, manifest.json, diff.patch, ApplicationHeap.hpp, and the changed source ranges in Export.cpp, Options.cpp, Uri.cpp, and Transport.cpp for all six changed files. All six changed files are listed as included in the manifest. No files were excluded by the manifest.

Results

Check Result Note
Diff and source review passed Six changed files inspected
Author-reported Linux tests not run 74/74 CTests reported passed
Author-reported Windows validation not run Reported separately in the description
Build, native console, and performance measurement not run No local execution

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run the reported tests or builds, verify native Windows/macOS behavior, or measure behavior on a console, GPU, or title. The description reports Hmd2 SDK branches are currently unreachable; I did not independently verify that coverage claim. The description also reports the other reviewers' test runs; those were not run by me.

To get this to a good state

Nothing is required.

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiled the exact shared SDK helper into a Linux fixture. It read the compiled SDK field while ignoring the adjacent Prospero field, and a second call saw a value change without redoing the process-parameter lookup. I checked the call sites against the previously used offset. This run covered the shared helper.

AI-assisted: yes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix error Closes an issue (Fixes #N) needs rebase Conflicts with main, rebase needed prx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: one helper for the title's compiled SDK version (16 copies in 16 libraries)

5 participants