Files
sp00nz 0a8097e9e4 v0.7.0 "Non-Local": unwind across recompiled frames, fs: segment, kernel gaps
Control flow that leaves a function without returning from it, and the three
places the toolkit got it wrong.

Non-local jumps. A recompiled function is a real C function, so restoring the
guest esp is only half of a longjmp: the abandoned frames stay on the native
stack and control returns into them once the resume point finishes. Each guest
jmp_buf is now paired with a native one taken at the setjmp call site, the only
place a native setjmp is valid, so the frames actually unwind. The CRT's pair is
detected by the "VC20" cookie MSVC stamps into every jmp_buf.

Frameless callees inherited a dead frame: ebp is read through g_seh_ebp, but
only tail jumps and the SEH helpers ever wrote it, so one reached by an ordinary
call got whatever the last tail jump left behind. Published wherever g_ebp is.

The fs: segment prefix was dropped, putting the TIB at guest address 0 - where a
null pointer also lands. A null check written as "cmp byte [ecx], 0" read the
exception chain head's 0xFF and passed; a null store overwrote that head instead
of faulting. Segment overrides are recorded and based at XBOX_FS_BASE, leaving
page zero free for RECOMP_TRAP_NULL to trap.

Kernel exports implemented but never dispatched: RtlUnwind, XeLoadSection,
XeUnloadSection, NtSuspendThread. Each returned success without acting, which is
worse than a stub. NtSuspendThread was the costly one - a worker that parked
itself never stopped, spinning 289M kernel calls; now 9,789.

MCPX APU never started: the frame thread idles on pause_requested, which init
sets and only the test tone ever cleared, so a title enabling the APU through
SECTL/FECTL got an APU that stayed asleep.

cvtps2pi / cvttps2pi implemented; 36 sat inside one title's WMV decoder as
no-op comments.

New xbox_video library: Media Foundation FMV decode onto a D3D8 texture, plus a
window on the guest framebuffer. Orientation comes from IMF2DBuffer's pitch
sign rather than the RGB32 convention, which had the video upside down.

Diagnostics, since a recompiled title offers no debugger: tools/stackwalk.py
guest backtraces, RECOMP_WATCHDOG_SECS, RECOMP_TRACE_ARGS/DEREF, RECOMP_PEEK
and PEEK_CHAIN, RECOMP_WATCH_VA, RECOMP_PB_SCAN/PB_EXEC, RECOMP_FB_WINDOW.

Fixed: duplicate trace symbols broke the link for any title defining its own
recomp_trace_*; they now live once in the kernel.

Verified: 4639 + 211 conformance vectors 0 mismatches, 146 tests, Halo builds.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PZDe6qTWAvohfDtYXbpRyM
2026-08-31 09:36:29 -07:00

54 lines
1.8 KiB
Python

"""Turn the crash handler's raw guest-stack dump into a backtrace.
A recompiled call pushes the guest return address and then jumps, so the guest
stack still carries a return site for every guest frame -- but the native stack
shows only the C functions the translator happened to emit, which is not the
same shape. Reading the guest words back and keeping the ones that land inside
a known function body reconstructs the call chain the title actually took.
A word is kept only if it points *into* a function rather than at its entry:
a return address is by definition mid-body, so entry hits are data (function
pointers, vtable slots) that would otherwise pad the trace with noise.
Usage: <run producing GS lines> | python tools/stackwalk.py functions.json
"""
import bisect
import json
import re
import sys
FUNCTIONS, GS_LINE = sys.argv[1], re.compile(r"GS ([0-9A-Fa-f]{8}) ([0-9A-Fa-f]{8})")
def load(path):
def num(v):
return int(v, 0) if isinstance(v, str) else v
funcs = sorted((num(f["start"]), num(f["end"]), f["name"])
for f in json.load(open(path)))
return funcs, [f[0] for f in funcs]
def main():
funcs, starts = load(FUNCTIONS)
depth = 0
for line in sys.stdin:
m = GS_LINE.search(line)
if not m:
continue
slot, word = int(m.group(1), 16), int(m.group(2), 16)
i = bisect.bisect_right(starts, word) - 1
if i < 0:
continue
start, end, name = funcs[i]
if not start < word < end: # entry hit or past the body: not a return
continue
depth += 1
print(f" #{depth:<3} {slot:08X} -> {word:08X} {name}+0x{word - start:X}")
if not depth:
print(" no guest return addresses on the stack")
if __name__ == "__main__":
main()