startup: X2W_LOW_ADDRESSES keeps the title's own memory below 2^40 #2851

Merged
tedin7 merged 2 commits from upstream-pr/2859 into main 2026-11-27 19:52:33 +00:00
tedin7 commented 2026-11-26 14:39:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T14:39:42Z.


Part of #1758

Fixes #2858

What this unblocks: a run can keep the title's own allocations below 2^40, so the package acceleration-structure builder no longer sees a destination address with bits set above bit 39.

What changed

  • tools/startup/launch.py and tools/startup/debug_launch.py start the title with PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY set to PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_OFF when X2W_LOW_ADDRESSES=1, so the title's own VirtualAlloc blocks come from the low end of the address space instead of a random start (often above 2^40). tools/startup/run.ps1 -LowAddresses sets the variable.
  • Off by default. If the attribute list cannot be built, the launcher prints why and starts the title unchanged.
  • tests/startup_launch_probe.cpp gets an addresses mode; tests/startup_launch_check.py runs it four times with the switch (every block must end below 2^40) and eight times without (at least one block must end above 2^40, the control).
  • docs/startup-runtime.md: a row next to X2W_XMEM_STARTUP_BELOW_40, which covers only the blocks the shim allocates.

Why it is correct: the builder receives the title's CPU address of the block (docs/experiments.md, "Startup blocks below 2^40"), which the shim cannot move; the blocks the title allocates itself follow the process's bottom-up ASLR setting, so turning that off keeps them low.

Source: Microsoft documentation of UpdateProcThreadAttribute, PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY and PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_OFF; docs/experiments.md, "Startup blocks below 2^40".

Verification:

  • python3 -I tests/startup_launch_check.py --unit: passed.
  • python3 -I tests/docs_links_check.py: 29 files, 545 links, clean. git diff --cached --check: clean.
  • x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only tests/startup_launch_probe.cpp: ok.
  • python3 -I tests/startup_launch_cli_check.py: 1 error on Linux (ctypes.get_last_error is Windows-only); the same single error on a plain origin/main checkout, so it is not caused by this change.
  • Win2025 (Windows Server 2025, MSVC, D3D12 WARP) on the exact PR head 314b097a9: startup_launch (built from startup_launch_probe) passed in Debug (1/1) and Release (1/1). Four launches with X2W_LOW_ADDRESSES=1 keep every block below 2^40; the control without it gets a block above 2^40 in at least one of eight launches.
  • Mutant (policy value changed from 0x2 << 16 to 0): the check fails ("a block ends at 0x16dd2b3ffff, above 2^40").

Real-hardware testing: @Makto94 - thanks for the help.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5512014795 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T14:39:42Z. --- Part of #1758 Fixes #2858 What this unblocks: a run can keep the title's own allocations below 2^40, so the package acceleration-structure builder no longer sees a destination address with bits set above bit 39. What changed - `tools/startup/launch.py` and `tools/startup/debug_launch.py` start the title with `PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY` set to `PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_OFF` when `X2W_LOW_ADDRESSES=1`, so the title's own `VirtualAlloc` blocks come from the low end of the address space instead of a random start (often above 2^40). `tools/startup/run.ps1 -LowAddresses` sets the variable. - Off by default. If the attribute list cannot be built, the launcher prints why and starts the title unchanged. - `tests/startup_launch_probe.cpp` gets an `addresses` mode; `tests/startup_launch_check.py` runs it four times with the switch (every block must end below 2^40) and eight times without (at least one block must end above 2^40, the control). - `docs/startup-runtime.md`: a row next to `X2W_XMEM_STARTUP_BELOW_40`, which covers only the blocks the shim allocates. Why it is correct: the builder receives the title's CPU address of the block (docs/experiments.md, "Startup blocks below 2^40"), which the shim cannot move; the blocks the title allocates itself follow the process's bottom-up ASLR setting, so turning that off keeps them low. Source: Microsoft documentation of `UpdateProcThreadAttribute`, `PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY` and `PROCESS_CREATION_MITIGATION_POLICY_BOTTOM_UP_ASLR_ALWAYS_OFF`; docs/experiments.md, "Startup blocks below 2^40". Verification: - `python3 -I tests/startup_launch_check.py --unit`: passed. - `python3 -I tests/docs_links_check.py`: 29 files, 545 links, clean. `git diff --cached --check`: clean. - `x86_64-w64-mingw32-g++ -std=c++17 -fsyntax-only tests/startup_launch_probe.cpp`: ok. - `python3 -I tests/startup_launch_cli_check.py`: 1 error on Linux (`ctypes.get_last_error` is Windows-only); the same single error on a plain `origin/main` checkout, so it is not caused by this change. - Win2025 (Windows Server 2025, MSVC, D3D12 WARP) on the exact PR head `314b097a9`: `startup_launch` (built from `startup_launch_probe`) passed in Debug (1/1) and Release (1/1). Four launches with `X2W_LOW_ADDRESSES=1` keep every block below 2^40; the control without it gets a block above 2^40 in at least one of eight launches. - Mutant (policy value changed from `0x2 << 16` to `0`): the check fails ("a block ends at 0x16dd2b3ffff, above 2^40"). Real-hardware testing: @Makto94 - thanks for the help. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot] commented 2026-11-26 14:48:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T14:48:13Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 314b097a94

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6076142029 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859#pullrequestreview-6076142029). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-26T14:48:13Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `314b097a94` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-26 15:00:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T14:49:26Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6076162114 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859#pullrequestreview-6076162114). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T14:49:26Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-26 15:01:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T14:42:55Z.


