feat(host): svcQueryMemory answers for the image module by module, as the kernel does #3167

Merged
HumanBean merged 2 commits from snaildev99/Longshot:mods/query-memory-modules into main 2026-12-05 17:28:40 +00:00
Member

Summary

main builds a mod's code module (exefs/subsdk*) into the game, but answered svcQueryMemory for the whole game
image as one executable region. A mod's code module finds the game's main the way it does on a console: by walking
the memory regions down from its own. With one region the walk meets the loader and gives up, so the module never
finds the game. The SDK's own readers (nn::ro's module header search, nn::diag's backtrace) find a module's start
the same way.

With this change svcQueryMemory answers module by module, as the kernel does: each module's .text read-execute,
.rodata read-only, and .data with the bss read-write, back to back, together spanning the image. The image
builder lists the regions (image::Image::memory_regions), the lift writes them into gen/image.c, A64Image
carries the table (A64_MODULE_ABI 2: the runtime and the game module must agree on its layout), and
host/game_module.c copies it at the load. An address in the image that no region holds gets the whole image, as
before; the stack, heap, system region, output region and free gaps are unchanged. HOS_QUERY_MEMORY_OLD=1 (a kill
switch) answers the one region as before.

This is the part of #984 that main didn't have yet (main already builds the modules in, modules.rs).

Read first: host/hos_svc.c (image_region, query_memory), builder/crates/image/src/lib.rs
(memory_regions), then builder/crates/lift/src/whole/files.rs (image_c).

Testing

Tested: Windows 11 Pro, RTX 3090, NVIDIA 610.88, in the game, built by longshot-builder play --profile with
this PR and the other mod compatibility ports merged, adult Link in Kakariko: HUD of Time and Rupee Counter, two mods
with a code module each, find the game and draw their HUD. The switch both ways, at the same spot after loading the
same save: with HOS_QUERY_MEMORY_OLD=1 (the start's switches line says HOS_QUERY_MEMORY_OLD=1 (kill)) HUD of
Time's clock is gone; unset, it is drawn (13:12, bottom left). On main, with the module built in (Code module subsdk9: built in.), the clock is gone too (screenshots in the comments).
Game-free: tests/test_query_memory.py (the real query_memory over a made-up image: each segment, a mod module's
walk down to main, a hole, the switch both ways, four broken variants) and tests/test_query_memory_free.py, with
llvm-mingw's clang; the lift's image_c_writes_each_modules_regions and the image builder's region tests.

mise run test, run locally while CI's run waits for approval (Windows 11, tests/run_all.py --strict, 12 checks at
once), here @ f4b45e70a and on main @ f577a1aea: 832 passed, 14 failed, 51 skipped here; 820 passed, 25 failed, 51
skipped on main. 13 of the 14 also fail on main: test_cursor_hidden_linux, test_dev_update, test_dlssg_folders,
test_fsr4_tune, test_fsr_uniform_ownership, test_input_background, test_lifter, test_linux_pressure,
test_loaded_modules_drop, test_program_cache_cleanup, test_program_cache_one_variant, test_program_cache_store_record,
test_state_list_give_back. The other, test_fallback_buffer_cleanup, hit its program's 10-second timeout under that
load and passes here run alone (--exact); this PR touches none of the renderer sources it cuts.

Still to test:

  • Linux, any GPU: build the game from this PR and start it to the title screen, expecting it to build and start as
    on main (host code changed) (@Beanstalk)

Measurements

Verdict: Fixed: a code module that walks memory down to the game finds it, and HUD of Time draws its clock, which
it does not on main or with the switch set. Nothing changes per frame: svcQueryMemory looks the address up in a
table of a few regions.

Setup: Windows 11 Pro, RTX 3090, NVIDIA 610.88; the test profile above in Kakariko; the switch set in the launcher's
environment, one run each way, the same save loaded and nothing pressed after.

Before: main @ f577a1aea After: this PR @ f4b45e70a
python -I tests/test_query_memory.py fails (image_region is not in host/hos_svc.c) passes
cargo test -p lift image_c_writes_each_modules_regions 1 failed (image.c has no region table) 1 passed
In the game: HUD of Time's clock in Kakariko after loading the save not drawn drawn; not drawn with HOS_QUERY_MEMORY_OLD=1

