runtime validate ApuAlloc outputs #2487

Closed
KelboLive wants to merge 1 commit from upstream-pr/2495 into main
KelboLive commented 2026-11-25 18:37:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T18:37:30Z.


Adds runtime validation of ApuAlloc outputs with a new fixture test.

Files:

  • (+11/-3)
  • (+90/-30)
  • (+49)

Run: Test project D:/Kelbo AI Dashboard Projects/Xbox2Windows/out/build/dev
Start 112: startup_acphal_apu_free
1/1 Test #112: startup_acphal_apu_free .......... Passed 0.16 sec

100% tests passed out of 1

Total Test time (real) = 0.20 sec

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6611197354 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2495). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-25T18:37:30Z. --- Adds runtime validation of ApuAlloc outputs with a new fixture test. **Files:** - (+11/-3) - (+90/-30) - (+49) Run: Test project D:/Kelbo AI Dashboard Projects/Xbox2Windows/out/build/dev Start 112: startup_acphal_apu_free 1/1 Test #112: startup_acphal_apu_free .......... Passed 0.16 sec 100% tests passed out of 1 Total Test time (real) = 0.20 sec
ChazY11 commented 2026-11-25 20:04:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T19:15:59Z.


Built and run here: both AcpHal cases pass — one of three mutations caught, and the two survivors name the inputs that are missing

startup_acphal_apu_free and cpu_native_acphal_hal both pass on this branch, together with their prerequisites
(cpu_acphal_hal_caller, cpu_acphal_hal_provider, cpu_acphal_hal_provider_faulty, cpu_exe_io, pe_map):

1/2 Test  #97: startup_acphal_apu_free ......   Passed   0.46 sec
2/2 Test #779: cpu_native_acphal_hal ........   Passed   1.60 sec
100% tests passed, 0 tests failed out of 2

Worth recording for anyone else reproducing this: cpu_native_acphal_hal fails with FileNotFoundError on
cpu_acphal_hal_provider_faulty unless that target and cpu_exe_io/pe_map are built too — the failure is a missing
artifact, not a defect. I hit it once before building them.

Three mutations of the new range logic

mutation of src/startup_stubs/acphal.cpp result
the 4 GiB clamp dropped (limit = bytes > 0x100000000ull ? … : bytes → bytes) survived
the null-base test dropped from if (!base || limit <= heap_start || …) survived
the free-side range test dropped (if (heap_base && address >= base + heap_start && …) → if (false)) caught

The caught one is the important half: startup_acphal_apu_free really does assert that a pointer outside the APU
range is rejected on free, so the new validation is load-bearing for the case the fixture builds.

The two survivors are unexercised inputs, not defects

  • 4 GiB clamp. Observable only when the heap is larger than 4 GiB, and the fixture's heap is a fraction of that
    (the churn loop hands out 64 MiB over 30 times). Any heap under 4 GiB takes the same branch either way.
  • !base. Observable only for a free/validate call made before any heap exists. The fixture always allocates
    first, so base is non-null in every path it takes.

Both are cheap to pin if you want them covered: a call to the free entry point before the first allocation (expect the
invalid-argument failure, and no crash), and a heap configured above 4 GiB whose first byte past 4 GiB must be rejected
while the byte below it is accepted. The second one may be the reason the clamp exists at all, so it is the one I would
add a case for.

Environment

Windows 11 build 26300.9974, targets built individually with cmake --build --preset dev --target … (the full target
set does stop in DXC on this host, these do not). Each mutation was built, run, then reverted and rebuilt; the final
state is green.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7172056048 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2495#issuecomment-7172056048). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T19:15:59Z. --- ## Built and run here: both AcpHal cases pass — one of three mutations caught, and the two survivors name the inputs that are missing `startup_acphal_apu_free` and `cpu_native_acphal_hal` both pass on this branch, together with their prerequisites (`cpu_acphal_hal_caller`, `cpu_acphal_hal_provider`, `cpu_acphal_hal_provider_faulty`, `cpu_exe_io`, `pe_map`): ```text 1/2 Test #97: startup_acphal_apu_free ...... Passed 0.46 sec 2/2 Test #779: cpu_native_acphal_hal ........ Passed 1.60 sec 100% tests passed, 0 tests failed out of 2 ``` Worth recording for anyone else reproducing this: `cpu_native_acphal_hal` fails with `FileNotFoundError` on `cpu_acphal_hal_provider_faulty` unless that target and `cpu_exe_io`/`pe_map` are built too — the failure is a missing artifact, not a defect. I hit it once before building them. ### Three mutations of the new range logic | mutation of `src/startup_stubs/acphal.cpp` | result | |---|---| | the 4 GiB clamp dropped (`limit = bytes > 0x100000000ull ? … : bytes` → `bytes`) | survived | | the null-base test dropped from `if (!base \|\| limit <= heap_start \|\| …)` | survived | | the free-side range test dropped (`if (heap_base && address >= base + heap_start && …)` → `if (false)`) | **caught** | The caught one is the important half: `startup_acphal_apu_free` really does assert that a pointer outside the APU range is rejected on free, so the new validation is load-bearing for the case the fixture builds. ### The two survivors are unexercised inputs, not defects - **4 GiB clamp.** Observable only when the heap is larger than 4 GiB, and the fixture's heap is a fraction of that (the churn loop hands out 64 MiB over 30 times). Any heap under 4 GiB takes the same branch either way. - **`!base`.** Observable only for a free/validate call made before any heap exists. The fixture always allocates first, so `base` is non-null in every path it takes. Both are cheap to pin if you want them covered: a call to the free entry point before the first allocation (expect the invalid-argument failure, and no crash), and a heap configured above 4 GiB whose first byte past 4 GiB must be rejected while the byte below it is accepted. The second one may be the reason the clamp exists at all, so it is the one I would add a case for. ### Environment Windows 11 build 26300.9974, targets built individually with `cmake --build --preset dev --target …` (the full target set does stop in DXC on this host, these do not). Each mutation was built, run, then reverted and rebuilt; the final state is green. AI-assisted.
upstream-sync closed this pull request 2026-11-25 21:01:08 +00:00

Pull request closed

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!2487
No description provided.