acphal: AcpHalReleaseShapeContexts takes no argument (RT-ACPHAL-RELEASE) #405

Open
github-bot wants to merge 1 commit from github-bot/gh-405 into main AGit
Owner

@⁠Kokonotcu on GitHub · 2026-11-24 04:44 UTC · original
Kokonotcu:pr/acphal-release-abi → main · +14 −14 · 2 files · 1 commits · open

Claim: RT-ACPHAL-RELEASE (#14).

What was wrong. The GDK's AcpHalReleaseShapeContexts() has no parameter: it frees what AcpHalAllocateShapeContexts allocated. The shim declared it as AcpHalReleaseShapeContexts(SHAPE_CONTEXTS* ctx = nullptr) and, for a non-null ctx, wrote nullptr into six array pointers through it. A caller passes nothing, so ctx is whatever RCX holds at the call, and six words are written through a stale pointer. In a test that calls it the way the title does (no argument) this showed up as heap corruption, 0xc0000374, in about one run in three; in the title the same writes land in its own memory.

Change. The function takes no argument and only frees its recorded arrays. The caller's structure stays the caller's to clear.

Test. acphal_test now calls it with a stand-in for a stale RCX (a block of 0xAA bytes) and checks the block comes back untouched; before this change the six pointer slots in it were zeroed.

Tested on Windows 10, i7-11800H, RTX 3080 Laptop (no GPU needed): acphal_test passes 10 of 10 repeats under ctest (--repeat until-fail:10), on this branch based on main ece4ba5b3.

🤖 Generated with Claude Code

**@⁠Kokonotcu** on GitHub · 2026-11-24 04:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/405) `Kokonotcu:pr/acphal-release-abi` → `main` · +14 −14 · 2 files · 1 commits · open Claim: RT-ACPHAL-RELEASE (#14). **What was wrong.** The GDK's `AcpHalReleaseShapeContexts()` has no parameter: it frees what `AcpHalAllocateShapeContexts` allocated. The shim declared it as `AcpHalReleaseShapeContexts(SHAPE_CONTEXTS* ctx = nullptr)` and, for a non-null `ctx`, wrote `nullptr` into six array pointers through it. A caller passes nothing, so `ctx` is whatever RCX holds at the call, and six words are written through a stale pointer. In a test that calls it the way the title does (no argument) this showed up as heap corruption, `0xc0000374`, in about one run in three; in the title the same writes land in its own memory. **Change.** The function takes no argument and only frees its recorded arrays. The caller's structure stays the caller's to clear. **Test.** `acphal_test` now calls it with a stand-in for a stale RCX (a block of `0xAA` bytes) and checks the block comes back untouched; before this change the six pointer slots in it were zeroed. Tested on Windows 10, i7-11800H, RTX 3080 Laptop (no GPU needed): `acphal_test` passes 10 of 10 repeats under ctest (`--repeat until-fail:10`), on this branch based on `main` `ece4ba5b3`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The GDK's AcpHalReleaseShapeContexts() has no parameter: it frees what
AcpHalAllocateShapeContexts allocated. The shim declared it as
AcpHalReleaseShapeContexts(SHAPE_CONTEXTS* ctx = nullptr) and, when ctx
was non-null, wrote nullptr into six array pointers through it. A caller
passes nothing, so ctx is whatever RCX holds at the call, and six words
were written through a stale pointer: heap corruption (0xc0000374) about
one run in three in a test that calls it as the title does, and the same
writes into the title's memory at its call.

The function now takes no argument and only frees its recorded arrays;
the caller's own structure stays the caller's.

acphal_test calls it with a stand-in for a stale RCX (a block of 0xAA)
and checks the block comes back untouched; before, the six pointer slots
were overwritten with zeros.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:58:17 +00:00
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-24 10:34 UTC · original

The signature fix is right: the GDK reference gives HRESULT AcpHalReleaseShapeContexts() with no parameters (https://devdocs.xbox.com/reference/audio/acphal/functions/acphalreleaseshapecontexts). It also fits docs/audio_hal_exe_calls.md, where the title's one call site loads the handle AcpHalCreate returned into the first argument register, so the old code wrote six nulls into that object. Not built here (Windows-only shim). Nit: the same GDK page lists ACP_E_NOT_ALLOCATED for a release without an allocation, while the test expects S_OK from the second call; that was so before this PR, but may be worth a follow-up. AI-assisted review.

**@⁠Oliwettoo** on GitHub · 2026-11-24 10:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/405#issuecomment-7128962214) The signature fix is right: the GDK reference gives `HRESULT AcpHalReleaseShapeContexts()` with no parameters (https://devdocs.xbox.com/reference/audio/acphal/functions/acphalreleaseshapecontexts). It also fits `docs/audio_hal_exe_calls.md`, where the title's one call site loads the handle `AcpHalCreate` returned into the first argument register, so the old code wrote six nulls into that object. Not built here (Windows-only shim). Nit: the same GDK page lists `ACP_E_NOT_ALLOCATED` for a release without an allocation, while the test expects `S_OK` from the second call; that was so before this PR, but may be worth a follow-up. AI-assisted review.
Author
Owner

@⁠nicoco23 on GitHub · 2026-11-26 16:29 UTC · original · reviewed

The bug this fixes is real (six pointer writes through an argument the caller never passes), but main already covers it: AcpHalReleaseShapeContexts in runtime/shims/acphal.cpp now takes an unused void* /*hal*/ and writes nothing through it. The only part not on main is the test's stale-RCX check (a 0xAA block that must come back untouched), which would still be a useful regression test on its own. With the conflict and main moved on, it may be simpler to close this and send just that test. AI-assisted review (Claude Code).

**@⁠nicoco23** on GitHub · 2026-11-26 16:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/405#pullrequestreview-6077566078) · **reviewed** The bug this fixes is real (six pointer writes through an argument the caller never passes), but main already covers it: `AcpHalReleaseShapeContexts` in `runtime/shims/acphal.cpp` now takes an unused `void* /*hal*/` and writes nothing through it. The only part not on main is the test's stale-RCX check (a 0xAA block that must come back untouched), which would still be a useful regression test on its own. With the conflict and main moved on, it may be simpler to close this and send just that test. AI-assisted review (Claude Code).
This pull request has changes conflicting with the target branch.
  • runtime/shims/acphal.cpp
  • runtime/test/acphal_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/405/head:github-bot/gh-405'
git switch 'github-bot/gh-405'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-405'
git switch 'github-bot/gh-405'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-405'
git switch 'github-bot/gh-405'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-405'
git switch 'main'
git merge --squash 'github-bot/gh-405'
git switch 'main'
git merge --ff-only 'github-bot/gh-405'
git switch 'main'
git merge 'github-bot/gh-405'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.