Gate receipt for head 314b097a9 (Windows Server 2025 build 26100, MSVC 14.44, WARP).

The head reached Windows as the exact PR head (fetched from pull/2859/head, no patch).

python3 x2w_pipe.py win2025 2859 --host proxmox --regex '^startup_launch' --targets startup_launch_probe --keep-release --force

Result: dev 2/2 and release 2/2 passed (startup_launch, startup_launch_cli_check).

Mutant (patch, applied): startup_for_create always returns the unchanged startup info, so the mitigation attribute is never set. startup_launch fails with with X2W_LOW_ADDRESSES=1 a block ends at 0x1a46bc4ffff, above 2^40 in both dev and release.

Not covered by this gate: the policy-value-0 mutant (gated separately) and any run with a real title.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7195216278 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859#issuecomment-7195216278). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T14:42:55Z. --- Gate receipt for head 314b097a9 (Windows Server 2025 build 26100, MSVC 14.44, WARP). The head reached Windows as the exact PR head (fetched from `pull/2859/head`, no patch). ``` python3 x2w_pipe.py win2025 2859 --host proxmox --regex '^startup_launch' --targets startup_launch_probe --keep-release --force ``` Result: dev 2/2 and release 2/2 passed (`startup_launch`, `startup_launch_cli_check`). Mutant (patch, applied): `startup_for_create` always returns the unchanged startup info, so the mitigation attribute is never set. `startup_launch` fails with `with X2W_LOW_ADDRESSES=1 a block ends at 0x1a46bc4ffff, above 2^40` in both dev and release. Not covered by this gate: the policy-value-0 mutant (gated separately) and any run with a real title. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 15:01:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T14:42:58Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T14:48:16.184619Z 314b097 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7195217354 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859#issuecomment-7195217354). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T14:42:58Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"314b097a9483198bcb8e8a2d978052c3b603ec90","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T14:48:16.184619Z">2026-11-26T14:48:16.184619Z</relative-time> | `314b097` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-26 15:01:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T14:48:13Z.

Code review location: tests/startup_launch_check.py; line 242

@@ -222,6 +222,26 @@ def main(probe):
         assert result.returncode == 0, result.stderr
         assert captured(logdir, "stdout.txt") == "spawn ok\n", captured(logdir, "stdout.txt")
 
