Skip to content

runtime: add an opt-in console profile for the OEM ConsoleMode read - #2650

Merged
R0Y00 merged 2 commits into
R0Y00:mainfrom
pigalot:runtime/console-profile
Nov 26, 2026
Merged

R0Y00 merged 2 commits into
R0Y00:mainfrom
pigalot:runtime/console-profile

Conversation

@pigalot

@pigalot pigalot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Change

Slice 4 of 4 from #2591: the opt-in profile.

X2W_DEVICE_TYPE (with X2W_RUNTIME_PROXY=1) answers the title's reads of
HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM\ConsoleMode:

Value Answer
6 0x60 (Series S)
7 0x64 (Series X)
1 value missing (PC)

Unset, every call goes to the real registry as before.

  • console_mode.h holds the value table and recognises the key and value.
  • registry_console_mode.inl holds hooks for RegOpenKeyExW, RegOpenKeyW, RegQueryValueExW,
    RegGetValueW and RegCloseKey. They answer only a ConsoleMode read under the OEM key while the
    switch names a known console. Every other call is passed through. Opening the key and reading the
    value are logged a few times either way.
  • runtime_gpa_patch.h: visit_imports_with takes a classifier, so the proxy can rewrite the
    registry imports of the EXE and package helpers. visit_imports keeps its old behaviour.
  • runtime_proxy.cpp patches those imports and returns the hooks from GetProcAddress by name.

The switch changes only what the registry reads answer. On the Series S profile, the path a title
then takes meets desktop refusals that the other profiles do not reach. Those are separate slices:
device slot 76 and view dimensions. R9G9B9E5_SHAREDEXP with unordered access is already covered on
main. This slice claims nothing about what runs after the profile is chosen.

Refs #2591. Independent of the other three slices. Comparing a combined start-up build needs all four.

Verification

Build: this branch, one commit bac83cb2 on main at 02368737. From the worktree in PowerShell:
. .\tools\dev.ps1, cmake --preset release, cmake --build --preset release (Python env
out/pe-env from requirements-dev.txt).

Environment: NVIDIA GeForce RTX 5090, driver 32.0.16.1088, Windows 10.0.26200.9974. The fixture
creates no device and replaces the registry functions with fakes, so no machine state is read or
changed.

  • ctest --preset release --no-tests=error -R '^startup_(console_mode(_control)?|runtime_gpa_patch(_name_only_control)?|runtime_proxy_scope.*)$' -V: 5/5 passed (startup_console_mode and its control, which prints 5 FAIL: lines; startup_runtime_gpa_patch and its name_only control; startup_runtime_proxy_scope).
  • ctest --preset release -j 6 --no-tests=error -R '^startup_' -E '_hardware$|^startup_audio_': 640 tests, 633 passed, 6 skipped (capability, exit 77), 1 failed: startup_storage_worker_start timed out at 60 s under -j 6; rerun alone (ctest --preset release --no-tests=error -R '^startup_storage_worker_start$') it passed in 13.9 s, as on the slice-1 build (14.0 s). This change does not touch it.
  • python -B tests/docs_links_check.py: pass (19 Markdown files, 509 links).
    python -B tests/bidi_controls_check.py: pass. git diff --check origin/main...HEAD: clean.

Evidence

