Skip to content

Sync: upstream's NRO header fix replaces the fork's, and the patchers fit seedds main again (the nightly sync stops on test_nro_header.py) - #115

Closed
v0lumehi wants to merge 2 commits into
LNPANDY:mainfrom
v0lumehi:sync-nro-fix
Closed

v0lumehi wants to merge 2 commits into
LNPANDY:mainfrom
v0lumehi:sync-nro-fix

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Rebased onto main after #101 and Andy's 607b5da / 1c3acc7 ("keep OURS files when upstream adds its own, and read the daily-health shape right").

What Andy's commits already cover (not repeated here): the OURS skip for a file upstream also adds, the daily-health deletion-of-a-file-not-in-old fix in unprotected_edits, the MAIN_M_ROMFS anchor and no-game-data hunk for the romfs.id identity check, and the line-start anchor of the slim mapping. What main still lacked: against current seedds main (6c4a81d, which moved after his commits) the sync and test_sync_patchers.py still failed on hle_fs.c (#513 handles), build_ipa_from_nsp.py (the pwd import anchor) and patch_nso.py (seedds' #451 reworked the text scan, so the fork's NRO patcher no longer applies). Because the fork's NRO patcher cannot apply any more, keeping test_nro_header.py as OURS would test code that no longer exists, so this PR keeps dropping the NRO fork files (upstream's fix covers the same bug, see Cause) instead of Andy's OURS skip. The main.m identity handling and the unprotected_edits change below overlap his work and rebased without conflict; verified on the rebased branch.

Verified on the rebased branch against seedds/main 6c4a81d: sync_upstream.py --old $(cat .upstream-ref) --new seedds/main with the host build and host unit tests: SYNC OK; python3 -m unittest scripts/tests/test_sync_patchers.py: 8 tests OK.

Fixes #104 and #105. Unblocks #109 (points 2 and 3): upstream main already has the "Game language" launcher row and launcher.json for --platform mac-app, but the fork never received them because the nightly sync stops.

Cause

The nightly sync stopped at upstream writes over a fork file: dm/tools/tests/test_nro_header.py. The fork carried its own NRO header skip (patch_nso.py code_start/code_ranges, a lo bound in nso_code.py, and test_nro_header.py in OURS). It was sent upstream as seedds/nxnative#397 and closed as superseded: upstream fixed the same bug itself in 3e77816 (FFX/X-2, #14), 7e0f597 and 337186c.

I checked that upstream's fix covers the fork's: nso_code.data_blocks() starts at 0x80 for an NRO and returns the header past its first two words as a data block, so CODE_RANGES holds no code before 0x80 and the scans (func_of included) cannot enter the header. Its test covers both the build ID decoding as ldr x18 and a br x18 before the first FDE. Nothing of the fork's fix is missing, so no residual patcher is kept.

What changed (scripts/sync_upstream.py, scripts/tests/test_sync_patchers.py)

  • NRO: patcher patch_patch_nso, its marker and the OURS entry for test_nro_header.py are gone. patch_nso.py, nso_code.py and test_nro_header.py are in DROPPED with the reason, so upstream's versions win.
  • Once that was out of the way, the sync stopped at four more places, because seedds main moved after the last sync. All four fit seedds main and still fit the last sync base (test_the_patchers_fit_the_last_sync_base):
  • test_the_patched_makefile_uses_one_compiler_spelling: a line the patcher only appended to keeps upstream's spelling (upstream's own t_resolution rule says clang, not $(CLANG)).

Local run

In a scratch worktree of this branch: sync_upstream.py --old $(cat .upstream-ref) --new seedds/main (6c4a81d) with the host build: SYNC OK, all 30 patchers applied and agree with the tree, every .py parses on 3.9, build_ipa.sh passes bash -n, host build OK (01006F8002326000). Upstream's test_nro_header.py passes on the synced tree. python -m unittest scripts/tests/test_sync_patchers.py: 8 tests OK.

