acphal: follow the 26100 APU heap, flag and alignment rules #527

Merged
csj0oe merged 2 commits from upstream-pr/527 into main 2026-11-29 21:04:36 +00:00
csj0oe commented 2026-11-29 20:09:00 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-29T20:09:00Z.


What

Three APU semantics that a title can observe, plus the default heaps the contract requires:

  • Default heaps: any APU or ACP call before ApuCreateHeap now allocates the documented defaults (64 MB cached and a small non-cached heap) and later ApuCreateHeap returns the "already allocated" error, matching the 26100 contract. ApuHeapGetState reports the "not allocated" error only when the defaults themselves cannot be allocated.
  • Second heap: ApuCreateHeap returns APU_E_HEAP_ALREADY_ALLOCATED (0x8ACA0001) instead of S_OK, and rejects a zero cached size with E_INVALIDARG.
  • Allocation flags and alignment: ApuAlloc routes by the cached/non-cached flag, rejects unknown flags and alignments of 0, below 4 or non-power-of-two with E_INVALIDARG instead of clamping, and takes SHAPE contexts from the non-cached heap.

MACRO values were verified with a compiler static_assert against the supplied header, not by arithmetic.

Verification

  • Failing first, then 9 tests pass on Linux and as a real x64 binary under Proton GE, exercising the #[cfg(windows)] path with real address-space calls.
  • Sensitivity proven by re-introducing each defect and watching the matching test fail.
  • The export table is unchanged (10 names/ordinals); python tuxbox.py check --no-gpu 8/8.

Not covered

  • No GPUs or title launches; nothing here was exercised against a real title.
  • ApuCreateHeap(0, …) now returns E_INVALIDARG because no recorded call passes a zero cached size; the import exists, so the arguments are unrecorded rather than proven absent.
  • ApuMap*, ApuIsVirtualAddressValid and ApuFree answer without allocating the defaults, which is more generous than the console and never a new failure.
  • Related earlier work: #410 (reusing freed APU heap blocks and reporting the heap state); this change does not alter that reuse path.
<!-- greyfinch-sync:brcly/TuxBox:issue:5554623071 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/527). Originally posted by [csj0oe](https://github.com/csj0oe) on 2026-11-29T20:09:00Z. --- ## What Three APU semantics that a title can observe, plus the default heaps the contract requires: - **Default heaps:** any APU or ACP call before `ApuCreateHeap` now allocates the documented defaults (64 MB cached and a small non-cached heap) and later `ApuCreateHeap` returns the "already allocated" error, matching the 26100 contract. `ApuHeapGetState` reports the "not allocated" error only when the defaults themselves cannot be allocated. - **Second heap:** `ApuCreateHeap` returns `APU_E_HEAP_ALREADY_ALLOCATED` (`0x8ACA0001`) instead of `S_OK`, and rejects a zero cached size with `E_INVALIDARG`. - **Allocation flags and alignment:** `ApuAlloc` routes by the cached/non-cached flag, rejects unknown flags and alignments of 0, below 4 or non-power-of-two with `E_INVALIDARG` instead of clamping, and takes SHAPE contexts from the non-cached heap. `MACRO` values were verified with a compiler `static_assert` against the supplied header, not by arithmetic. ## Verification - Failing first, then 9 tests pass on Linux and as a real x64 binary under Proton GE, exercising the `#[cfg(windows)]` path with real address-space calls. - Sensitivity proven by re-introducing each defect and watching the matching test fail. - The export table is unchanged (10 names/ordinals); `python tuxbox.py check --no-gpu` 8/8. ## Not covered - No GPUs or title launches; nothing here was exercised against a real title. - `ApuCreateHeap(0, …)` now returns `E_INVALIDARG` because no recorded call passes a zero cached size; the import exists, so the arguments are unrecorded rather than proven absent. - `ApuMap*`, `ApuIsVirtualAddressValid` and `ApuFree` answer without allocating the defaults, which is more generous than the console and never a new failure. - Related earlier work: #410 (reusing freed APU heap blocks and reporting the heap state); this change does not alter that reuse path.
brcly commented 2026-11-29 20:38:02 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-29T20:38:02Z.


Thanks. From reading, this looks fine: honest local answers and tests for each case. We're adding Lanes self-test scenarios that call these providers, so they're checked without booting a title. We'll merge it once those pass with it.

<!-- greyfinch-sync:brcly/TuxBox:comment:7262236280 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/527#issuecomment-7262236280). Originally posted by [brcly](https://github.com/brcly) on 2026-11-29T20:38:02Z. --- Thanks. From reading, this looks fine: honest local answers and tests for each case. We're adding Lanes self-test scenarios that call these providers, so they're checked without booting a title. We'll merge it once those pass with it.
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
brcly/TuxBox!527
No description provided.