+        # X2W_LOW_ADDRESSES=1 starts the child with bottom-up ASLR off, so its blocks stay below 2^40 (the package
+        # acceleration-structure builder refuses a destination with bits set above bit 39, #1758).
+        limit = 1 << 40
+
+        def highest(env_extra, name):
+            env = dict(os.environ, **env_extra)
+            result, logdir, _ = launch(probe, work, name, ["--timeout", "20"], ["addresses"], env=env)
+            assert result.returncode == 0, result.stderr
+            text = captured(logdir, "stdout.txt")
+            assert text and text.startswith("addresses highest=0x"), (text, result.stdout)
+            return int(text.split("=")[1], 16), result.stdout
+
+        for attempt in range(4):
+            top, out = highest({"X2W_LOW_ADDRESSES": "1"}, f"low-{attempt}")
+            assert top < limit, f"with X2W_LOW_ADDRESSES=1 a block ends at 0x{top:x}, above 2^40"
+            assert "bottom-up ASLR off" in out, out
+        # Control: without the switch, the same child gets blocks above 2^40 on some runs (the default ASLR picks a random start).
+        above = [highest({}, f"default-{attempt}")[0] >= limit for attempt in range(8)]

P2 Badge Clear the inherited low-address flag for the control runs

When the Windows test is started from an environment that already has X2W_LOW_ADDRESSES=1, highest({}) preserves that value through dict(os.environ, **env_extra). All eight “default” children therefore receive the low-address mitigation too, so a correctly working implementation makes any(above) false and fails startup_launch. Remove the variable from the control environment, or explicitly override it with "0", so the negative control actually exercises the disabled case.

AGENTS.md reference: AGENTS.md:L314-L314

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4709976465 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859#discussion_r4709976465). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T14:48:13Z. **Code review location:** `tests/startup_launch_check.py`; line 242 ~~~~diff @@ -222,6 +222,26 @@ def main(probe): assert result.returncode == 0, result.stderr assert captured(logdir, "stdout.txt") == "spawn ok\n", captured(logdir, "stdout.txt") + # X2W_LOW_ADDRESSES=1 starts the child with bottom-up ASLR off, so its blocks stay below 2^40 (the package + # acceleration-structure builder refuses a destination with bits set above bit 39, #1758). + limit = 1 << 40 + + def highest(env_extra, name): + env = dict(os.environ, **env_extra) + result, logdir, _ = launch(probe, work, name, ["--timeout", "20"], ["addresses"], env=env) + assert result.returncode == 0, result.stderr + text = captured(logdir, "stdout.txt") + assert text and text.startswith("addresses highest=0x"), (text, result.stdout) + return int(text.split("=")[1], 16), result.stdout + + for attempt in range(4): + top, out = highest({"X2W_LOW_ADDRESSES": "1"}, f"low-{attempt}") + assert top < limit, f"with X2W_LOW_ADDRESSES=1 a block ends at 0x{top:x}, above 2^40" + assert "bottom-up ASLR off" in out, out + # Control: without the switch, the same child gets blocks above 2^40 on some runs (the default ASLR picks a random start). + above = [highest({}, f"default-{attempt}")[0] >= limit for attempt in range(8)] ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Clear the inherited low-address flag for the control runs** When the Windows test is started from an environment that already has `X2W_LOW_ADDRESSES=1`, `highest({})` preserves that value through `dict(os.environ, **env_extra)`. All eight “default” children therefore receive the low-address mitigation too, so a correctly working implementation makes `any(above)` false and fails `startup_launch`. Remove the variable from the control environment, or explicitly override it with `"0"`, so the negative control actually exercises the disabled case. AGENTS.md reference: [AGENTS.md:L314-L314](https://github.com/R0Y00/Xbox2Windows/blob/314b097a9483198bcb8e8a2d978052c3b603ec90/AGENTS.md#L314-L314) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-26 15:01:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T14:49:26Z.

Code review location: tests/startup_launch_check.py; line 242

@@ -222,6 +222,26 @@ def main(probe):
         assert result.returncode == 0, result.stderr
         assert captured(logdir, "stdout.txt") == "spawn ok\n", captured(logdir, "stdout.txt")
 