startup_console_mode (from #2591, unchanged) reaches the hooks through GetProcAddress, the way a
title does, against fake registry functions that report the value missing:

  • Unset: the read is passed to the fake.
  • 6 and 7: answer 0x60 and 0x64 without calling the fake.
  • 1: answers missing.
  • Other keys, values and closed handles: passed through.

--control leaves X2W_DEVICE_TYPE unset for the answered cases, so those rows print FAIL:. The
test is registered with PASS_REGULAR_EXPRESSION "FAIL: ". The existing startup_runtime_gpa_patch
and its name_only control pass unchanged, which shows the classifier refactor keeps the proxy's own
import walk the same.

Hypothesis: what the ConsoleMode values mean on the console comes from public notes, not from a
measurement here. With a local console executable (not included), each value changed which start-up
path the title took (#2591).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

This change was AI-assisted.

X2W_DEVICE_TYPE (with X2W_RUNTIME_PROXY) answers the title's reads of
HKLM\Software\Microsoft\Windows NT\CurrentVersion\OEM\ConsoleMode:
6 = 0x60 (Series S), 7 = 0x64 (Series X), 1 = value missing (PC).
Unset, every call goes to the real registry.

The proxy rewrites five registry imports of the EXE and package helpers
(regular IAT and GetProcAddress by name); visit_imports_with takes a
classifier for them and visit_imports keeps its own behaviour. Opening
the key and reading the value are logged a few times either way.

New fixture with a negative control: startup_console_mode, against fake
registry functions; the control leaves the switch unset for the answered
cases.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review of head bac83cb against main (comment only).

Code read: console_mode.h, registry_console_mode.inl, the runtime_gpa_patch.h classifier change, the runtime_proxy.cpp wiring, and tests/startup_console_mode_check.cpp.

  • The switch is opt-in. Unset, or any number other than 1, 6 or 7, passes every call to the real registry.
  • The visit_imports_with refactor keeps visit_imports unchanged: it passes the old classifier through. The existing startup_runtime_gpa_patch tests cover that.
  • The fixture is source-built, goes through GetProcAddress like a title would, and uses fake registry functions. It has a negative control (--control, PASS_REGULAR_EXPRESSION "FAIL: "). So the "source-built regression test plus negative control" requirement is met.
  • Small note, not a blocker: oem_keys holds 16 handles. When it is full, a further OEM key is not tracked and its reads go to the real registry. That is a safe fallback, but a log line when it happens would help.
  • The meaning of 0x60 / 0x64 / missing comes from public notes of another project. The PR says this itself.

Commands run locally on the exact head:

  • python3 -B tests/docs_links_check.py, python3 -B tests/bidi_controls_check.py, git diff --check origin/main...HEAD: all clean.
  • The fixture includes <windows.h>, so it does not build on Linux. I could not run it or a mutation of it here, and I did not run Win2025. The test results in the PR body are the author's.

Merge: the PR says that, with a local console executable, each value changed which start-up path the title took (#2591). This is a start-up claim from running the game, and I cannot check it. I am not merging this. The merge stays with MasterDomino or @R0Y00, who can verify on the game.

AI-assisted; commands listed were executed locally.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The registry hooks currently match function name alone on both routes. patch_registry_imports ignores the imported DLL argument, and hooked_get_proc_address passes only the export name and address into registry_hook_for. Because remember_registry saves the first address globally, a package DLL exporting the same name can change which implementation later calls reach, even with X2W_DEVICE_TYPE unset. Please restrict both routes to the supported Windows registry providers, preserving the existing provider identity checks on the other proxy hooks. Add a source-built decoy DLL or synthetic IAT provider with the same export name and distinct result to verify the decoy is untouched, including with the switch unset.

Both console-mode routes matched the import name alone, so a package DLL
exporting RegQueryValueExW or RegOpenKeyExW could be hooked and, because
the first address is kept, become the registry later calls reach.

The IAT route now needs the import DLL to be advapi32.dll, kernelbase.dll,
kernel32.dll or an api-ms-win-core-registry-* API set, and the bound
address to lie in the system-directory copy of one of those modules. The
GetProcAddress route needs the module to be one of them. Only addresses
inside them are remembered as the real function.

startup_console_mode loads a source-built decoy DLL with the same export
names and a distinct result. With X2W_DEVICE_TYPE unset and set, its
GetProcAddress lookups and synthetic IAT entries naming it (or naming
advapi32.dll but bound to it) stay untouched, and the hooks still reach
the fake registry. startup_console_mode_provider_control matches by name
alone and must fail. startup_runtime_proxy_scope checks the same through
the real loader against advapi32.dll.

A full 16-entry OEM handle table is now logged once.
@pigalot

pigalot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@R0Y00 thanks, addressed in 0ac58f7 (new commit on top of bac83cb, no rebase).

Both routes are now limited to the Windows registry providers (src/startup_stubs/registry_console_mode.inl)

  • IAT route (patch_registry_imports): an import is classified only if its DLL name is advapi32.dll, kernelbase.dll, kernel32.dll or api-ms-win-core-registry-* (any case). On top of that, the bound slot address must lie in the system-directory copy of advapi32/kernelbase/kernel32 (GetModuleHandleExW(FROM_ADDRESS), then compared with GetModuleHandleW(<system dir>\<name>)). That way a package DLL that has the same name, or sits behind a provider-named import, does not match.
  • GetProcAddress route: registry_hook_for(module, name, real) now takes the HMODULE. It returns a hook only when that module is one of those system modules, so hooked_get_proc_address returns the original export for any other module.
  • remember_registry refuses any address outside those modules, so a decoy can never become the remembered implementation, whether X2W_DEVICE_TYPE is set or not.
  • The provider identity checks on the other proxy hooks are unchanged: GetProcAddress from any module, and QueryApiImpl / InitializeApiImpl* only from xgameruntime.dll. startup_runtime_gpa_patch(_name_only_control) passes as before.

Decoy coverage

  • New source-built startup_console_mode_decoy.dll (tests/startup_console_mode_decoy.cpp/.def). It exports RegOpenKeyExW and RegQueryValueExW returning 0x5EC0, which no registry returns, plus a call counter. startup_console_mode --decoy <dll> runs the decoy checks before the fake registry is registered, so a name-only match would keep the decoy first. The checks run with the switch unset and again with X2W_DEVICE_TYPE=7:
    • GetProcAddress on the decoy returns the decoy's own exports, and calling them returns 0x5EC0 and counts.
    • In a synthetic IAT, entries that name the decoy DLL, and an advapi32.dll entry bound to the decoy, are left untouched; a call through the decoy's slot reaches the decoy. Only the advapi32.dll entries bound to the fixture's registry are rewritten (2 of 5).
    • The decoy's address is never remembered, and the RegQueryValueExW hook still reaches the fake registry (ERROR_FILE_NOT_FOUND, decoy counter unchanged).
    • The provider predicates accept the system advapi32/kernelbase, refuse the decoy module, and refuse a longer or unrelated import name.
  • New control startup_console_mode_provider_control (--control provider) matches registry imports by name alone and must print FAIL:. The decoy checks fail in both passes. The existing startup_console_mode_control is unchanged.
  • startup_runtime_proxy_scope (real loader, proxy carrier) uses its existing decoy DLL, which now also exports RegQueryValueExW. With the switch unset and set: the host's GetProcAddress(decoy, "RegQueryValueExW") stays the decoy's export and returns its own result, while GetProcAddress(advapi32, ...) is hooked and returns advapi32's own answer, with no decoy call.
  • Source mutation check: I removed the three provider checks (dll name, module, address) and rebuilt. startup_console_mode failed (35 checks, all decoy checks in both passes) and startup_runtime_proxy_scope failed (4 mismatches: decoy lookup hooked and hook reaching the decoy, in both passes). After restoring the source both pass.

tedin7's note: when all 16 oem_keys slots are in use, one line ... 16 OEM key handles already open, another is not tracked is logged once. It is covered in startup_console_mode.

docs/startup-runtime.md (Console profile) now describes the provider rule and the new control.

Commands and results (commit 0ac58f7; NVIDIA GeForce RTX 5090, driver 32.0.16.1088, Windows 10.0.26200.9974, D3D12 debug layer off; none of the tests below use the GPU)

. .\tools\dev.ps1
cmake --preset release
cmake --build --preset release
ctest --preset release --no-tests=error -R 'console_mode|gpa_patch|proxy' -V

6/6 passed: startup_runtime_gpa_patch, startup_runtime_gpa_patch_name_only_control, startup_console_mode, startup_console_mode_control, startup_console_mode_provider_control (both controls print FAIL: as required), startup_runtime_proxy_scope.

ctest --preset release -j 6 --no-tests=error -R '^startup_' -E '_hardware$|^startup_audio_'

640/641 passed, plus 6 not run (skip/disabled): startup_view_heap_warp, startup_gameinput_script_syntax, startup_sharedexp_target_warp, startup_small_texture_4k_addrlib, startup_logical_view_warp, startup_run_sh. startup_inflate timed out under -j 6. Run alone (ctest --preset release --no-tests=error -R '^startup_inflate$'), it passes in 9.6 s. It does not touch the registry code.

python -B tests/docs_links_check.py      # 19 Markdown files, 509 links: ok
python -B tests/bidi_controls_check.py   # 1869 files: no bidirectional controls
git diff --check origin/main...HEAD      # clean

This change was AI-assisted.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Re-reviewed the bound-address plus system-module checks for IAT and GetProcAddress at 0ac58f7. Windows Release passed six targeted CTests, including the real loaded runtime-proxy host. The decoy kept its sentinel with the switch unset and with X2W_DEVICE_TYPE=7. The genuine advapi32 lookup reached the system registry, and both the registry name-only mutant and the original provider-scope mutant were detected. This resolves my provider-identity finding. The startup behavior remains an opt-in experiment.

@R0Y00
R0Y00 merged commit 82c7080 into R0Y00:main Nov 26, 2026
5 checks passed
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