mirror of
https://github.com/sp00nznet/xboxrecomp.git
synced 2026-12-06 02:22:30 +00:00
0a8097e9e4
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
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
"""Turn a host RIP from a crash dump back into the guest function it came from.
|
|
|
|
py -3 tools/symbolize.py <game>/bin/<game>.map 0x1405DABEB [0x... ...]
|
|
... | py -3 tools/symbolize.py <game>/bin/<game>.map (reads stdin)
|
|
|
|
Every generated function becomes a real symbol in the linker map, so the map is
|
|
all that is needed -- no PDB, no debugger. Without this a crash report gives a
|
|
bare host address and the only way back to guest code is guesswork; with it the
|
|
report names sub_000ECBF7 directly.
|
|
|
|
Reading from stdin scans for anything that looks like a host code address
|
|
(0x14xxxxxxx) and annotates it, so a whole crash dump can be piped through.
|
|
"""
|
|
|
|
import bisect
|
|
import re
|
|
import sys
|
|
|
|
# " 0001:0000abcd symbol 0000000140401234 f i file.obj"
|
|
_SYM = re.compile(r"\s+[0-9a-fA-F]{4}:[0-9a-fA-F]{8}\s+(\S+)\s+([0-9a-fA-F]{16})\s")
|
|
_ADDR = re.compile(r"0x([0-9a-fA-F]{9,16})")
|
|
|
|
|
|
def load_map(path):
|
|
"""Return (sorted addresses, names) for every public symbol in the map."""
|
|
syms = []
|
|
with open(path, encoding="utf-8", errors="replace") as handle:
|
|
for line in handle:
|
|
match = _SYM.match(line)
|
|
if match:
|
|
syms.append((int(match.group(2), 16), match.group(1)))
|
|
if not syms:
|
|
raise SystemExit("no symbols found in %s -- is it a linker /MAP file?"
|
|
% path)
|
|
syms.sort()
|
|
return [a for a, _ in syms], [n for _, n in syms]
|
|
|
|
|
|
def resolve(addrs, names, rip):
|
|
"""Name the symbol containing rip, with its offset. None if before them all."""
|
|
i = bisect.bisect_right(addrs, rip) - 1
|
|
if i < 0:
|
|
return None
|
|
return names[i], rip - addrs[i]
|
|
|
|
|
|
def main(argv):
|
|
if len(argv) < 2:
|
|
raise SystemExit(__doc__)
|
|
addrs, names = load_map(argv[1])
|
|
|
|
def fmt(rip):
|
|
hit = resolve(addrs, names, rip)
|
|
return "0x%X -> ??" % rip if hit is None else \
|
|
"0x%X -> %s + 0x%X" % (rip, hit[0], hit[1])
|
|
|
|
if len(argv) > 2:
|
|
for arg in argv[2:]:
|
|
print(" " + fmt(int(arg, 0)))
|
|
return 0
|
|
|
|
for line in sys.stdin:
|
|
line = line.rstrip("\n")
|
|
print(line)
|
|
for match in _ADDR.finditer(line):
|
|
rip = int(match.group(1), 16)
|
|
hit = resolve(addrs, names, rip)
|
|
if hit is not None:
|
|
print(" ^ %s + 0x%X" % hit)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv))
|