fix(chans): assemble integer immediates without signed-shift overflow #1056

Merged
coah80 merged 1 commits from agent/bittle/chans-immediate-review into main 2026-10-03 05:27:04 +00:00
coah80 commented 2026-10-03 05:26:17 +00:00 (Migrated from github.com)

Source-width correction

VmLoadImmInteger assembled big-endian immediate bytes by repeatedly left-shifting an s64. An eight-byte immediate whose first byte has its high bit set reaches signed-shift overflow. Accumulate in u64 and convert only the completed bit pattern to vmInteger at CHANSVmSetInteger.

Original PPC implements modulo-64 shift/OR, preserving all byte bits and passing the high/low result words in r5/r6. Short immediates remain non-sign-extending. The out-of-range unsigned-to-signed final conversion is implementation-defined in C; the configured MWCC behavior is verified. No universal portability claim, no fuzzy gain.

Independent verification

Rebased on 404a8675f1285007154a5aef7bbd755a691e8739; tested tree 1b490a2b4f.

  • Source-extracted baseline UBSan reproduces the eight-byte shift overflow
  • Candidate passes 315,813 cases across widths 1/2/4/8 plus zero, including high-bit boundaries, callback VM/output pointers, return value and captured result
  • Original-DOL instruction interpreter independently passes 165,813 cases, checking big-endian bytes, short-width behavior and fixed r3/r4/r5:r6 tail-call contract
  • Helper remains exact, 17/17 instructions; entire CHANSVm object and complete 1,027-unit report unchanged, all allocated payloads/canonical relocations unchanged
  • Unit 222/233 exact, matched code 38,136/53,564 and data 6,904/6,904 preserved
  • Pool 125/125 identical; literal audit 233 functions/40 arguments with no candidates/skips/errors
  • Full 43U build/progress/report/DOL passed; SHA1 26116613f624061ba99c8d1a299aaa6efa85670d; worktree/diff checks pass

Focused helper/slice tests, not full VM or Wii runtime execution. Detailed evidence: tools/decomp-assist/CHANSVm-immediate-width-20261003.md. No linking flags, headers or unrelated decoder changes.

Note

Fix signed-shift overflow when assembling integer immediates in VmLoadImmInteger

Changes the immediate-byte accumulator in VmLoadImmInteger from signed 64-bit to unsigned 64-bit in CHANSVm.c. The big-endian byte assembly and masking are unchanged, and the result is explicitly converted to vmInteger before calling CHANSVmSetInteger. Also documents the correction, calling conventions, and verification results in CHANSVm-immediate-width-20261003.md. Risk: eight-byte immediates with the high bit set still convert to vmInteger in an implementation-defined way when the value exceeds its signed range.

Macroscope summarized 20f3a4a.

## Source-width correction VmLoadImmInteger assembled big-endian immediate bytes by repeatedly left-shifting an s64. An eight-byte immediate whose first byte has its high bit set reaches signed-shift overflow. Accumulate in u64 and convert only the completed bit pattern to vmInteger at CHANSVmSetInteger. Original PPC implements modulo-64 shift/OR, preserving all byte bits and passing the high/low result words in r5/r6. Short immediates remain non-sign-extending. The out-of-range unsigned-to-signed final conversion is implementation-defined in C; the configured MWCC behavior is verified. No universal portability claim, no fuzzy gain. ## Independent verification Rebased on 404a8675f1285007154a5aef7bbd755a691e8739; tested tree 1b490a2b4fec53c69ab831aa806d72208d756263. - Source-extracted baseline UBSan reproduces the eight-byte shift overflow - Candidate passes 315,813 cases across widths 1/2/4/8 plus zero, including high-bit boundaries, callback VM/output pointers, return value and captured result - Original-DOL instruction interpreter independently passes 165,813 cases, checking big-endian bytes, short-width behavior and fixed r3/r4/r5:r6 tail-call contract - Helper remains exact, 17/17 instructions; entire CHANSVm object and complete 1,027-unit report unchanged, all allocated payloads/canonical relocations unchanged - Unit 222/233 exact, matched code 38,136/53,564 and data 6,904/6,904 preserved - Pool 125/125 identical; literal audit 233 functions/40 arguments with no candidates/skips/errors - Full 43U build/progress/report/DOL passed; SHA1 26116613f624061ba99c8d1a299aaa6efa85670d; worktree/diff checks pass Focused helper/slice tests, not full VM or Wii runtime execution. Detailed evidence: tools/decomp-assist/CHANSVm-immediate-width-20261003.md. No linking flags, headers or unrelated decoder changes. <!-- Macroscope's pull request summary starts here --> <!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. --> <!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. --> > [!NOTE] > ### Fix signed-shift overflow when assembling integer immediates in `VmLoadImmInteger` > Changes the immediate-byte accumulator in `VmLoadImmInteger` from signed 64-bit to unsigned 64-bit in [CHANSVm.c](https://github.com/coah80/wii-ipl/pull/1056/files#diff-fcd94241dcc82f12e50e6a224211f94b32d8c83c08ab0880c20261cea99b4f75). The big-endian byte assembly and masking are unchanged, and the result is explicitly converted to `vmInteger` before calling `CHANSVmSetInteger`. Also documents the correction, calling conventions, and verification results in [CHANSVm-immediate-width-20261003.md](https://github.com/coah80/wii-ipl/pull/1056/files#diff-3f00c03a8a237f191fa1ff94a32ab103a65de866fa26a7e895649901c04e24de). Risk: eight-byte immediates with the high bit set still convert to `vmInteger` in an implementation-defined way when the value exceeds its signed range. > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized 20f3a4a.</sup> > <!-- Macroscope's review summary ends here --> > <!-- Macroscope's pull request summary ends here -->
coah80 commented 2026-10-03 05:27:02 +00:00 (Migrated from github.com)

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.
Sign in to join this conversation.