Health check (#105)

All files in its list are classified below; none holds a fork change, so nothing needs a patcher or OURS entry. The list is a false positive of daily-health.yml, which runs sync_upstream.py --old "$NEW" --new "$NEW": with the base set to upstream's tip, every file the fork does not have yet (new upstream files) reads as "deleted/edited in the fork and changed by upstream". With the real base (.upstream-ref) the sync reports no such file. The second commit fixes the workflow: the dry run now passes --old the real base (.upstream-ref, falling back to the tip when the file is missing, as the sync workflow does) and fetches upstream's full history so that base commit exists.

Files (from #105) Fork state Classification
dm/host/motion_{apple,fusion,pro,pro_mac}.h, dm/host/tests/t_motion*.{c,m} absent in fork and in the last base new upstream files, upstream added
dm/mac/Launcher.swift, dm/ios/Sources/LauncherRow.swift, dm/ios/tests/launcher_layout_check.swift, docs/launcher.schema.json absent new upstream files
docs/frontends.md, dm/tools/docs_gallery.py, docs/images/gallery.tsv, 10 docs/images/*.png/jpg absent new upstream files
dm/gfx/tests/{t_missing_src1,t_pso_stall,t_queue_origin}.m, test_{shader_split_progress,unity_2017,unity_pairs,vbf}.py, dm/gfx/tools/vbf.py absent new upstream files
dm/sanitizers/{ignorelist.txt,sanitizers.mk,tsan.supp}, dm/tools/tests/test_ci_toolchain.py, dm/games/0100E95004038000/smoke.tsv absent new upstream files

Across the whole git diff seedds/main HEAD the same way: 202 files absent in the fork (new upstream), 225 equal to the last base (upstream is newer), 47 fork-only files, and 34 files that differ from the base, all of which are in PATCHED or DROPPED (the 34 include hle_time.c, t_time.c, nso_code.py and patch_nso.py, which are DROPPED with their reasons). test_no_fork_edit_is_unprotected passes.

… fit seedds main again (the nightly sync stops on test_nro_header.py)

The fork's NRO header skip (patch_nso.py code_start/code_ranges, nso_code.py lo bound, its own
test_nro_header.py) is dropped: upstream fixed the same bug itself in 3e77816 (FFX/X-2), 7e0f597 and
337186c (nso_code.data_blocks starts after the 0x80 header and reports it as a data block), so
upstream's three files win (DROPPED, not OURS).

The patchers behind it that stopped on seedds main now fit it, and still fit the last sync base:
- hle_fs.c: handles reach the guest shifted by FH_OUT (LNPANDY#513); the archive handle's tag moves to bit 57
- main.m: upstream's romfs.id identity check (LNPANDY#493) is carried through the per-game romfs_locate
- build_ipa.sh: upstream has the ad-hoc entitlements and DM_COPY_ROMFS itself (LNPANDY#478, LNPANDY#493), so only the
  fork's slim-by-default (DM_FULL_ROMFS) and add-on content rule remain
- build_ipa_from_nsp.py: the pwd import follows upstream's errno; rmtree takes upstream's hook, with
  the Python 3.9 spelling (onerror)
test_sync_patchers: a line the patcher only appended to keeps upstream's compiler spelling.
LNPANDY added a commit that referenced this pull request Oct 28, 2026
Sync: the nightly sync works again, carrying v0lumehi's repair from #115
@LNPANDY

LNPANDY commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Merged as #127, the PR's tree unchanged — thank you. A textual merge against main conflicted inside the same GetFileSize hunks both of us had rewritten, so I took your three files as they are and verified: both patcher suites pass against seedds main 062cd06 and against the last sync base, and the dry sync reaches SYNC OK.

Your call to drop the fork's NRO patcher is right: upstream's data_blocks() fix covers the same bug, and keeping an OURS test for code that no longer exists would only confuse the next reader. The FH_OUT/FH_IN bit-57 rework and the double-signing removal are the kind of thing only someone who reads upstream's diffs catches. Co-authored-by is in the commit.

@LNPANDY LNPANDY closed this Oct 28, 2026
v0lumehi pushed a commit to v0lumehi/NX2Apple that referenced this pull request Oct 28, 2026
…ied as a merge that keeps its tree

PR LNPANDY#115 is the complete version of the sync repair: it drops the fork's
NRO patcher because upstream fixed the same bug itself (3e77816,
7e0f597, 337186c - their data_blocks() starts an NRO's code at 0x80
and their test covers both cases the fork's did), reworks the archive
handle tag to bit 57 for seedds LNPANDY#513's FH_OUT/FH_IN shift, stops the
double ad-hoc signing build_ipa.sh would get now that upstream carries
the entitlements itself, follows the new pwd/errno anchor, and makes
the daily health check use the real .upstream-ref base (issue LNPANDY#105).

A textual merge against main conflicted inside the same GetFileSize
hunks both sides had rewritten, so the three files are taken from the
PR's branch as they are. Verified here: both patcher suites pass
(against seedds main 062cd06 and against the last sync base), and
--old 75065df --new seedds/main --skip-build reaches SYNC OK.

Co-authored-by: v0lumehi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upstream sync failed at 712eb81

2 participants