+        # X2W_LOW_ADDRESSES=1 starts the child with bottom-up ASLR off, so its blocks stay below 2^40 (the package
+        # acceleration-structure builder refuses a destination with bits set above bit 39, #1758).
+        limit = 1 << 40
+
+        def highest(env_extra, name):
+            env = dict(os.environ, **env_extra)
+            result, logdir, _ = launch(probe, work, name, ["--timeout", "20"], ["addresses"], env=env)
+            assert result.returncode == 0, result.stderr
+            text = captured(logdir, "stdout.txt")
+            assert text and text.startswith("addresses highest=0x"), (text, result.stdout)
+            return int(text.split("=")[1], 16), result.stdout
+
+        for attempt in range(4):
+            top, out = highest({"X2W_LOW_ADDRESSES": "1"}, f"low-{attempt}")
+            assert top < limit, f"with X2W_LOW_ADDRESSES=1 a block ends at 0x{top:x}, above 2^40"
+            assert "bottom-up ASLR off" in out, out
+        # Control: without the switch, the same child gets blocks above 2^40 on some runs (the default ASLR picks a random start).
+        above = [highest({}, f"default-{attempt}")[0] >= limit for attempt in range(8)]

Fixed in cbffed0ab: the control children now start from an environment without X2W_LOW_ADDRESSES (new child_env helper in tests/startup_launch_check.py); only the switch-on children get it, from the test. Added a Linux unit assertion (a caller with the variable set does not leak it into the control environment); a version of the helper that keeps the variable fails it. The Windows result of the earlier head is unchanged by this test-only edit; Stage-2 can re-run startup_launch on the new head.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4709990235 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859#discussion_r4709990235). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T14:49:26Z. **Code review location:** `tests/startup_launch_check.py`; line 242 ~~~~diff @@ -222,6 +222,26 @@ def main(probe): assert result.returncode == 0, result.stderr assert captured(logdir, "stdout.txt") == "spawn ok\n", captured(logdir, "stdout.txt") + # X2W_LOW_ADDRESSES=1 starts the child with bottom-up ASLR off, so its blocks stay below 2^40 (the package + # acceleration-structure builder refuses a destination with bits set above bit 39, #1758). + limit = 1 << 40 + + def highest(env_extra, name): + env = dict(os.environ, **env_extra) + result, logdir, _ = launch(probe, work, name, ["--timeout", "20"], ["addresses"], env=env) + assert result.returncode == 0, result.stderr + text = captured(logdir, "stdout.txt") + assert text and text.startswith("addresses highest=0x"), (text, result.stdout) + return int(text.split("=")[1], 16), result.stdout + + for attempt in range(4): + top, out = highest({"X2W_LOW_ADDRESSES": "1"}, f"low-{attempt}") + assert top < limit, f"with X2W_LOW_ADDRESSES=1 a block ends at 0x{top:x}, above 2^40" + assert "bottom-up ASLR off" in out, out + # Control: without the switch, the same child gets blocks above 2^40 on some runs (the default ASLR picks a random start). + above = [highest({}, f"default-{attempt}")[0] >= limit for attempt in range(8)] ~~~~ --- Fixed in cbffed0ab: the control children now start from an environment without X2W_LOW_ADDRESSES (new child_env helper in tests/startup_launch_check.py); only the switch-on children get it, from the test. Added a Linux unit assertion (a caller with the variable set does not leak it into the control environment); a version of the helper that keeps the variable fails it. The Windows result of the earlier head is unchanged by this test-only edit; Stage-2 can re-run startup_launch on the new head. AI-assisted; commands listed were executed locally.
KelboLive commented 2026-11-26 15:53:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-26T15:53:31Z.

Review: APPROVED


Reviewed PR for X2W_LOW_ADDRESSES: keeps the title's VirtualAlloc allocations below 2^40.

Summary

This PR enables bottom-up ASLR to be always off via PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY when X2W_LOW_ADDRESSES=1. The result is that the title's own memory stays below 2^40, which is needed for the acceleration-structure builder that refuses destination addresses with bits above bit 39.

Changes

tools/startup/launch.py

  • New STARTUPINFOEXW ctypes structure
  • PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY and related constants
  • low_addresses_requested() and startup_for_create() functions
  • startup_for_create() gracefully falls back when the attribute list cannot be built
  • CreateProcessW updated to use extended startup info

tools/startup/debug_launch.py

  • Updated to use startup_for_create() for extended startup info
  • Prints startup_note when present (e.g., "X2W_LOW_ADDRESSES: bottom-up ASLR off")

