feat(libSceJson2): implement allocator-backed values and recovery #10378
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10378"
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 kyon-eth on 2026-10-23T20:04:19Z.
What
Implement allocator-backed Json2 values, object trees and iterators, auxiliary callback records, recovery fallbacks, and initialization resources. Preserve allocation ordering, partial failure states, ownership, callback precedence and retry behavior instead of using host-only storage or fabricated success results.
Implement 73 of the 74 inventory exports introduced by #9517. The remaining base allocator deleting destructor deliberately traps and stays explicitly unsupported. Correct member/callback signatures, setter return declarations, special-float settings and SDK-dependent storage behavior. Document remaining unsupported cases in the library debt file.
Expose the four read-only Boolean, signed-integer, unsigned-integer and real fallback objects and the three writable String, Array and Object fallback pointers. The pointers are published after construction, used by getters and initialization admission, and consumed and cleared during cleanup. When a getter reaches its default path, it returns the corresponding exported object's address; successful callback replacements retain their own addresses. These data NIDs also occur in
libSceJson; this branch defines them inlibSceJson2, and independently loaded provider resolution remains separate.Original prerequisites #10212, #10353 and #8530 have merged into main. This branch retains their String/Array assignment and parser-cleanup regressions. There is no remaining landing dependency on those PRs.
Preserved the String overload cases from #10212 and the deep-copy/source-independence/self-assignment regression from #10353. Two String expectations are deliberately corrected: out-of-range
atreturns zero, and a null C-string needle is empty. Existing String boundary regressions cover those contracts. Array assignment keeps the SDK-dependent allocator ordering and partial-failure behavior covered by the allocator tests. The current debt file retains applicable limitations instead of restoring obsolete pending-export declarations.Integrated #8530 in the agreed order. Array parsing continues to admit an owned placeholder through
AppendArraybefore parsing its payload. Its expanded buffer/callback, malformed/nested, long-key and missing-key checks are retained, with expectations reconciled to the implemented ABI and measured partial-parser states. Host-allocation counts from the former list storage are not treated as guest-allocation coverage.Other overlap review: #8658 decimal conversion, #9826 placeholder bodies, #6039 debt documentation and #6044 test organization. Same-name matches in #9470 belong to libSceJson, a different module. These are not prerequisites.
Tested
50843f45d9, a fresh macOS x86-64 production-source fixture passed all 202 supported JSON tests, including scalar fallback addresses, writable pointer identity and replacement, allocator-callback publication and initialization rollback. A separate historical callback baseline timed out and is excluded from that supported suite. The four scalar objects were present at distinct read-only addresses and the three pointer symbols were exported as writable data in the linked fixture. No patched guest-import, Linux or Windows execution was performed on this head.Current-main refresh: merged
556547da71in3a9241afe5, retaining both the existing test links and the new C++23 requirement. The macOS x86-64 production-source fixture passes 202/202 registeredguest_jsoncases; the public-header audit, conventions and whitespace checks pass. The fixture adapts unrelated libc/kernel boundaries; no full product build or new Linux/Windows run is claimed.Current-main validation (2026-10-28): merged main
6a28efaa27inda1fb929eaand reconciled its decimal-underflow fix with this PR's reference-backedParseDecimal, allocator admission andAssignRealpath. The registered decimal-range tests cover signed underflow to zero, subnormals and overflow settings. Rebuilt macOS x86-64 production-source fixture: 202/202guest_jsonchecks pass. Header audit, conventions, whitespace and privacy checks pass. This is a focused fixture with unrelated libc/kernel boundaries adapted, not a full product build.Current-main validation (2026-10-27): integrated main
9ae2f7d22ain34632912cf. All 202/202 supported Json2 CTest cases pass in the rebuilt macOS x86-64 production-source fixture. The fixture now also compiles the production macOS guest-image lookup required by main; unrelated libc/kernel boundaries remain substituted. Conventions, whitespace and privacy checks pass. The reviewer independently reports both focused Linux ownership/callback-thread cases passing, including a later QEMU TCG run. No complete Linux-suite or Windows runtime pass is claimed; Windowsguest_jsonremains outstanding.Historical integration:
18f7696bd6includes main941ace5f34and merged #8530. The production-source macOS x86-64/Rosetta fixture rebuilt and passed 219/219 registered JSON checks, using production process-metadata lookup. File/mutex and unrelated libc boundaries remain substituted; the unsupported-export adapter uses the production diagnostic format. No full product, Linux/Windows or game run is claimed.Previous public-header integration (
7f0fe1d09b, main2e22b67032): reconciled #10706's public-header migration with the implemented ABI layouts and signatures. All Json2 callers/tests use the canonical declarations; raw parameter/layout fixtures retain explicit ABI casts. Private storage helpers remain outside the exported API through a header-derived linker export list, including the existingString::nposdata symbol.Export.cppfunction bodies are unchanged by this integration. The built module exports exactly the 216 declared API function/data symbols, with no extra private storage helpers.Overlap follow-up: added a bounded guest-allocation sweep for
[1]and malformed[1,parsed into an already owned empty array, through buffer and callback readers. It checks public error propagation, admitted entry ownership, cleanup and retry of the same destination. Existing measured partial-array and nested-parser expectations remain intact. Seven focused parser/allocator/callback checks pass per macOS architecture. This earlier check preceded the combined #8530 validation above. The missing-sentinel refusal remains documented and unsupported.Allocation-failure follow-up on main
c9b2660d56: reproduced the two reported macOS failures with the productionApplicationProcessParameters.cpplookup instead of the earlier null-returning metadata adapter. A missing process-metadata lookup throwsstd::runtime_error; repeatedly constructing that exception can allocate from the host heap while the tests deliberately disable host allocations. Json2 now remembers a failed lookup with an atomic flag and keeps the existing unknown-SDK fallback. Successful metadata queries remain unchanged, preserving SDK-dependent behavior. Main-executable metadata cannot appear later without relinking/restarting the process.Latest review check: the reported PS4 Pro 10.71 measurements corroborate the measured iterator ABI, allocator slots, constructor footprints and Array assignment results. Added the exact
{"a":}case to the existing parser-state regression: parsing returns0x80848101, publicgetType()returns object (7), a later parse succeeds and teardown reclaims the admitted storage. This behavior already worked on this branch; no parser implementation change was needed. These PS4 observations do not establish PS5 console or cross-firmware compatibility.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)Review follow-up: descendant assignment now snapshots aliased payloads before releasing the owning tree; allocation bookkeeping no longer nests the legacy shared recovery mutex under the host state mutex. Public-entry ownership regressions reproduce the old failure. A coordinated legacy mismatch/parser test times out on the old implementation and completes on the fix. Supported Json2 tests pass 202/202 in the rebuilt macOS production-source fixture. Explicitly unsupported throw-pinning tests were removed, while supported rollback, callback exceptions and returning retries remain.
Windows export generation now marks String::npos DATA and retains function exports normally. The real CMake generator produces 216 entries with exactly that one DATA export. This is generation validation, not a Windows runtime rerun. File mocks include the kernel API header and use int descriptors. The vector insertion behind the reported GCC warning was rewritten as equivalent element appends; the independent Linux ASan/LSan report on the prior code found no overflow. No Linux/Windows execution by the author is claimed for this update. Overlapping ancestor/descendant swaps are explicitly unsupported before mutation pending a verified reference contract; partial object-allocation and null-callback-cycle gaps remain documented.
The callback-thread test substitutes the application-heap allocation entry points and kernel mutex primitives; it exercises the real Json2 state locks, mismatch callback and parser. Its five-word SDK fixture supplies only the compatibility SDK query and is not presented as real application-heap metadata. The substitution now also checks that every legacy application-heap allocation is released. The prior implementation still times out with that corrected fixture and the fixed implementation completes. The raw Object descendant setter also has a public-entry regression alongside Array/String/Value assignment.
The Windows CI failure on the previous head reported ambiguous fallback-data references. The seven definitions now use the namespace of their declarations while retaining C linkage. The macOS production-source fixture rebuilds and all 202 registered tests pass; Windows CI passed on head
881f168de66d.Independent platform evidence
Native supported-CPU Windows report validates prior exact head
34632912cf: 202 registered groups, three runs each (606 successes), including theString::npos DATAimport. It closes the previously missing Windows evidence for that head. It predates this main merge; no current-head Windows rerun is claimed. The Linux report on that head also predates this merge and documents an unsupported-CPU guard bypass, so it is not a supported-CPU Linux result.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T20:07:16Z.
Review: CHANGES_REQUESTED
I reviewed the exact head
d88f434966and the declared overlaps. This branch changes the same Json2 exports and shared files as open #10212 and #10353; directgit merge-tree --write-treepreviews conflict inExport.cpp,InventoryExports.cppandlibSceJson2.mdwith #10212, and additionallyGuestJson.cppwith #10353. The checklist is intentionally unchecked for duplicate functions, butDepends on: noneand the description says only that coordination is needed; it does not record an agreed order. CONTRIBUTING requires the authors to agree which overlapping work lands first and list prerequisites. Please coordinate with #10212/#10353 authors, update the dependency/order and keep both branches' distinct tests and debt entries in the final tree. This is a merge-order request, not a conclusion that the broader allocator/recovery work is duplicate or unnecessary. Hosted conventions and labels are still pending, so I have not approved.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T01:22:28Z.
Review: COMMENTED
Linux data point for the
memcpywarning question above, plus a Linux run of the current head.Machine: Linux x86_64, i7-8700 (6 cores / 12 threads, AVX2), Ubuntu 26.04, GCC 15.2, Release,
BUILD_TESTING=ON. Head18f7696bdmerged ontomaine2d457be3(clean).jsontests pass on Linux,guest_jsonamong them (it fails at line 647 on Windows).writing 128 bytes into a region of size 24, inlined fromCheckInheritedMapatGuestJsonLegacyHandlers.cpp:429.guest_json_legacy_handlers_tests(the test TU andlibSceJson2/Export.cpp) with-O1 -g -fsanitize=address, linked against the normallibc.prx/libkernel.prx, and ran all 40 registered argument sets withdetect_leaks=1. That includes the no-argument run that reachesCheckInheritedMap. All exit 0, with no ASan or LSan report. So on this run, the warning looks like a GCC-Wstringop-overflowfalse positive onvector::insertafter the twopush_backs, not a real overflow.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T05:32:04Z.
Review: CHANGES_REQUESTED
The Windows export list still treats
String::nposas a function.include/Api.hppdeclares_ZN3sce4Json6String4nposEas anextern std::size_tdata object (line 93), but theWIN32branch inCMakeLists.txtextracts every_ZN...declaration and writes the names tojson2.defwithout aDATAattribute (lines 8–23). The Windows import library therefore creates a function-style import for this data symbol, and the newguest_jsonassertion reads the import thunk as the value at line 647. This is the reported Windows failure:guest_jsonfails at this assertion, while the other 218 tests pass; the discussion reports that marking data exportsDATAmakes all 222 Linux-style JSON tests pass on Windows.Please generate the
.defentry withDATAfor declarations that are data objects (currentlyString::npos) and retain ordinary function entries for the rest. Then rerun the Windowsguest_jsontest at this head. The current PR checks skip both Windows and Linux build jobs due to path policy, so they do not cover this regression. I could not reproduce the Windows executable locally: the installed MinGW cross-toolchain is missing the required runtime DLL, and the local Linux configure is blocked because SDL2 development files are unavailable.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T05:57:45Z.
Review: CHANGES_REQUESTED
The previous Windows export blocker is fixed in this head: the generated
.defnow marks the data symbolString::nposasDATA. I also builtguest_json_testsand the newguest_json_callback_threads_testsfrom this head on Linux. The existingguest_jsontest passes when I temporarily bypass only this host's unsupported-CPU guard in the isolated review checkout.The new callback-thread test fails before reaching its assertions with
application heap: invalid process parameters. ItsApplicationProcessParameters_nid_no_patch()fixture atcore/libs/tests/GuestJsonCallbackThreads.cpp:13-15returns five zero-initializeduint32_twords with0x05000000at offset 16.ApplicationHeapInitializerequires a process-parameter length of at least0x40and the0x4942524fmagic at offset 8, then reads nested libc and allocator-replacement records. The fixture therefore cannot initialize the application heap, so the test does not exercise the regression it was added to cover. Please provide a valid process-parameter/allocator fixture (or mock the application-heap boundary) and rerun this test.The host CPU guard bypass was confined to the temporary review checkout and has been restored. Without it, the local host (Xeon E5-1620 v2) cannot execute guest tests because it lacks required AVX2-era features. Hosted Linux and Windows product jobs are currently skipped by path policy, so this new test failure is not covered there.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T09:04:20Z.
Review: COMMENTED
Follow-up on exact head
3e03f8df73d6b02e1f1f70e1af86d2fcc259e450:397f3e3ca2: it now mocks the public legacy allocation/deallocation entry points and checks that those allocations balance after teardown.guest_json_callback_threads_testsandguest_json_value_ownership_teststargets on Linux. Both focused CTest cases pass (2/2) after temporarily bypassing only the static host CPU guard in the isolated review checkout; the Xeon E5-1620 v2 host lacks the AVX2-era features required by AnyPS5. I restored the guard and rebuilt the normal library and test executables. The isolated checkout is clean.String::nposexport now carriesDATAin the generated.def, addressing the previous import-thunk defect. The Windows job is skipped by this PR's automatic path filter. I attempted the repository-documented manual full build workflow, but GitHub rejected dispatch with HTTP 403 (Must have admin rights to Repository), so no remote build was started.The targeted Linux changes now pass, but I still cannot independently verify the Windows import at runtime or run the full platform suite here. I am leaving this as a comment rather than approving; a Windows
guest_jsonrun on this exact head would close the outstanding platform check.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T06:57:34Z.
Review: APPROVED
Re-reviewed — approved
Reviewed exact PR head
da1fb929eabd09573783570048a07438fad59f8dagainst currentmainedf6804cf52c62eacafc592dd6142cb4efe5bd05.What I checked
34632912cfb6d6861443eb73be13ad6538582575, every PR-touched file is byte-identical at the current head; the intervening update merges current main.6a28efaa277ca38291ba263aa2774859858161a0. Current main has changed 358 paths since then, with no overlap with the PR's 51 changed paths.git merge-tree --write-tree upstream/main refs/review/upstream-10378: clean treeb041b021928f387c1cd070aad408e02e8c380828.git diff --check upstream/main...refs/review/upstream-10378: pass.python3 tools/check_conventions.py --base upstream/main: pass.Results
34632912cfb6d6861443eb73be13ad6538582575under QEMU after bypassing only this host's unsupported-CPU guard; not rerun on this merge headda1fb929in a production-source fixture34632912cfb6d6861443eb73be13ad6538582575; the PR-touched files are unchanged at the current headNegative control
The author reports the callback-thread regression times out with the previous implementation and completes with the fix. No full negative-control run was reported for the current merged tree.
Findings
Blocking
None. The Windows-specific
String::nposdata export, callback ownership changes, and decimal-range behavior were covered by the reported platform tests. The current-head macOS suite exercises the merged integration; source and test files for this PR are unchanged from the extensive Windows run.Non-blocking
Sources
Not verified
I did not rerun the Linux or Windows suites on the merged head, nor the macOS fixture. Platform results are attributed above to my earlier run or the authors' reports.