HOS_QUERY_MEMORY_OLD ships unset (the module-by-module answer): set, the mod's HUD is gone as on main; unset, it is
drawn. The game's After column is the build with the other mod compatibility ports merged (72d64e92f).

Risks

  • A64_MODULE_ABI 2: a game module built before this change is refused until the game is built again. A player's
    build links the runtime and the game module together, so an update builds both.
  • An address inside the image between two regions is still answered as the whole image. The image builder places
    modules back to back, so a real image has no such hole.
  • A mod module whose segments are out of order is reported as one read-execute span, and a walk down past it may not
    see main as its own region (the module checks of the module PR leave such a module out).
  • Turn it off with HOS_QUERY_MEMORY_OLD=1. Players: code modules that walk memory find the game. No save, setting or
    cache changes.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (run locally, Testing names them; CI's run waits for approval)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • A check under tests/ that reads changed source is updated, not weakened. (tests/test_query_memory_free.py stubs the new image_region, so it still sees one region)
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: the build above; Linux: asked of the Test Farm in the comments, waits)
  • Screenshots of the same spot on main and here, for a change that shows on screen. (in the comments)
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary `main` builds a mod's code module (`exefs/subsdk*`) into the game, but answered `svcQueryMemory` for the whole game image as one executable region. A mod's code module finds the game's `main` the way it does on a console: by walking the memory regions down from its own. With one region the walk meets the loader and gives up, so the module never finds the game. The SDK's own readers (`nn::ro`'s module header search, `nn::diag`'s backtrace) find a module's start the same way. With this change `svcQueryMemory` answers module by module, as the kernel does: each module's `.text` read-execute, `.rodata` read-only, and `.data` with the bss read-write, back to back, together spanning the image. The image builder lists the regions (`image::Image::memory_regions`), the lift writes them into `gen/image.c`, `A64Image` carries the table (`A64_MODULE_ABI` 2: the runtime and the game module must agree on its layout), and `host/game_module.c` copies it at the load. An address in the image that no region holds gets the whole image, as before; the stack, heap, system region, output region and free gaps are unchanged. `HOS_QUERY_MEMORY_OLD=1` (a kill switch) answers the one region as before. This is the part of #984 that `main` didn't have yet (`main` already builds the modules in, `modules.rs`). Read first: `host/hos_svc.c` (`image_region`, `query_memory`), `builder/crates/image/src/lib.rs` (`memory_regions`), then `builder/crates/lift/src/whole/files.rs` (`image_c`). ## Testing **Tested:** Windows 11 Pro, RTX 3090, NVIDIA 610.88, in the game, built by `longshot-builder play --profile` with this PR and the other mod compatibility ports merged, adult Link in Kakariko: HUD of Time and Rupee Counter, two mods with a code module each, find the game and draw their HUD. The switch both ways, at the same spot after loading the same save: with `HOS_QUERY_MEMORY_OLD=1` (the start's switches line says `HOS_QUERY_MEMORY_OLD=1 (kill)`) HUD of Time's clock is gone; unset, it is drawn (`13:12`, bottom left). On `main`, with the module built in (`Code module subsdk9: built in.`), the clock is gone too (screenshots in the comments). Game-free: `tests/test_query_memory.py` (the real `query_memory` over a made-up image: each segment, a mod module's walk down to `main`, a hole, the switch both ways, four broken variants) and `tests/test_query_memory_free.py`, with llvm-mingw's clang; the lift's `image_c_writes_each_modules_regions` and the image builder's region tests. `mise run test`, run locally while CI's run waits for approval (Windows 11, `tests/run_all.py --strict`, 12 checks at once), here @ f4b45e70a and on `main` @ f577a1aea: 832 passed, 14 failed, 51 skipped here; 820 passed, 25 failed, 51 skipped on `main`. 13 of the 14 also fail on `main`: test_cursor_hidden_linux, test_dev_update, test_dlssg_folders, test_fsr4_tune, test_fsr_uniform_ownership, test_input_background, test_lifter, test_linux_pressure, test_loaded_modules_drop, test_program_cache_cleanup, test_program_cache_one_variant, test_program_cache_store_record, test_state_list_give_back. The other, test_fallback_buffer_cleanup, hit its program's 10-second timeout under that load and passes here run alone (`--exact`); this PR touches none of the renderer sources it cuts. **Still to test:** - Linux, any GPU: build the game from this PR and start it to the title screen, expecting it to build and start as on `main` (host code changed) (@Beanstalk) ## Measurements **Verdict:** Fixed: a code module that walks memory down to the game finds it, and HUD of Time draws its clock, which it does not on `main` or with the switch set. Nothing changes per frame: `svcQueryMemory` looks the address up in a table of a few regions. Setup: Windows 11 Pro, RTX 3090, NVIDIA 610.88; the test profile above in Kakariko; the switch set in the launcher's environment, one run each way, the same save loaded and nothing pressed after. | | Before: main @ f577a1aea | After: this PR @ f4b45e70a | |---|---|---| | `python -I tests/test_query_memory.py` | fails (`image_region` is not in `host/hos_svc.c`) | passes | | `cargo test -p lift image_c_writes_each_modules_regions` | 1 failed (`image.c` has no region table) | 1 passed | | In the game: HUD of Time's clock in Kakariko after loading the save | not drawn | drawn; not drawn with `HOS_QUERY_MEMORY_OLD=1` | `HOS_QUERY_MEMORY_OLD` ships unset (the module-by-module answer): set, the mod's HUD is gone as on `main`; unset, it is drawn. The game's After column is the build with the other mod compatibility ports merged (72d64e92f). ## Risks - `A64_MODULE_ABI` 2: a game module built before this change is refused until the game is built again. A player's build links the runtime and the game module together, so an update builds both. - An address inside the image between two regions is still answered as the whole image. The image builder places modules back to back, so a real image has no such hole. - A mod module whose segments are out of order is reported as one read-execute span, and a walk down past it may not see `main` as its own region (the module checks of the module PR leave such a module out). - Turn it off with `HOS_QUERY_MEMORY_OLD=1`. Players: code modules that walk memory find the game. No save, setting or cache changes. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). (run locally, Testing names them; CI's run waits for approval) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [x] A check under `tests/` that reads changed source is updated, not weakened. (`tests/test_query_memory_free.py` stubs the new `image_region`, so it still sees one region) - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: the build above; Linux: asked of the Test Farm in the comments, waits) - [x] Screenshots of the same spot on `main` and here, for a change that shows on screen. (in the comments) - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(host): svcQueryMemory answers for the image module by module, as the kernel does
Some checks failed
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
f4b45e70a3
The part of #984 main does not have yet (main builds a mod's code module in, modules.rs; this is how it finds the
game once it runs).

