Skip to content

DM_HITCH_DUMP: all graphics APIs, and safe thread access - #137

Closed
v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:hitch-dump-fixes
Closed

v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:hitch-dump-fixes

Conversation

@v0lumehi

Copy link
Copy Markdown
Contributor

Follow-up to the two DM_HITCH_DUMP points in the review of #134.

  • Every graphics API. dm_present_ns is now written in present_enqueue (nvn_mtl.m), which the NVN present (mtl_present) and the Vulkan and GL layers (mtl_present_ext, from hle_vk.m and hle_gl.m) all go through. The NVN-only write in hle_nvn.c is removed. The tests' weak definitions are unchanged.
  • hitch_main. It no longer uses thr_t pointers after releasing G. hitch_grab copies what a dump line needs (handle, name, wait state, last SVC, registers, the raw pc / lr / frame-pointer chain) into a hitch_t while holding G; thread exit and thr_free need G, so no listed thread is freed or leaves meanwhile. Between suspend and resume it runs only mach calls and memory reads. hitch_log does the module lookup, dladdr and the logging after all threads run again, so a thread holding the dyld lock (or malloc / stdio) cannot deadlock the dump.

Checked: host unit tests and the whole gfx run list pass (GAME=01007EF00011E000); the Mac host builds for Breath of the Wild (NVN) and Hades (Vulkan). Not run in a game.

…s and the dyld lock (follow-up to seedds#134's review). The present time dm_present_ns was written only in the NVN present (hle_nvn.c), so the dump never fired for the Vulkan and GL games; it is now written in present_enqueue (nvn_mtl.m), which mtl_present (NVN), mtl_present_ext (Vulkan: hle_vk.m; GL: hle_gl.m) all reach, and the NVN-only write is gone. hitch_main took thr_t pointers under G, released G, and read the threads afterwards, so a thread that exits and is freed during a dump was a use-after-free; and it called dladdr while the target thread was suspended, which deadlocks if that thread holds the dyld lock. Now hitch_grab copies what a line needs (handle, name, wait state, svc, registers, the raw pc / lr / frame-pointer chain) into a hitch_t while holding G (thread exit and thr_free need G, so no listed thread is freed or leaves), and between suspend and resume only mach calls and memory reads run; hitch_log then looks the symbols up (module table, dladdr) and logs after every thread runs again. The tests' weak dm_present_ns definitions (t_host_stubs.c, t_nvn.c) stay as they are. Checked: the host unit tests and the gfx run list pass (GAME=01007EF00011E000); the Mac host builds for Breath of the Wild (NVN) and Hades (Vulkan). Not run in a game.
seedds added a commit that referenced this pull request Oct 25, 2026
…s and the dyld lock (follow-up to #134's review). The present time dm_present_ns was written only in the NVN present (hle_nvn.c), so the dump never fired for the Vulkan and GL games; it is now written in present_enqueue (nvn_mtl.m), which mtl_present (NVN), mtl_present_ext (Vulkan: hle_vk.m; GL: hle_gl.m) all reach, and the NVN-only write is gone. hitch_main took thr_t pointers under G, released G, and read the threads afterwards, so a thread that exits and is freed during a dump was a use-after-free; and it called dladdr while the target thread was suspended, which deadlocks if that thread holds the dyld lock. Now hitch_grab copies what a line needs (handle, name, wait state, svc, registers, the raw pc / lr / frame-pointer chain) into a hitch_t while holding G (thread exit and thr_free need G, so no listed thread is freed or leaves), and between suspend and resume only mach calls and memory reads run; hitch_log then looks the symbols up (module table, dladdr) and logs after every thread runs again. The tests' weak dm_present_ns definitions (t_host_stubs.c, t_nvn.c) stay as they are. Checked: the host unit tests and the gfx run list pass (GAME=01007EF00011E000); the Mac host builds for Breath of the Wild (NVN) and Hades (Vulkan). From PR #137 (v0lumehi). Also checked on current main: the host unit tests and the gfx run list pass; on the Mac with DM_HITCH_DUMP=20:2, Mario vs. Donkey Kong (NVN) logged two dumps in its opening movie and Balatro (GL, which never dumped before: no present time was written outside NVN) one, every guest thread with its guest frames and host symbols, and both games ran on to the end of the run. Not checked: a Vulkan game (none on the drives; Vulkan presents reach present_enqueue through mtl_present_ext as GL's do)
@seedds

seedds commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Thanks! Landed on main as 188c1d8 (re-committed with a note of the checks). Also checked on current main: the host unit tests and the gfx run list pass; with DM_HITCH_DUMP=20:2, Mario vs. Donkey Kong (NVN) logged two dumps and Balatro (GL) one, every thread with guest frames and host symbols, and both games ran on. Not run in a Vulkan game.

@seedds seedds closed this Oct 25, 2026
@v0lumehi
v0lumehi deleted the hitch-dump-fixes branch October 26, 2026 09:29
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…s and the dyld lock (follow-up to seedds#134's review). The present time dm_present_ns was written only in the NVN present (hle_nvn.c), so the dump never fired for the Vulkan and GL games; it is now written in present_enqueue (nvn_mtl.m), which mtl_present (NVN), mtl_present_ext (Vulkan: hle_vk.m; GL: hle_gl.m) all reach, and the NVN-only write is gone. hitch_main took thr_t pointers under G, released G, and read the threads afterwards, so a thread that exits and is freed during a dump was a use-after-free; and it called dladdr while the target thread was suspended, which deadlocks if that thread holds the dyld lock. Now hitch_grab copies what a line needs (handle, name, wait state, svc, registers, the raw pc / lr / frame-pointer chain) into a hitch_t while holding G (thread exit and thr_free need G, so no listed thread is freed or leaves), and between suspend and resume only mach calls and memory reads run; hitch_log then looks the symbols up (module table, dladdr) and logs after every thread runs again. The tests' weak dm_present_ns definitions (t_host_stubs.c, t_nvn.c) stay as they are. Checked: the host unit tests and the gfx run list pass (GAME=01007EF00011E000); the Mac host builds for Breath of the Wild (NVN) and Hades (Vulkan). From PR seedds#137 (v0lumehi). Also checked on current main: the host unit tests and the gfx run list pass; on the Mac with DM_HITCH_DUMP=20:2, Mario vs. Donkey Kong (NVN) logged two dumps in its opening movie and Balatro (GL, which never dumped before: no present time was written outside NVN) one, every guest thread with its guest frames and host symbols, and both games ran on to the end of the run. Not checked: a Vulkan game (none on the drives; Vulkan presents reach present_enqueue through mtl_present_ext as GL's do)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants