fix(WUD): reload deletion state during asynchronous wait #1236

Merged
coah80 merged 1 commits from agent/fix/wud-deletion-wait into main 2026-10-05 19:05:01 +00:00
coah80 commented 2026-10-05 19:04:25 +00:00 (Migrated from github.com)

Fix a concrete infinite-wait hazard in the API added by #1232. The old MWCC output loaded deleteState once and branched back only to the comparison. Take an interrupt-protected state snapshot each iteration using existing OS APIs; restore interrupt state before polling again.

Tested base f762dfefbdb3d819bc66729489ce5878e837642b; tested tree ef455492cd.

Parent independently rebuilt, reran host/compiled-loop checks and the original object audit, then rebuilt/retested after the mechanical rebase. All 66 retail functions and 92 other WUD source functions preserve instructions and resolved relocations. Data, full report and linked loadable bytes unchanged. Only non-allocated compiler label strings differ in ELF. The corrected API remains excluded from retail main.elf.

Full 43U + explicit ok pass; DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d. Host regression covers asynchronous success/error and busy paths, and baseline reproduces the hang. This is not hardware testing or a completion claim.

Reproduce: python tools/decomp-assist/verify_wud_delete_wait.py --object build/43U/src/libs/RVL_SDK/src/wud/WUD.o
Audit: tools/decomp-assist/wud-deletion-wait-audit.md. No merge or auto-merge requested.

Note

Fix stale WUDCB.deleteState read in _WUDDeleteStoredDevice wait loop

  • Fixes the asynchronous delete wait in WUD.c: each polling iteration now disables interrupts, samples WUDCB.deleteState into a local byte, restores the prior interrupt state, and compares the snapshot against WUD_STATE_DELETE_START. Previously the loop read the shared field directly, so it could miss state changes made by the WUD callback and alarm machinery.
  • Adds verify_wud_delete_wait.py, a host-side harness that compiles the extracted C function against mock WUD/OS/alarm/storage layers and runs tests covering busy-state rejection, callback-owned requests, interrupt-state preservation, delayed deletion progress, and flush outcomes. It can also audit the compiled object for the expected interrupt-protected polling loop.
  • Adds wud-deletion-wait-audit.md documenting the stale-load defect, the fix, and the object-level evidence.
  • Behavioral Change: _WUDDeleteStoredDevice now restores the caller's interrupt state after each sampled read instead of leaving interrupts disabled for the whole wait.

Macroscope summarized ef35b2e.

Fix a concrete infinite-wait hazard in the API added by #1232. The old MWCC output loaded deleteState once and branched back only to the comparison. Take an interrupt-protected state snapshot each iteration using existing OS APIs; restore interrupt state before polling again. Tested base f762dfefbdb3d819bc66729489ce5878e837642b; tested tree ef455492cd9cc3f08dd7fa52f07fa6750cfc638a. Parent independently rebuilt, reran host/compiled-loop checks and the original object audit, then rebuilt/retested after the mechanical rebase. All 66 retail functions and 92 other WUD source functions preserve instructions and resolved relocations. Data, full report and linked loadable bytes unchanged. Only non-allocated compiler label strings differ in ELF. The corrected API remains excluded from retail main.elf. Full 43U + explicit ok pass; DOL SHA1 26116613f624061ba99c8d1a299aaa6efa85670d. Host regression covers asynchronous success/error and busy paths, and baseline reproduces the hang. This is not hardware testing or a completion claim. Reproduce: python tools/decomp-assist/verify_wud_delete_wait.py --object build/43U/src/libs/RVL_SDK/src/wud/WUD.o Audit: tools/decomp-assist/wud-deletion-wait-audit.md. No merge or auto-merge requested. <!-- 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 stale `WUDCB.deleteState` read in `_WUDDeleteStoredDevice` wait loop > - Fixes the asynchronous delete wait in [WUD.c](https://github.com/coah80/wii-ipl/pull/1236/files#diff-de026f217152eb24014531233d0812ddab4eee3950cd20cca6beafdd6e278ea0): each polling iteration now disables interrupts, samples `WUDCB.deleteState` into a local byte, restores the prior interrupt state, and compares the snapshot against `WUD_STATE_DELETE_START`. Previously the loop read the shared field directly, so it could miss state changes made by the WUD callback and alarm machinery. > - Adds [verify_wud_delete_wait.py](https://github.com/coah80/wii-ipl/pull/1236/files#diff-096c76c7862c18728c037cd30f40acef9bd8567e3fce430351facd38082540d8), a host-side harness that compiles the extracted C function against mock WUD/OS/alarm/storage layers and runs tests covering busy-state rejection, callback-owned requests, interrupt-state preservation, delayed deletion progress, and flush outcomes. It can also audit the compiled object for the expected interrupt-protected polling loop. > - Adds [wud-deletion-wait-audit.md](https://github.com/coah80/wii-ipl/pull/1236/files#diff-c6972e3bcb3118f028aafbd8076b5e80ff6f5177842958e15db74ae753c1ac19) documenting the stale-load defect, the fix, and the object-level evidence. > - Behavioral Change: `_WUDDeleteStoredDevice` now restores the caller's interrupt state after each sampled read instead of leaving interrupts disabled for the whole wait. > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized ef35b2e.</sup> > <!-- Macroscope's review summary ends here --> > <!-- Macroscope's pull request summary ends here -->
coah80 commented 2026-10-05 19:04:59 +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.