The whole image was one executable region. A mod's code module finds the game's main by walking the memory regions
down from its own, as it does on a console; with one region the walk met the loader and gave up. The SDK's own
readers (nn::ro's module header search, nn::diag's backtrace) find a module's start the same way.

The image builder now lists each module's segments (image::Image::memory_regions): .text read-execute, .rodata
read-only, .data with the bss read-write, back to back, together spanning the image. The lift writes them into
gen/image.c, and A64Image carries the table (A64_MODULE_ABI 2: the runtime and the game module must agree on its
layout). host/game_module.c copies it at the load, and query_memory answers from it: static code for the read-only
and executable regions, mutable code for the data. An address in the image that no region holds gets the whole image,
as before. Stack, heap, the system region, the output region and the free gaps are unchanged.

HOS_QUERY_MEMORY_OLD=1 (kill) answers the one region as before.

tests/test_query_memory.py runs the real query_memory over a made-up image: each segment, a mod module's walk down to
main, a hole, the switch, and four broken variants. The lift's image_c_writes_each_modules_regions and the image
builder's region tests check what is written.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in game: Windows 11 Pro, RTX 3090, NVIDIA 610.88, adult Link in Kakariko, built by longshot-builder play --profile with the mod compatibility ports merged: HUD of Time and Rupee Counter, a code module each, found the game and drew their HUD. The run with HOS_QUERY_MEMORY_OLD=1 is still to do.

Tested in game: Windows 11 Pro, RTX 3090, NVIDIA 610.88, adult Link in Kakariko, built by longshot-builder play --profile with the mod compatibility ports merged: HUD of Time and Rupee Counter, a code module each, found the game and drew their HUD. The run with HOS_QUERY_MEMORY_OLD=1 is still to do.
Member

