Repository navigation
Conversation
Presses menu_button, waits a swept delay, sends machine:reset and requires the device to keep answering. It reproduces the use-after-free of the menu's windows (REST reset releases the UI from the HTTP task while the menu task draws) that stops the device on a fast host link. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
UserInterface::release_host() is called by C64_Subsys::executeCommand from whichever task runs the command; REST machine:reset runs it on the HTTP task. That deinit()ed the menu's windows while the menu task was still drawing them (appear() / TreeBrowserState::draw_item), a use-after-free that ends in a Nios exception and a dead device. A caller on another task now only requests the teardown; run_once() performs it between draws. The caller waits up to 2 s and carries on if the menu task is busy in a blocking dialog, the request then being served when it returns. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A REST caller that holds the C64 ownership lock waits for the menu task to tear down; the menu task can then block on that same lock before it reaches the loop again. Clearing the request once the windows are gone lets the caller go at once instead of timing out after 2 s. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… going on A request from another task that the menu task does not serve within 2 s is withdrawn and release_host() returns false. Every C64_Subsys caller (reset, unfreeze, clear memory, reboot, start cartridge, DMA loads and raw DMA) then returns an error and leaves the machine alone, so a REST reset with a menu popup open answers an error instead of resetting under a live menu. The destructor clears a client that points at it and the owner task. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
popup, string_box, choice and the other blocking loops already end on a menu button push. A pending request from release_host() now ends them the same way, so run_once() can serve it and a REST reset with a popup open resets instead of failing after the 2 s wait. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Opens the Save REU Memory string box in the menu task and resets over REST; the device must reset and answer. RETURN is pressed only after the highlighted row has been read. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The client pointer is private to C64; the helper and the UserInterface destructor need friend access or a public accessor to reach it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Navigating to a string box passed rows next to Power OFF and the highlight could not be read reliably; F3 opens the help screen, which runs in the same kind of nested loop, with a single key and no row activated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Ending a blocking popup, choice or string_box on a foreign request returns 0, which several callers read as consent: filetype_bin.cc (BUTTON_NO: an unverified ROM is copied or set), network_esp32.cc (choice 0 is "Open", so a connect without a password, or a half-typed one, goes ahead) and c1541.cc (continue without saving). While a blocking dialog is open, a release request from another task therefore times out and its caller fails cleanly (REST reset answers an error; machine and menu are untouched). That is the known limit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…he clients - The release request is one state word (none, requested, serving) changed in a critical section, so the 2 s withdrawal cannot overlap a serve; a caller returns true if the menu closed meanwhile. The wait runs to a tick deadline. - run_once() leaves the loop after a served request, so MENU_EXIT/HIDE in the same pass does not tear the windows down a second time. - A refused release now fails the command: the DMA load and raw DMA commands set SSRET_INTERNAL_ERROR, the socket DMA reset closes the connection and the control target reboot answers "8A,MENU NOT RELEASED". - Drop C64::drop_client and the destructor block; the case cannot occur (menus that are deleted run on a stream and never use run_once or the C64 client). - Known limit, in the code comment: while a blocking dialog is open the menu task cannot serve the request, so the caller fails after the wait. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…changes nothing With the help screen open, machine:reset must answer an error within a few seconds, leave the help screen up, keep the device answering, and a reset after closing the menu must succeed. A refused reset in the race rounds is counted, not a failure. Add the suite to the tests/README.md matrix (only its own row; the matrix has other stale rows at the base). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
SocketDMA now reads the status of the reset command it runs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Restores the nested-loop abort (reverting the revert): a REST reset with the help screen open resets, as on master, instead of failing. Each loop that ends because another task asked for the teardown returns what Escape returns in it, never 0 and never a yes: string_box and string_edit -1, choice -1, forms MENU_CLOSE; a popup has no Escape, so it returns its Cancel, else No, else Ok button (the custom-button popup its last button). The editor/help and monitor loops are void and just return. The test row expects a clean reset again and guards this unwind path; it is not a RED reproducer. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Ending a question or input dialog on a release request hands its caller a result it can read as an answer: a No on c1541.cc "Save?" drops the user's disk writes, and a -1 from string_box is truthy in config_menu.cc and its sibling callers, whose half-edited buffer is then committed. So popup, choice, string_box, string_edit, forms, the hex editor and the monitor are not ended. Known limit: a REST reset is refused (HTTP 500, machine and dialog untouched) while a question or input dialog is open on the menu. Only run_editor(const char *, int), the read-only text viewer (help, logs), closes on the request; a REST reset with the help screen open resets. This replaces the wording of the nested-loop commits before it, where every nested loop returned its Escape value. The race test fails if more than 3 of 60 resets are refused. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Only the read-only viewer (the help screen) closes on the release request; question and input dialogs do not, and a REST reset gets HTTP 500 while one is open. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1111.
A REST
machine:resetthat arrived while the menu was opening deleted the menu's windows from the HTTP task while the menu task was still drawing them, and the device stopped answering.What changes
UserInterface::release_host()now checks which task calls it.run_once(), and runs thedeinit()loop itself. The request is a single state word (none, requested, serving) changed in a critical section, so a request that times out is withdrawn cleanly and cannot overlap a serve in progress.release_host()returns false and its callers fail without touching the machine:C64_Subsysunfreeze, reset, clear memory, reboot and start cartridge answerSSRET_INTERNAL_ERROR(REST reset answers HTTP 500); the DMA load and raw DMA commands do the same; the socket DMA reset closes the connection; the control target reboot answers8A,MENU NOT RELEASED.string_boxthatconfig_menu.cctreats as true. So while one of these is open, a REST reset is refused with HTTP 500 and the machine and the dialog are untouched. This is a known limit.Relation to #1109
#1109 is merged, and this branch now contains it. Both touch
dma_load_raw_buffer. #1109 takes the ownership lock at the top of that function, so whenrelease_host()is refused there, the function now callsc64->unlock_ownership()beforereturn -1. Without that line the lock would stay held. #1109 alone does not fix this crash: on a build with only #1109, the same load test crashed the device in the menu task.Tests
New suite
menu-reset-race(tests/e2e/api/menu_reset_race_test.py, registered inrun-tests, row added to the matrix intests/README.md):machine:reset; the device must keep answering. It fails if more than 3 of the 60 resets are refused.Hardware results, on an Ultimate 64 Elite over wired Ethernet, firmware loaded volatile over JTAG. All of these rows ran on builds made before master was merged into this branch:
fe40f0e5f)dc301f291)5e3614c95)After merging master (head
e1dfbaaaf):make host_testspasses in the Linux container, and the u64 and u64ii builds pass the size report. The merge left the fix's code unchanged, apart from theunlock_ownership()line described above. The tested fix-plus-#1109 build5e3614c95has identicalsoftware/io/c64sources. The only differences in the fix's own files are unrelated upstream edits inuserinterface.cc(null checks on the progress box and a freed message when the queue is full). I did not re-run the hardware rows on the merged head.The refusal with a question dialog open is untested on hardware. The only dialogs I could reach with keys are in the C64 Machine submenu, next to Power Off and the reboot rows, and I did not want an automated test navigating there.
The U2+ (Nios) and U2 (RISC-V) applications were compiled and linked before the merge, and not rebuilt since. I could not build their images here. U2+L is not built.
Written with Claude Fable 5.2 and Claude Sonnet 5.5 in Claude Code.
🤖 Generated with Claude Code