tools/startup/run.ps1

  • New -LowAddresses switch that sets X2W_LOW_ADDRESSES=1

tests/startup_launch_probe.cpp

  • New "addresses" mode: probes VirtualAlloc for various block sizes (64K, 16M, 1G, 4G) and prints the highest address allocated

tests/startup_launch_check.py

  • child_env() helper that strips X2W_LOW_ADDRESSES from inherited env
  • Unit test: verifies child_env doesn't leak X2W_LOW_ADDRESSES
  • 4 runs with X2W_LOW_ADDRESSES=1 (all blocks below 2^40) + 8 runs without (control, at least one above 2^40)

docs/startup-runtime.md

  • New row documenting X2W_LOW_ADDRESSES

Review Assessment

Correctness:

  • The mitigation policy is applied via the standard PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY attribute, which is the correct mechanism
  • Graceful fallback when attribute list cannot be built (prints why, continues without the switch)
  • child_env() correctly strips X2W_LOW_ADDRESSES so control runs don't inherit from parent env
  • The 2^40 limit is exactly what the acceleration-structure builder needs (docs/experiments.md confirms)

Safety:

  • Feature is off by default (X2W_LOW_ADDRESSES not set)
  • No impact on existing behavior when not requested
  • The mitigation policy only affects the child process (the title), not the launcher itself

Testing:

  • 4 runs with the switch: every block ends below 2^40, and "bottom-up ASLR off" appears in output
  • 8 runs without the switch: control confirms at least one block ends above 2^40
  • Mutation test (policy changed to 0): the check correctly fails
  • Verified on Windows Server 2025 with MSVC/D3D12 WARP

This is a clean, targeted change with thorough testing. No issues to address.

Approved for merge.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6077086810 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859#pullrequestreview-6077086810). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-26T15:53:31Z. **Review:** APPROVED --- Reviewed PR for X2W_LOW_ADDRESSES: keeps the title's VirtualAlloc allocations below 2^40. ## Summary This PR enables bottom-up ASLR to be always off via PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY when X2W_LOW_ADDRESSES=1. The result is that the title's own memory stays below 2^40, which is needed for the acceleration-structure builder that refuses destination addresses with bits above bit 39. ## Changes ### tools/startup/launch.py - New STARTUPINFOEXW ctypes structure - PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY and related constants - low_addresses_requested() and startup_for_create() functions - startup_for_create() gracefully falls back when the attribute list cannot be built - CreateProcessW updated to use extended startup info ### tools/startup/debug_launch.py - Updated to use startup_for_create() for extended startup info - Prints startup_note when present (e.g., "X2W_LOW_ADDRESSES: bottom-up ASLR off") ### tools/startup/run.ps1 - New -LowAddresses switch that sets X2W_LOW_ADDRESSES=1 ### tests/startup_launch_probe.cpp - New "addresses" mode: probes VirtualAlloc for various block sizes (64K, 16M, 1G, 4G) and prints the highest address allocated ### tests/startup_launch_check.py - child_env() helper that strips X2W_LOW_ADDRESSES from inherited env - Unit test: verifies child_env doesn't leak X2W_LOW_ADDRESSES - 4 runs with X2W_LOW_ADDRESSES=1 (all blocks below 2^40) + 8 runs without (control, at least one above 2^40) ### docs/startup-runtime.md - New row documenting X2W_LOW_ADDRESSES ## Review Assessment Correctness: - The mitigation policy is applied via the standard PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY attribute, which is the correct mechanism - Graceful fallback when attribute list cannot be built (prints why, continues without the switch) - child_env() correctly strips X2W_LOW_ADDRESSES so control runs don't inherit from parent env - The 2^40 limit is exactly what the acceleration-structure builder needs (docs/experiments.md confirms) Safety: - Feature is off by default (X2W_LOW_ADDRESSES not set) - No impact on existing behavior when not requested - The mitigation policy only affects the child process (the title), not the launcher itself Testing: - 4 runs with the switch: every block ends below 2^40, and "bottom-up ASLR off" appears in output - 8 runs without the switch: control confirms at least one block ends above 2^40 - Mutation test (policy changed to 0): the check correctly fails - Verified on Windows Server 2025 with MSVC/D3D12 WARP This is a clean, targeted change with thorough testing. No issues to address. Approved for merge.
pigalot commented 2026-11-27 19:52:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T19:52:17Z.