Possibly related, for context:

  • issue #2497 Mods that ship extra ExeFS modules (subsdkN) are not loaded: the .ips applies but its code is missing — Reports missing mod-provided subsdk code modules
  • PR #1683 fix(svc): svcQueryMemory answers a free range as the whole gap, Inaccessible past the address space — Earlier svcQueryMemory kernel-behavior change
Possibly related, for context: - issue #2497 Mods that ship extra ExeFS modules (subsdkN) are not loaded: the .ips applies but its code is missing — Reports missing mod-provided subsdk code modules - PR #1683 fix(svc): svcQueryMemory answers a free range as the whole gap, Inaccessible past the address space — Earlier svcQueryMemory kernel-behavior change
Author
Member

Screenshots: Kakariko after loading the same save, nothing pressed after, the same test profile (Windows 11, RTX 3090). HUD of Time draws a clock at the bottom left from its code module.

Before, main @ f577a1aea (the module built in): no clock.
main

After, this PR (the build with the other mod compatibility ports merged, 72d64e92f): the clock is drawn.
this PR

After, with HOS_QUERY_MEMORY_OLD=1: no clock, as on main.
this PR, switch set

Screenshots: Kakariko after loading the same save, nothing pressed after, the same test profile (Windows 11, RTX 3090). HUD of Time draws a clock at the bottom left from its code module. **Before**, main @ f577a1aea (the module built in): no clock. ![main](https://git.magicbean.dev/attachments/61f11a69-0412-4a0c-9278-86b65c2726a9) **After**, this PR (the build with the other mod compatibility ports merged, 72d64e92f): the clock is drawn. ![this PR](https://git.magicbean.dev/attachments/e4b88e5b-69c4-4c18-ae0d-fa96b453fe2d) **After, with `HOS_QUERY_MEMORY_OLD=1`**: no clock, as on main. ![this PR, switch set](https://git.magicbean.dev/attachments/c8f1ac39-17ce-4a6f-87e3-0fe6f55f65f0)
Author
Member

Description updated: the switch's A/B in the game is in Testing and Measurements (HUD of Time's clock is drawn with this PR, and not on main or with HOS_QUERY_MEMORY_OLD=1; screenshots in the comment above).

Description updated: the switch's A/B in the game is in Testing and Measurements (HUD of Time's clock is drawn with this PR, and not on main or with HOS_QUERY_MEMORY_OLD=1; screenshots in the comment above).
Author
Member

@Beanstalk Build the game from this PR on Linux (any GPU) and start it to the title screen, no mods. It changes host C (host/hos_svc.c, host/game_module.c) and the game module's ABI (A64_MODULE_ABI 2): expect it to build and start as main does.

@Beanstalk Build the game from this PR on Linux (any GPU) and start it to the title screen, no mods. It changes host C (`host/hos_svc.c`, `host/game_module.c`) and the game module's ABI (`A64_MODULE_ABI` 2): expect it to build and start as `main` does.
Member

