Skip to content

Loader: the image the game's module sections are read from can be set - #729

Closed
v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:route-c-loader-header
Closed

v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:route-c-loader-header

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The iOS loader reads the game's embedded module sections from a fixed &_mh_execute_header (map_image() and nro_pieces() in dm/host/loader.c), so they have to be linked into the app executable. An embedder that links them into another image of the app, for example a framework it dlopens from its signed bundle, has no way to say so.

This adds dm_set_game_image_header(const void *mh) (dm/host/loader_image.h). IMAGE_MH reads it, and unset it is still &_mh_execute_header, so every existing build behaves exactly as before. The host's own tables (__DATA,swforce in force_init(), __DATA,swhle in hle.c) stay the executable's. Nothing calls the setter in this PR.

It is the loader half of an opt-in DM_FRAMEWORK=1 packaging mode (the game's modules in DmIOS.app/Frameworks/DmGame.framework, which the app dlopens). That mode is carried in LNPANDY/NX2Apple#144 for now, and it comes here as its own PR once the run time profile (#492) is settled, because it ships the profile inside the framework. The setter is useful on its own, so it comes first. The change is by @LNPANDY, taken over from that PR.

Checked

  • Tests: make -C dm/host/tests GAME=010015100B514000 run passes, including t_nro and t_symbols, which compile loader.c. python3 dm/tools/lint_python.py: 0 new findings (no Python touched).
  • Games run, with title ID and version: none. The default path is unchanged by construction (the macro's fallback is the old expression), and the iOS build runs through compile_check.py in the follow-up PR.
  • Devices and OS: none.
  • Regress report: not run, no behaviour change on any path that sets nothing.

Docs

  • No finding to record (no symptom or game note)
  • No chain tool touched
  • No game files, keys or data extracted from a game in the change or the attachments

The iOS loader reads the game's embedded module sections (__TEXT,__dm<mod>x0, __DM<mod>W,__img, __TEXT,__dm<mod>x1 and the
packed NRO sections) from a fixed &_mh_execute_header, so they must be linked into the app executable. An embedder that links
them into another image of the app (a framework it dlopen()s from its signed bundle) had no way to say so.

dm_set_game_image_header() (loader_image.h) names that image's mach header. IMAGE_MH, used by map_image() and nro_pieces(),
reads it, and unset it is still &_mh_execute_header, so every existing build behaves exactly as before. The host's own tables
(__DATA,swforce in force_init(), __DATA,swhle in hle.c) stay the executable's. Nothing calls the setter in this change.

Checked: make -C dm/host/tests GAME=010015100B514000 run (includes t_nro and t_symbols, which compile loader.c), and
lint_python.py (no Python touched, 0 new findings).
v0lumehi added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 30, 2026
The loader's settable image header is forwarded as seedds/nxnative#729. The game framework, its build, tests and env switch row are fork-only until the runtime profile (seedds/nxnative#492) is upstream, because the framework carries profile.tsv and main.m sets DM_PROFILE.
v0lumehi added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 30, 2026
The loader's settable image header is forwarded as seedds/nxnative#729. The game framework, its build, tests and env switch row are fork-only until the runtime profile (seedds/nxnative#492) is upstream, because the framework carries profile.tsv and main.m sets DM_PROFILE.
v0lumehi added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 31, 2026
The loader's settable image header is forwarded as seedds/nxnative#729. The game framework, its build, tests and env switch row are fork-only until the runtime profile (seedds/nxnative#492) is upstream, because the framework carries profile.tsv and main.m sets DM_PROFILE.
v0lumehi added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 31, 2026
The loader's settable image header is forwarded as seedds/nxnative#729. The game framework, its build, tests and env switch row are fork-only until the runtime profile (seedds/nxnative#492) is upstream, because the framework carries profile.tsv and main.m sets DM_PROFILE.
v0lumehi added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 31, 2026
The loader's settable image header is forwarded as seedds/nxnative#729. The game framework, its build, tests and env switch row are fork-only until the runtime profile (seedds/nxnative#492) is upstream, because the framework carries profile.tsv and main.m sets DM_PROFILE.
v0lumehi added a commit to LNPANDY/NX2Apple that referenced this pull request Oct 31, 2026
The loader's settable image header is forwarded as seedds/nxnative#729. The game framework, its build, tests and env switch row are fork-only until the runtime profile (seedds/nxnative#492) is upstream, because the framework carries profile.tsv and main.m sets DM_PROFILE.
seedds added a commit that referenced this pull request Nov 2, 2026
…#729)

The iOS loader reads the game's embedded module sections from a fixed &_mh_execute_header, so they
must be linked into the app executable. An app that links them into another image, a framework it
dlopens from its signed bundle, had no way to say so.

dm_set_game_image_header (front.h, iOS only) names that image's mach header, before
dm_host_preload_start. map_image and nro_pieces read it, and unset it is the executable, so every
existing build behaves as before. Nothing in this repository calls it; docs/frontends.md lists it.

Co-authored-by: LNPANDY <[email protected]>
Co-authored-by: v0lumehi <[email protected]>
@seedds

seedds commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thanks. Landed as 694ea91, with @LNPANDY and @v0lumehi as co-authors. The name and the behaviour are the same, with these changes:

  • The setter is iOS-only and sits inside the TARGET_OS_IPHONE branch. The Mac loader reads files, so there it would have done nothing; now that misuse is a link error.
  • It is declared in front.h next to dm_host_preload_start, which it has to run before, so loader_image.h is gone.
  • The comments describe only the contract: DM_FRAMEWORK and DmGame.framework don't exist in this repository, and where the host's own tables live may change with Run a game from a library loaded at run time (one app, many games) #926.
  • docs/frontends.md lists it.

t_nro and t_symbols build the Mac path, so they never compile IMAGE_MH; compile_check.py and build_smoke.py cover the iOS build here. Nothing in this repository calls the setter, so it was not run here. An unreferenced setter is absent from the smoke app, most likely dead-stripped, so an app must call it directly rather than find it with dlsym.

This doesn't decide #492 or #926.

@seedds seedds closed this Nov 2, 2026
Fbenhaddou pushed a commit to Fbenhaddou/NX2Apple that referenced this pull request Nov 2, 2026
Drop 0045 and 0052 (landed upstream as seedds/nxnative#729 and LNPANDY#742), refresh 0053 and the route C patches for the setter now declared in front.h, mark the runtime profile patches as declined in seedds/nxnative#492, regenerate the gallery.
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…seedds#729)

The iOS loader reads the game's embedded module sections from a fixed &_mh_execute_header, so they
must be linked into the app executable. An app that links them into another image, a framework it
dlopens from its signed bundle, had no way to say so.

dm_set_game_image_header (front.h, iOS only) names that image's mach header, before
dm_host_preload_start. map_image and nro_pieces read it, and unset it is the executable, so every
existing build behaves as before. Nothing in this repository calls it; docs/frontends.md lists it.

Co-authored-by: LNPANDY <[email protected]>
Co-authored-by: v0lumehi <[email protected]>
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.

3 participants