Return ApuFree blocks to the APU heap stand-in #1414
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1421"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:11:22Z.
Change
The AcpHal stand-in (permissive mode) served
ApuAllocwith a bump allocator andApuFreewas a logged no-op, so a long run of allocate and free cycles (for example streaming audio banks) ends inE_OUTOFMEMORY. The heap is now a first-fit free list with coalescing in a static table of 4096 extents, guarded by one SRW lock.ApuFreereturns the block and merges it with free neighbours. While nothing is freed the offsets match the old bump allocator.Behaviour chosen where the console's codes are not public (documented in docs/startup-runtime.md): size 0 or a non power-of-two alignment is
E_INVALIDARG(before: size 0 succeeded, a bad alignment was silently set to 16; 0 and below 16 still mean 16);ApuFree(NULL)staysS_OK; an address that does not start a live block (unknown, interior, already freed) isE_INVALIDARGand changes nothing; a reused block is zeroed like fresh heap memory. A refused call leaves heap and outputs unchanged. Size and alignment stay 32-bit.AcpHalAllocateShapeContextsis untouched (separate work).The diff is a bit over the usual size: acphal.cpp is about 100 lines, the rest is the test, one CMake entry and two short docs.
Verification
AI-assisted (Claude Code); commands listed were executed locally. Linux, clang++-19 (mingw target) for the DLL, mingw g++ 14 for the test, Wine:
startup_acphal_apu_free(tests/startup_acphal_apu_free.cpp) against this branch: 8 of 8 runs printok.python3 -B tests/docs_links_check.pyandtests/bidi_controls_check.py: pass. x2w_pipe.py preflight: WARN only (doc overlaps, rebased).To run on the Windows node (not run here, no MSVC):
ctest --preset dev --no-tests=error -R '^(startup_acphal_apu_free|startup_stubs)$' -V. This test is outside--preset prif that preset lists only a subset.Evidence and follow-up
No fixture data: the test builds its own heap with
ApuCreateHeapand checks the block layout from the exports. Follow-ups, separate PRs:AcpHalAllocateShapeContextsfor context types other than 4 (E_NOTIMPL);ApuIsVirtualAddressValidstill tests the whole heap range, not live blocks.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:22:47Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
64b6d2d325ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:25:41Z.
Review: CHANGES_REQUESTED
The Windows Release allocator fixture passed on
64b6d2d. The new lock still does not protect heap publication: ApuCreateHeap tests and assigns heap_base before taking it. Two first-time callers can commit two allocations, then reset the extent table while another caller already holds a block. Make heap creation and publication one locked operation, with the base, size and initial free extent visible together. Add a first-creation concurrency or repeat-init check which proves a live block survives competing heap creation.Please also keep the earlier fallback to 16-byte alignment for non-power-of-two values in this reuse PR unless there is evidence for changing that public input contract. The 2 GiB alignment control assumes an address-space placement the process does not control. Use a guaranteed no-fit request to cover that path.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:29:34Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:29:36Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T11:42:01Z.
Review: APPROVED
Re-reviewed the heap publication fix and alignment fallback. Windows Release startup_acphal_apu_free passed on this head, including the concurrent create and repeat-init controls.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:16:48Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit
64b6d2d3:--preset dev):ctest --preset dev -R '^startup_acphal_apu_free$' --no-tests=error --output-on-failure— 1/1 passed (0.15s)/O2(--preset release):ctest --preset release -R '^startup_acphal_apu_free$' --no-tests=error --output-on-failure— 1/1 passed (0.04s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:16:54Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
64b6d2dℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:37:49Z.
@R0Y00
f9033a9bcovers all three points. (a) ApuCreateHeap now allocates, sets the size, builds the initial free extent and publishes heap_base under heap_lock in one step; a repeat call finds the heap and changes nothing. New first_creation test: 4 threads race the first creation, each allocates right after, all blocks are distinct, a repeat creation leaves them live, a later allocation does not reuse them, and all free. (b) A non-power-of-two alignment (24, 3, 0xFFFFFFFF) means 16 again, as before; the test checks 16-byte alignment. (c) The placement-dependent 2 GiB check is replaced by a request of usable+16 bytes at 2 GiB alignment, which cannot fit wherever the heap lands, and leaves outputs untouched. Windows Server 2025 Debug and Release: startup_acphal_apu_free 1/1.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:22:47Z.
Code review location:
tests/startup_acphal_apu_free.cpp; line 146If the heap straddles a 2 GiB virtual-address boundary, this allocation can legitimately succeed: a heap base of
0x1ffff0000puts its first usable byte at0x200000000, which already satisfies the requested alignment. A Linux probe of the extracted allocator/test logic reproduced this success and five cascading test failures, because this assertion also leaves the unexpectedly successful allocation unreleased. Derive the expected result from the actual heap placement or construct a guaranteed exhaustion case instead of assuming that alignment larger than the heap implies failure.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:22:47Z.
Code review location:
docs/startup-runtime.md; line 475For a refused allocation with an already-populated virtual-address output, this guarantee is false:
ApuAllocunconditionally assignsmemoryto*virtual_address, clearing the previous value to null on failure. Only the optional APU-address output remains unchanged, and the newbad_requests()assertions explicitly require the virtual output to become null. Callers relying on this documented preservation contract can therefore lose an existing pointer during error handling. Document the actual null-on-failure behavior or update the implementation and tests to honor the promise.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:29:34Z.
Code review location:
tests/startup_acphal_apu_free.cpp; line 146Fixed in
71fbc403: probed the actual heap base and derivedbig_align_fitsfrom whether a 2 GiB boundary falls within[probe_addr, probe_addr + usable), freeing the block if it succeeds. Verified on Win2025 (Debug 0.12s, Release /O2 0.04s).Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:29:36Z.
Code review location:
docs/startup-runtime.md; line 475Fixed in
71fbc403: updateddocs/startup-runtime.mdto state that a refused call leaves the heap and optional APU-address output unchanged and writes null to the virtual-address output when non-null.