@snaildev99 only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for f4b45e7, and the PR has changed since (3d17857), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@snaildev99 only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `f4b45e7`, and the PR has changed since (`3d17857`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
Author
Member

mise run test, run locally while CI's run waits for approval (Windows 11, run_all --strict, 12 checks at once), here @ f4b45e70a and on main @ f577a1aea: 832 passed, 14 failed, 51 skipped here; 820 passed, 25 failed, 51 skipped on main. 13 of the 14 also fail on main (named in Testing); the other, test_fallback_buffer_cleanup, timed out under that load and passes here run alone (--exact). Box ticked. The Linux build (Host code) still waits for the Test Farm request's approval.

mise run test, run locally while CI's run waits for approval (Windows 11, run_all --strict, 12 checks at once), here @ f4b45e70a and on main @ f577a1aea: 832 passed, 14 failed, 51 skipped here; 820 passed, 25 failed, 51 skipped on main. 13 of the 14 also fail on main (named in Testing); the other, test_fallback_buffer_cleanup, timed out under that load and passes here run alone (--exact). Box ticked. The Linux build (Host code) still waits for the Test Farm request's approval.
Owner
@review
BeanBot left a comment

Recommendation: Approve. The new first-use switch cache has a data race when guest threads query memory concurrently. The new check also hard-codes GCC, so it can be skipped or fail on supported setups that provide another compiler. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge.

The change reports image memory by module segment, allowing code modules that walk memory downward to find the game. A Windows test with additional mod compatibility ports showed two mod HUDs working; the change adds a small region lookup and a kill switch.

Should fix (2): not blocking, but worth doing before merging.

  • L1 host/hos_svc.c:357: The lazy initialization of the shared switch cache uses unsynchronized reads and writes. (more on the line) Do: Initialize the switch before guest threads start, or use a thread-safe once mechanism or atomic cache.
  • L2 tests/test_query_memory.py:28: The new check hard-codes GCC instead of using the compiler selected by the test runner. (more on the line) Do: Use the runner's {cc} placeholder and honor CC for direct invocation, including compiler arguments as appropriate.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L3: The changed host and module ABI have not yet been exercised in a Linux game build. When: Linux players use the changed loader and query path, but the reported game run is on Windows only; a Linux build or startup failure would not be exposed by that run. Do: Build this head on Linux and start the game to the title screen, as already requested from the Test Farm.

@fix can do L1 and L2.

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Yes for the tested configuration: HUD of Time's clock was absent on main and with the kill switch set, and present with this change and the other mod compatibility ports merged. Linux game validation is still pending.

Other systems: The query can run on any guest thread and on both Windows and Linux. It changes answers for game and SDK callers as well as mods; the reported game run covers Windows on NVIDIA, while the requested Linux build and startup remain pending. No renderer or GPU-specific code changes.

Switches: HOS_QUERY_MEMORY_OLD is added, unset by default, selecting the new module-by-module answers; setting it to 1 restores the old whole-image answer. It has a switches.def row. The default fixes the demonstrated mod behavior, subject to the outstanding Linux run.

Reviewed: f4b45e70a3 against f577a1aeab: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, the diff and commit message; read the changed image and query tests and host game-module loader, and traced image construction, module collection, ABI loading and test compiler selection. Skimmed the remaining changed documentation, switch table, generated-C emission and unchanged surrounding code. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. The supplied comments and CI status were reviewed; screenshots themselves were not accessible.; nothing run (a code review).

Checked and fine:

  • The image builder places modules back to back and the generated regions use each module's segment boundaries.
  • The module ABI is bumped and incompatible modules are refused.
  • The switch has a table entry, and the reported Windows run exercises both switch states.
  • The commit records AI assistance, and the diff contains no committed build output or game files.

Testing: Read-only review; no builds, tests, or project scripts were run. CI is still running.

Overlaps and merge order: Not determined from the offline checkout.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The new first-use switch cache has a data race when guest threads query memory concurrently. The new check also hard-codes GCC, so it can be skipped or fail on supported setups that provide another compiler. Nothing blocking is left: what remains is for the author before merging (below). Recommend approval; not approved on the forge. The change reports image memory by module segment, allowing code modules that walk memory downward to find the game. A Windows test with additional mod compatibility ports showed two mod HUDs working; the change adds a small region lookup and a kill switch. **Should fix (2)**: not blocking, but worth doing before merging. - **L1** `host/hos_svc.c:357`: The lazy initialization of the shared switch cache uses unsynchronized reads and writes. (more on the line) **Do:** Initialize the switch before guest threads start, or use a thread-safe once mechanism or atomic cache. - **L2** `tests/test_query_memory.py:28`: The new check hard-codes GCC instead of using the compiler selected by the test runner. (more on the line) **Do:** Use the runner's {cc} placeholder and honor CC for direct invocation, including compiler arguments as appropriate. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L3**: The changed host and module ABI have not yet been exercised in a Linux game build. *When:* Linux players use the changed loader and query path, but the reported game run is on Windows only; a Linux build or startup failure would not be exposed by that run. **Do:** Build this head on Linux and start the game to the title screen, as already requested from the Test Farm. `@fix` can do L1 and L2. **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes for the tested configuration: HUD of Time's clock was absent on main and with the kill switch set, and present with this change and the other mod compatibility ports merged. Linux game validation is still pending. **Other systems:** The query can run on any guest thread and on both Windows and Linux. It changes answers for game and SDK callers as well as mods; the reported game run covers Windows on NVIDIA, while the requested Linux build and startup remain pending. No renderer or GPU-specific code changes. **Switches:** HOS_QUERY_MEMORY_OLD is added, unset by default, selecting the new module-by-module answers; setting it to 1 restores the old whole-image answer. It has a switches.def row. The default fixes the demonstrated mod behavior, subject to the outstanding Linux run. **Reviewed:** f4b45e70a380 against f577a1aeabdb: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, the diff and commit message; read the changed image and query tests and host game-module loader, and traced image construction, module collection, ABI loading and test compiler selection. Skimmed the remaining changed documentation, switch table, generated-C emission and unchanged surrounding code. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. The supplied comments and CI status were reviewed; screenshots themselves were not accessible.; nothing run (a code review). **Checked and fine:** - The image builder places modules back to back and the generated regions use each module's segment boundaries. - The module ABI is bumped and incompatible modules are refused. - The switch has a table entry, and the reported Windows run exercises both switch states. - The commit records AI assistance, and the diff contains no committed build output or game files. **Testing:** Read-only review; no builds, tests, or project scripts were run. CI is still running. **Overlaps and merge order:** Not determined from the offline checkout. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
host/hos_svc.c Outdated
@ -337,1 +354,4 @@
static void query_memory(uint64_t out, uint64_t addr) {
static int whole = -1;
if (whole < 0) whole = env_on("HOS_QUERY_MEMORY_OLD");
Member

L1 (should fix): The lazy initialization of the shared switch cache uses unsynchronized reads and writes.

When: If two guest threads enter svcQueryMemory while whole is still -1, both can read and write it concurrently. That is a C data race and has undefined behavior, even when both read the same environment value.

Do: Initialize the switch before guest threads start, or use a thread-safe once mechanism or atomic cache.

**L1** (should fix): The lazy initialization of the shared switch cache uses unsynchronized reads and writes. *When:* If two guest threads enter svcQueryMemory while whole is still -1, both can read and write it concurrently. That is a C data race and has undefined behavior, even when both read the same environment value. **Do:** Initialize the switch before guest threads start, or use a thread-safe once mechanism or atomic cache.
@ -0,0 +25,4 @@
import tempfile
from pathlib import Path
RUN_ALL_ARGS = ["--cc", "gcc"]
Member

L2 (should fix): The new check hard-codes GCC instead of using the compiler selected by the test runner.

When: On a supported Windows or Linux setup with CC pointing to clang but no gcc on PATH, run_all skips this check, or fails it in strict mode, even though a suitable compiler is available. Direct invocation also ignores CC.

Do: Use the runner's {cc} placeholder and honor CC for direct invocation, including compiler arguments as appropriate.

**L2** (should fix): The new check hard-codes GCC instead of using the compiler selected by the test runner. *When:* On a supported Windows or Linux setup with CC pointing to clang but no gcc on PATH, run_all skips this check, or fails it in strict mode, even though a suitable compiler is available. Direct invocation also ignores CC. **Do:** Use the runner's {cc} placeholder and honor CC for direct invocation, including compiler arguments as appropriate.
Owner
@fix
HumanBean changed title from WIP: feat(host): svcQueryMemory answers for the image module by module, as the kernel does to feat(host): svcQueryMemory answers for the image module by module, as the kernel does 2026-12-05 17:20:11 +00:00
BeanBot force-pushed mods/query-memory-modules from f4b45e70a3
Some checks failed
beanstalk/approval waiting for a BigBean's 👍 on the request
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
to 3d17857165
Some checks failed
beanstalk/approval changed since the request: ask again
PR description / Title and description (pull_request_target) Failing after 7s
CI / What the change needs (pull_request) Successful in 9s
CI / Third-party parts and guide screenshots (pull_request) Successful in 14s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 15s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 15m18s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Failing after 1m25s
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Successful in 10m40s
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Successful in 10m44s
CI / Website build and checks (pull_request) Failing after 35s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 48m59s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 1h0m7s
2026-12-05 17:21:30 +00:00
Compare
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The switch cache is synchronized and the test now uses the selected compiler. The host and module ABI still need a Linux build and game run. Recommend approval; not approved on the forge.

What @fix changed
I changed this pull request: the new head is 3d17857165. I rebased it onto main (3145d9d48f).

Changed

  • Switch cache race in host/hos_svc.c:356: Used atomic load and compare-exchange to publish and read the cached switch value safely.
  • Compiler selection in tests/test_query_memory.py:28: Used the runner’s compiler placeholder and shared compiler parsing for --cc and CC, including arguments. Tests were not run as requested.

Nothing was built or run: the checks run again on the new head.

The change lets code modules find the game by reporting image memory one module segment at a time. It adds a region table and an ABI change, with a switch to restore the previous answer.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L3: The changed host and module ABI have not yet been exercised in a Linux game build. When: Linux players use the changed loader and query path, but the reported game run is on Windows only; a Linux build or startup failure would not be exposed by that run. Do: Build this head on Linux and start the game to the title screen, as already requested from the Test Farm.

Checks: they run again on this head; a failure shows on the pull request.

More: does it help, other systems, switches, what was read

Does it help: Yes: the reported Windows run showed HUD of Time's clock with the change, but not on main or with the old-answer switch enabled. The tested build also included other mod compatibility ports.

Other systems: The host and game module both consume the new ABI and region table. Windows was exercised in game; Linux remains untested. The change does not alter rendering code directly.

Switches: HOS_QUERY_MEMORY_OLD defaults to unset, selecting module-by-module answers; setting it restores the old single-region answer. The reported Windows comparison supports the default.

Reviewed: 3d17857165 against 3145d9d48f: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the fix diff, tests/test_query_memory.py, tests/compiler_command.py and gpu/vk/compat/longshot_env.h in full; inspected the runner's compiler selection and the original pull request diff. Other changed files were reviewed through their diffs, not read in full. Tooling's AGENTS.md was unavailable; no review checklist was present.; nothing run (a code review).

Checked and fine:

  • The compare-exchange failure path uses the value published by the winning thread.
  • The fix retains the module-by-module answer and the old-answer switch.

Testing: No commands from the project or tests were run. The author reports Windows game testing and local test-suite results; CI has not run on this head, and the Linux Test Farm request awaits approval.

Overlaps and merge order: Not checked; network access is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The switch cache is synchronized and the test now uses the selected compiler. The host and module ABI still need a Linux build and game run. Recommend approval; not approved on the forge. **What `@fix` changed** I changed this pull request: the new head is 3d17857165cb. I rebased it onto `main` (3145d9d48f05). **Changed** - **Switch cache race in host/hos_svc.c:356**: Used atomic load and compare-exchange to publish and read the cached switch value safely. - **Compiler selection in tests/test_query_memory.py:28**: Used the runner’s compiler placeholder and shared compiler parsing for --cc and CC, including arguments. Tests were not run as requested. Nothing was built or run: the checks run again on the new head. The change lets code modules find the game by reporting image memory one module segment at a time. It adds a region table and an ABI change, with a switch to restore the previous answer. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L3**: The changed host and module ABI have not yet been exercised in a Linux game build. *When:* Linux players use the changed loader and query path, but the reported game run is on Windows only; a Linux build or startup failure would not be exposed by that run. **Do:** Build this head on Linux and start the game to the title screen, as already requested from the Test Farm. **Checks:** they run again on this head; a failure shows on the pull request. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes: the reported Windows run showed HUD of Time's clock with the change, but not on main or with the old-answer switch enabled. The tested build also included other mod compatibility ports. **Other systems:** The host and game module both consume the new ABI and region table. Windows was exercised in game; Linux remains untested. The change does not alter rendering code directly. **Switches:** HOS_QUERY_MEMORY_OLD defaults to unset, selecting module-by-module answers; setting it restores the old single-region answer. The reported Windows comparison supports the default. **Reviewed:** 3d17857165cb against 3145d9d48f05: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the fix diff, tests/test_query_memory.py, tests/compiler_command.py and gpu/vk/compat/longshot_env.h in full; inspected the runner's compiler selection and the original pull request diff. Other changed files were reviewed through their diffs, not read in full. Tooling's AGENTS.md was unavailable; no review checklist was present.; nothing run (a code review). **Checked and fine:** - The compare-exchange failure path uses the value published by the winning thread. - The fix retains the module-by-module answer and the old-answer switch. **Testing:** No commands from the project or tests were run. The author reports Windows game testing and local test-suite results; CI has not run on this head, and the Linux Test Farm request awaits approval. **Overlaps and merge order:** Not checked; network access is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch mods/query-memory-modules 2026-12-05 17:28:41 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!3167
No description provided.