Review: APPROVED


Independently reviewed cbffed0a integrated over main 968ddcdf (tree b52a33b2, clean merge).

What I traced.

  • Constants: both match the SDK. PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY is ProcThreadAttributeValue(7, FALSE, TRUE, FALSE) = 0x20007. ..._BOTTOM_UP_ASLR_ALWAYS_OFF is 0x2 << 16, inside the 0x3 << 16 mask, where 0x1 << 16 is ALWAYS_ON.
  • startup_for_create: it copies the caller's STARTUPINFOW, including the std handles, into a STARTUPINFOEXW, and sets cb to the extended size. It returns the attribute buffer and the policy word, so both stay alive across CreateProcessW. With the switch off, or when either call fails, it falls back to the unchanged si.
  • Not tested: debug_launch.py uses the same helper, but no test starts the title through it with the switch on.
  • Codex thread: resolved. child_env drops an inherited X2W_LOW_ADDRESSES for the control children.

What I ran. I built startup_launch_probe in dev and release, then ran
ctest --test-dir out/build/<preset> --no-tests=error -j 1 --output-on-failure -R '^startup_launch$'
3 times per preset: 6/6 passed. python -B tests/startup_launch_check.py --unit passes as well.

How strong the control is. On this host, startup_launch_probe.exe addresses, started directly 40 times, ended above 2^40 in 40 of 40 runs. So the "at least one of eight default runs above 2^40" control is not marginal here.

Mutant. With ALWAYS_ON (0x1 << 16) in place of ALWAYS_OFF, startup_launch fails at with X2W_LOW_ADDRESSES=1 a block ends at 0x259ff21ffff, above 2^40. Restored, it passes. git diff --check is clean.

Verdict: approve on cbffed0a.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10.
CI: Build and test on Windows passes on cbffed0a. The one review thread is resolved.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6092802346 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2859#pullrequestreview-6092802346). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T19:52:17Z. **Review:** APPROVED --- Independently reviewed `cbffed0a` integrated over `main` `968ddcdf` (tree `b52a33b2`, clean merge). **What I traced.** - **Constants:** both match the SDK. `PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY` is `ProcThreadAttributeValue(7, FALSE, TRUE, FALSE)` = `0x20007`. `..._BOTTOM_UP_ASLR_ALWAYS_OFF` is `0x2 << 16`, inside the `0x3 << 16` mask, where `0x1 << 16` is `ALWAYS_ON`. - **`startup_for_create`:** it copies the caller's `STARTUPINFOW`, including the std handles, into a `STARTUPINFOEXW`, and sets `cb` to the extended size. It returns the attribute buffer and the policy word, so both stay alive across `CreateProcessW`. With the switch off, or when either call fails, it falls back to the unchanged `si`. - **Not tested:** `debug_launch.py` uses the same helper, but no test starts the title through it with the switch on. - **Codex thread:** resolved. `child_env` drops an inherited `X2W_LOW_ADDRESSES` for the control children. **What I ran.** I built `startup_launch_probe` in `dev` and `release`, then ran `ctest --test-dir out/build/<preset> --no-tests=error -j 1 --output-on-failure -R '^startup_launch$'` 3 times per preset: 6/6 passed. `python -B tests/startup_launch_check.py --unit` passes as well. **How strong the control is.** On this host, `startup_launch_probe.exe addresses`, started directly 40 times, ended above 2^40 in 40 of 40 runs. So the "at least one of eight default runs above 2^40" control is not marginal here. **Mutant.** With `ALWAYS_ON` (`0x1 << 16`) in place of `ALWAYS_OFF`, `startup_launch` fails at `with X2W_LOW_ADDRESSES=1 a block ends at 0x259ff21ffff, above 2^40`. Restored, it passes. `git diff --check` is clean. **Verdict:** approve on `cbffed0a`. Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10. CI: `Build and test on Windows` passes on `cbffed0a`. The one review thread is resolved. This reply was AI-assisted.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2851
No description provided.