diff --git a/CMakeLists.txt b/CMakeLists.txt index d3db3a2d94..a31ea05ffc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3431,6 +3431,12 @@ if(EXISTS "${INTAKE_PYTHON}") add_test(NAME cpu_aot_direct_calls COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/cpu/calls_check.py" check "$" "$" "$") + cpu_asm_fixture(cpu_recursion recursion) + # The exports from tail_ping on exist only to be refused; the test translates each alone. + cpu_translation(cpu_recursion cpu_switch_aot sum_export,parity_export,walk_export,fold_export) + add_test(NAME cpu_aot_recursion COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/cpu/recursion_check.py" "$" + "$" "$") cpu_asm_fixture(cpu_call_entries call_entries) cpu_translation(cpu_call_entries cpu_switch_aot entry_caller,entry_tail) add_test(NAME cpu_aot_call_entries COMMAND "${INTAKE_PYTHON}" -B diff --git a/docs/experiments.md b/docs/experiments.md index a0a10299eb..1bf0274d84 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -2792,9 +2792,13 @@ A function may use its stack frame. A forward pass over the control-flow graph g `cpu_aot_stack_frames` builds [`frame.asm`](../tests/cpu/frame.asm), with the unwind directives each prologue needs, and translates nine exports. `push_loop` pushes and pops RBX and RSI and uses them in a loop. `spill_widths` allocates 24 bytes, stores 8, 4, 2 and 1 bytes, reads them back in overlapping pieces, adds to a slot in place, and uses `SETB` into the frame and `CMOVL` from it. `home_save` has the MSVC `/O2` shape: it saves RBX and RSI into home space with `MOV [RSP+8], RBX` and `MOV [RSP+10h], RSI` before `PUSH RDI` and `SUB RSP, 20h`, restores them with `MOV` on each of two returns, and carries the unwind codes MSVC writes for that prologue. `home_args` is the `cl /Od` output for a small C function that stores its arguments to home space, writes a local on both sides of a branch and reloads it. `two_paths` pushes RSI on one path and RDI on the other, rejoins at the same depth, and returns early on a third path after restoring RBX. `home_spill` spills two arguments into home space with no allocation of its own, and `loop_counter` keeps a counter and an accumulator in the frame across a loop's back edge. `realloc_slot` releases its allocation with `ADD RSP`, allocates the same bytes again and writes the slot before reading it. `frame_bound`, whose frame array is exactly 4,096 bytes, is translated and compiled but never called. Through the register probe, each original and translated export is compared with a Python reference over the direct-call input pairs, on the return value, the guarded trace, RBX and RSI, and every path of each export is taken. The probe shows that the original saves and restores RBX and RSI and that the translation leaves the caller's RBX and RSI intact. It does not show that the translation reproduces the original's save and restore: the generated locals are not the physical registers, and the host compiler saves and restores those itself. The test checks that the built source is the translation of the export list, that each frame array has the expected size, and that `rsp` appears nowhere in the generated C++. Thirty-two controls must be rejected. Twenty-six are copies of the image with one or two instructions replaced by others of the same length: an unbalanced `POP`, two paths that join at different depths, a loop that pushes on every iteration, a nonvolatile register not restored on one path, restored from another register's slot by `MOV` or by `POP`, or loaded into RAX from its save slot, a local written on one path only, home space never written, a 4-byte store removed under a later 8-byte read, a loop counter written only on the back edge, a stack argument at entry RSP + 40, a read and a write of the return address, `LEA RAX, [RSP+8]`, `MOV RAX, RSP`, `SUB RSP, RCX`, `SUB` and `ADD RSP` by 14h, `ADD RSP` at entry, a `JAE` left reading the flags of `SUB RSP`, an access below RSP, a frame of 4,112 bytes, `realloc_slot` without the store into its second allocation, `ADD RBX, RCX` on the caller's RBX, `PUSH RAX` and `PUSH 5`. The six others are exports rejected as written: a saved RBX whose slot is released by `ADD RSP` and allocated again before `POP RBX`; a slot that `POP` read and released, allocated again and read without a new store; a RIP-relative address spilled to the frame and reloaded, refused at the store as a read of an undefined register; RBX saved twice and reloaded from the 8 bytes that straddle the two copies; RBX pushed as data after only BL was written; and a register read after `POP` restored it. With MSVC 14.52 `cl`, `link` and `ml64` run under Wine on Linux, 1,992 calls per side matched and every control was rejected. The Windows job runs the same test. Run `ctest --preset dev --no-tests=error -R '^cpu_aot_stack_frames$' -V`. -The same translator follows direct calls and tail jumps to other functions of the image ([#317](https://github.com/R0Y00/Xbox2Windows/issues/317), step 2). A `CALL rel32`, or a direct `JMP` that leaves the function's owned ranges, must target a function entry of this image: the first byte of a verified primary runtime function (an unchained `.pdata` record with version 1 or 2 unwind data and a non-empty interval in executable code), or a non-forwarded code export in an executable section that lies outside every runtime-function interval. The start of a chained secondary range, an interior label (exported or not), a record start with any other unwind header, a forwarded export and a data export are not entries, and the message says which of these the target is. Each callee is translated once into the same source, as a static function named `fn_` that takes RCX, RDX, R8 and R9, and is defined before its first caller. A call to the caller's own entry is rejected as self-recursion and any longer cycle as mutual recursion. A caller is rejected when any callee is, and the message names the callee's RVA and its reason. A callee records how many low bytes of each argument register it may read while that register may still hold its entry value, and the caller must have those bytes defined at the call. After a call, RAX has the callee's return width of defined bytes. RCX, RDX and R8 to R11, the flags and the callee's 32-byte home space at RSP are undefined. The return address the `CALL` pushes and the callee's own frame lie below RSP, where the frame proof already holds every byte unwritten, because the bytes that `ADD RSP` and `POP` leave below RSP become unwritten; so they stay undefined if RSP later falls back over them. Nonvolatile registers keep their state, because each callee is itself checked to restore every one, and so do the other frame bytes, including saves by `MOV` into the caller's own home space above entry RSP, which the callee's home space cannot reach. RSP must be 8 mod 16 from entry at a call, so the native call is aligned, and the callee's home space must lie below the return address. A tail jump is checked like a `RET`, with RSP at its entry value and every nonvolatile register restored, and contributes the callee's return width. The callee's frame is its own array, so no frame address crosses a call. A frame address passed to a callee (`LEA RCX, [RSP+20h]`), stack arguments, indirect calls, callees with no reachable normal return, import thunks, and targets with no unwind entry or export (such as leaves that MSVC emits without `.pdata`) unless the invoker binds them as described below, stay rejected. +The same translator follows direct calls and tail jumps to other functions of the image ([#317](https://github.com/R0Y00/Xbox2Windows/issues/317), step 2). A `CALL rel32`, or a direct `JMP` that leaves the function's owned ranges, must target a function entry of this image: the first byte of a verified primary runtime function (an unchained `.pdata` record with version 1 or 2 unwind data and a non-empty interval in executable code), or a non-forwarded code export in an executable section that lies outside every runtime-function interval. The start of a chained secondary range, an interior label (exported or not), a record start with any other unwind header, a forwarded export and a data export are not entries, and the message says which of these the target is. Each callee is translated once into the same source, as a static function named `fn_` that takes RCX, RDX, R8 and R9, and is defined before its first caller. A call may close a call cycle, as described below. A caller is rejected when any callee is, and the message names the callee's RVA and its reason. A callee records how many low bytes of each argument register it may read while that register may still hold its entry value, and the caller must have those bytes defined at the call. After a call, RAX has the callee's return width of defined bytes. RCX, RDX and R8 to R11, the flags and the callee's 32-byte home space at RSP are undefined. The return address the `CALL` pushes and the callee's own frame lie below RSP, where the frame proof already holds every byte unwritten, because the bytes that `ADD RSP` and `POP` leave below RSP become unwritten; so they stay undefined if RSP later falls back over them. Nonvolatile registers keep their state, because each callee is itself checked to restore every one, and so do the other frame bytes, including saves by `MOV` into the caller's own home space above entry RSP, which the callee's home space cannot reach. RSP must be 8 mod 16 from entry at a call, so the native call is aligned, and the callee's home space must lie below the return address. A tail jump is checked like a `RET`, with RSP at its entry value and every nonvolatile register restored, and contributes the callee's return width. The callee's frame is its own array, so no frame address crosses a call. A frame address passed to a callee (`LEA RCX, [RSP+20h]`), stack arguments, indirect calls, callees with no reachable normal return, import thunks, and targets with no unwind entry or export (such as leaves that MSVC emits without `.pdata`) unless the invoker binds them as described below, stay rejected. -`cpu_aot_direct_calls` builds [`calls.asm`](../tests/cpu/calls.asm) and translates seven exports, which reach three unexported callees placed below them. `call_leaf` calls a leaf from a frame and keeps the trace pointer in RBX across the call. `chain3` calls `mid_step`, which spills RDX into its own frame above the callee's home space, calls the same leaf and reloads it, so the leaf is shared. `narrow_call` calls a callee that defines only AL and widens it with `MOVZX`. `narrow_tail` tail-jumps to that callee and reports width 1, `tail_call` tail-jumps to the leaf, and `tail_after_frame` pops its frame before tail-jumping to `mid_step`. `home_save_call` has the MSVC `/O2` save shapes around a call: RBX saved by `MOV` into its own home space before `SUB RSP, 28h`, and RSI saved by `MOV` into the allocation above the callee's home space. Through the register probe, the original must match a Python reference, and the translation must match the original on the defined return bytes, the guarded trace, RBX and RSI over 545 input pairs per export. The test checks that each callee is defined exactly once and that the reported return widths are 8 except for `narrow_tail`. Twenty copies must be rejected with their stated reason: a call to the caller's own entry, a call from `mid_step` back to `chain3`, calls into an instruction interior and to an instruction boundary that is not an entry, a target outside the image and one in `.rdata`, reads of RCX, R8 and the full RAX after a call, a second call to the leaf whose RCX and RDX the first call left undefined, a `SETE` after a call, a stack-argument read in a callee and an unsupported instruction two levels down, a spill and a `MOV` save of RSI moved into the callee's home space and reloaded after the call, a call at entry RSP - 0x30 and one at entry RSP - 0x8, a tail jump with a frame still allocated, a tail jump with RBX not restored, and, as built, `below_call`, which stores a slot at entry RSP - 0x40, raises RSP for a call whose return address overwrites it, and reloads it after RSP falls back (natively it returns the return address). Removing the volatile clobber accepts the RCX control, keeping RAX fully defined after a call accepts the narrow control, keeping the callee's home space defined accepts the spill control, dropping the callees' argument demands accepts the second-call control, translating a shared callee again for each caller emits it five times (and the C++ fails with `C2084`), and naming the wrong callee at a call fails `chain3`. On Windows 11 build 26200 with MSVC 19.50 and ML64, all 3,815 calls matched and every control was rejected. The C++ generated for the existing jump-table, `addr32`, entry-order, narrow, fourth-argument and frame fixtures is unchanged. Run `ctest --preset dev --no-tests=error -R '^cpu_aot_direct_calls$' -V`. +`cpu_aot_direct_calls` builds [`calls.asm`](../tests/cpu/calls.asm) and translates seven exports, which reach three unexported callees placed below them. `call_leaf` calls a leaf from a frame and keeps the trace pointer in RBX across the call. `chain3` calls `mid_step`, which spills RDX into its own frame above the callee's home space, calls the same leaf and reloads it, so the leaf is shared. `narrow_call` calls a callee that defines only AL and widens it with `MOVZX`. `narrow_tail` tail-jumps to that callee and reports width 1, `tail_call` tail-jumps to the leaf, and `tail_after_frame` pops its frame before tail-jumping to `mid_step`. `home_save_call` has the MSVC `/O2` save shapes around a call: RBX saved by `MOV` into its own home space before `SUB RSP, 28h`, and RSI saved by `MOV` into the allocation above the callee's home space. Through the register probe, the original must match a Python reference, and the translation must match the original on the defined return bytes, the guarded trace, RBX and RSI over 545 input pairs per export. The test checks that each callee is defined exactly once and that the reported return widths are 8 except for `narrow_tail`. A copy with a call to the caller's own entry and one with a call from `mid_step` back to `chain3` must translate with a declared call cycle. Nineteen copies must be rejected with their stated reason: a call from `mid_step` back to `tail_after_frame`, which closes a cycle with that function's tail jump, calls into an instruction interior and to an instruction boundary that is not an entry, a target outside the image and one in `.rdata`, reads of RCX, R8 and the full RAX after a call, a second call to the leaf whose RCX and RDX the first call left undefined, a `SETE` after a call, a stack-argument read in a callee and an unsupported instruction two levels down, a spill and a `MOV` save of RSI moved into the callee's home space and reloaded after the call, a call at entry RSP - 0x30 and one at entry RSP - 0x8, a tail jump with a frame still allocated, a tail jump with RBX not restored, and, as built, `below_call`, which stores a slot at entry RSP - 0x40, raises RSP for a call whose return address overwrites it, and reloads it after RSP falls back (natively it returns the return address). Removing the volatile clobber accepts the RCX control, keeping RAX fully defined after a call accepts the narrow control, keeping the callee's home space defined accepts the spill control, dropping the callees' argument demands accepts the second-call control, translating a shared callee again for each caller emits it five times (and the C++ fails with `C2084`), and naming the wrong callee at a call fails `chain3`. On Windows 11 build 26200 with MSVC 19.50 and ML64, all 3,815 calls matched and every control was rejected. The C++ generated for the existing jump-table, `addr32`, entry-order, narrow, fourth-argument and frame fixtures is unchanged. Run `ctest --preset dev --no-tests=error -R '^cpu_aot_direct_calls$' -V`. + +A `CALL` may close a call cycle ([#317](https://github.com/R0Y00/Xbox2Windows/issues/317), the fixed-point `return_width` proposed there). An export's call to its own entry translates that entry a second time as an internal function. A call into a function whose translation is in progress uses an assumed summary, at first 8 defined RAX bytes and no argument demands. When a function of the cycle is done, its computed return width and demands are compared with the assumed ones: if the computed width is lower or a demand is higher, the cycle is translated again from the lower width and the higher demands. Both move one way through a finite set, so this ends. When no computed width is lower and no demand is higher, every return of the cycle defines the assumed bytes and the cycle reads no more argument bytes, by induction on the depth of the calls that have returned. The functions of a cycle are kept together once its first function is done, after a declaration of each, so each may call any other. A cycle inside another is kept when its own first function is done. A function that goes on hold passes its dependence on to the functions held during its translation, so a later function that reuses one of them joins the same cycle. A refusal under an assumed summary stands, because a lower width or a higher demand cannot remove it. A tail jump that closes a cycle is refused with `tail jump within a call cycle`: the original runs such a cycle in constant stack and the C++ call does not. The translation's recursion depth is bounded by the host stack, whose use per call differs from the original's, so a recursion that ends on the console can overflow the host stack, or the reverse. + +`cpu_aot_recursion` builds [`recursion.asm`](../tests/cpu/recursion.asm) and translates four exports. `sum_export` calls `sum_down`, which recurses through `CALL` up to 511 levels and keeps its arguments in RBX and RSI across the call. `parity_export` calls `is_even` and `is_odd`, which call each other. `is_even` defines only AL at its base case and `is_odd` all of RAX, so only the second translation of the cycle gives `is_odd` its 1-byte width. `walk_export` calls `walk_a`, which is in a cycle with `walk_b` and `walk_c`. Only `walk_a` reads R8, so only the second translation makes `walk_c` demand it; `walk_b` also calls `count_down`, whose own cycle is kept while the outer cycle is still being translated. `fold_export` calls its own exported entry up to 64 levels. Through the register probe, the original must match a Python reference, and the translation must match the original on the return value, the guarded trace, RBX and RSI over 484 input pairs per export. The test checks that each of the eight internal functions is declared once and defined once, that `is_even` and `is_odd` return 1 byte and the others 8, and that exactly `walk_a`, `walk_b`, `walk_c` and the internal `fold_export` demand R8. Five exports must be refused as written: `tail_ping` and `tail_pong`, a cycle of tail jumps; `wide_odd`, which reads all of RAX after `is_odd`; `lost_k`, which calls `walk_c` after another call left R8 undefined; `bad_a`, in a cycle with `bad_b`, which executes `CPUID`; and `stale_e`, whose callee `stale_a` reads all of RAX after `stale_t`. `stale_t` is translated after `stale_s` and `stale_q` are on hold and reuses `stale_q`, so it is in their cycle and returns only AL; a translator that keeps `stale_t` on its own, with the 8 bytes first assumed for the cycle, accepts `stale_e`. Keeping the first summary of each cycle instead of translating it again (the test replaces `at_least_as_good`) accepts `wide_odd` and `lost_k`, and the test fails unless it does. Before this change all four exports were refused, with `self-recursion` or `mutual recursion: call cycle`. Measured on Linux x86-64 with `llvm-ml` 18, `lld-link` and `clang++` at `-O0` and `-O2`, with the original image mapped in-process and called through a Windows x64 register probe: the original matched the reference and kept RBX and RSI, and 3,872 translated calls matched it. The C++ generated for 15 other `cpu_switch_aot` fixtures and for the `calls`, `chains` and `rsp` fuzz programs at their default seeds, `calls` at `0xBEEF` and `chains` at `0xCCD1` with 128 functions, is unchanged. Run `ctest --preset dev --no-tests=error -R '^cpu_aot_recursion$' -V`. `cpu_aot_call_entries` builds [`call_entries.asm`](../tests/cpu/call_entries.asm), whose `.pdata` and `.xdata` are written explicitly so the image has a primary function continued by a chained secondary range. It also exports an interior label of a primary function, a `.data` variable as `DATA` and a forwarder to `kernel32.GetTickCount`. The test reads the image's own records and checks that the translator's entries are exactly the four primary runtime functions. A framed `CALL` and a tail `JMP` to the primary leaf translate and match the original and a Python reference over 249 input pairs each. Eight retargeted copies must be rejected with the reason that names the distinction: the call retargeted to the exported interior label, the chained range's start, the data export and the forwarder; the tail jump retargeted to the interior label and the chained start; and the leaf's unwind header patched from version 1 to version 3, for both the call and the tail jump. The translator before this rule refused the first six later and for unrelated reasons (`no unique function interval`, `not in an executable section`, `edge outside owned ranges`), and accepted the last two. Removing the version check, or accepting an export at the start of an unverified record, accepts the version controls. Counting interior exports or chained ranges as entries, or classifying forwarders and data exports as code, fails the check of the entry table. Run `ctest --preset dev --no-tests=error -R '^cpu_aot_call_entries$' -V`. diff --git a/tests/cpu/bare_calls_check.py b/tests/cpu/bare_calls_check.py index dd20ac08b8..23421b14d1 100644 --- a/tests/cpu/bare_calls_check.py +++ b/tests/cpu/bare_calls_check.py @@ -196,7 +196,8 @@ def apply(manifest, rvas): "call in a function without unwind data"), ("call_bare", [("bare_mix", 0x00, "48 6b c9 05", "53 5b 90 90")], None, "stack change in a function without unwind data"), - ("call_bare", [("bare_mix", 0x00, "48 6b c9 05 48 8b c1", ("call", "bare_mix"))], None, "self-recursion"), + ("call_bare", [("bare_mix", 0x00, "48 6b c9 05 48 8b c1", ("call", "bare_mix"))], None, + "call in a function without unwind data"), ] diff --git a/tests/cpu/calls_check.py b/tests/cpu/calls_check.py index 444e250d90..06dd4fbbe5 100644 --- a/tests/cpu/calls_check.py +++ b/tests/cpu/calls_check.py @@ -9,6 +9,7 @@ import ctypes from pathlib import Path import random +import re import struct import sys @@ -173,9 +174,12 @@ def check(probe_path, original_path, lifted_path): # the callees' RVAs as {leaf}, {mid} and {low}. CALL = "e8 ?? ?? ?? ??" CONTROLS = [ - ("call_leaf", [("call_leaf", 0x08, CALL, ("call", "call_leaf"))], "self-recursion"), - ("chain3", [("mid", 0x0c, CALL, ("call", "chain3"))], - "callee at RVA {mid:#x} refused: mutual recursion: call cycle"), + # Recursion through CALL is translated (tests/cpu/recursion_check.py); a cycle that a tail jump + # closes is not. A reason of None means the patched copy must translate. + ("call_leaf", [("call_leaf", 0x08, CALL, ("call", "call_leaf"))], None), + ("chain3", [("mid", 0x0c, CALL, ("call", "chain3"))], None), + ("tail_after_frame", [("mid", 0x0c, CALL, ("call", "tail_after_frame"))], + "callee at RVA {mid:#x} refused: callee at RVA {tail_after_frame:#x} refused: tail jump within a call cycle"), ("call_leaf", [("call_leaf", 0x08, CALL, ("call", ("leaf", 1)))], "is not a function entry"), ("call_leaf", [("call_leaf", 0x08, CALL, ("call", ("leaf", 4)))], "is not a function entry"), ("call_leaf", [("call_leaf", 0x08, CALL, ("call", ("rva", "end")))], "call target outside the image"), @@ -236,7 +240,7 @@ def resolve(target): with TemporaryDirectory() as folder: path = Path(folder) / "control.dll" for name, patches, reason in CONTROLS: - reason = reason.format(**rvas) + reason = None if reason is None else reason.format(**rvas) damaged = bytearray(data) sites = [] for function, delta, before, after in patches: @@ -263,6 +267,12 @@ def resolve(target): raise AssertionError(f"unexpected encoding for control {reason!r} in {function}") damaged[at:at + len(after)] = after path.write_bytes(damaged) + if reason is None: + source, _ = aot.translate(path, [name]) + if not re.search(r"^static word fn_[0-9a-f]+\(word rcx, word rdx, word r8, word r9\);$", source, re.M): + raise AssertionError(f"{name} control ({', '.join(sites)}) has no declared call cycle") + print(f"control {name} ({', '.join(sites)}): translated with a declared call cycle") + continue try: aot.translate(path, [name]) except ValueError as error: diff --git a/tests/cpu/recursion.asm b/tests/cpu/recursion.asm new file mode 100644 index 0000000000..7ad54dfb49 --- /dev/null +++ b/tests/cpu/recursion.asm @@ -0,0 +1,401 @@ +; Source-owned differential fixture for recursion through direct calls in the jump-table translator. +; Each export is fn(x, y, trace) with x in RCX, y in RDX and a three-word trace in R8, and returns +; RAX. The recursive functions are not exported: each has its own runtime-function entry. The +; register probe seeds RBX and RSI, so a save or restore that the translation loses shows up as a +; changed sentinel. The exports from tail_ping on exist only to be refused. +.code + +; sum_down(n, k): the sum of i XOR k for i = n down to 1, by self-recursion through CALL. RBX and +; RSI keep n and k across the call. +sum_down PROC FRAME + push rbx + .pushreg rbx + push rsi + .pushreg rsi + sub rsp, 28h + .allocstack 28h + .endprolog + xor eax, eax + test rcx, rcx + jz sum_down_done + mov rbx, rcx + mov rsi, rdx + lea rcx, [rbx-1] + call sum_down + mov rcx, rbx + xor rcx, rsi + add rax, rcx +sum_down_done: + add rsp, 28h + pop rsi + pop rbx + ret +sum_down ENDP + +; is_even(n): AL = 1 when n is even, through is_odd. Only AL is defined at the base case. +is_even PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + test rcx, rcx + jnz is_even_step + mov al, 1 + add rsp, 28h + ret +is_even_step: + dec rcx + call is_odd + add rsp, 28h + ret +is_even ENDP + +; is_odd(n): AL = 1 when n is odd, through is_even. Its base case defines all of RAX, so only +; the cycle limits its return to AL. +is_odd PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + test rcx, rcx + jnz is_odd_step + xor eax, eax + add rsp, 28h + ret +is_odd_step: + dec rcx + call is_even + add rsp, 28h + ret +is_odd ENDP + +; count_down(n): the sum of i AND 3 for i = n down to 1. Its own cycle, reached only from walk_b. +count_down PROC FRAME + push rbx + .pushreg rbx + sub rsp, 20h + .allocstack 20h + .endprolog + xor eax, eax + test rcx, rcx + jz count_down_done + mov rbx, rcx + dec rcx + call count_down + and ebx, 3 + add rax, rbx +count_down_done: + add rsp, 20h + pop rbx + ret +count_down ENDP + +; walk_a(n, v, k): v XOR k when n = 0, otherwise walk_b(n - 1, v + n, k) + 1. The only read of k +; (R8) in the cycle walk_a -> walk_b -> walk_c -> walk_a is here. +walk_a PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + test rcx, rcx + jnz walk_a_step + mov rax, rdx + xor rax, r8 + add rsp, 28h + ret +walk_a_step: + add rdx, rcx + dec rcx + call walk_b + inc rax + add rsp, 28h + ret +walk_a ENDP + +; walk_b(n, v, k): v when n = 0, otherwise walk_c(n - 1, 3 * v, k) XOR count_down(n). +walk_b PROC FRAME + push rbx + .pushreg rbx + push rsi + .pushreg rsi + sub rsp, 28h + .allocstack 28h + .endprolog + mov rax, rdx + test rcx, rcx + jz walk_b_done + mov rbx, rcx + lea rdx, [rdx+rdx*2] + dec rcx + call walk_c + mov rsi, rax + mov rcx, rbx + call count_down + xor rax, rsi +walk_b_done: + add rsp, 28h + pop rsi + pop rbx + ret +walk_b ENDP + +; walk_c(n, v, k): v when n = 0, otherwise walk_a(n - 1, v + 5, k). It passes k on without +; reading it, so only the cycle makes it demand R8. +walk_c PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + mov rax, rdx + test rcx, rcx + jz walk_c_done + dec rcx + add rdx, 5 + call walk_a +walk_c_done: + add rsp, 28h + ret +walk_c ENDP + +; trace[0] = sum_down(x AND 1FFh, y); returns it plus x. +sum_export PROC FRAME + push rbx + .pushreg rbx + push rsi + .pushreg rsi + sub rsp, 28h + .allocstack 28h + .endprolog + mov rbx, r8 + mov rsi, rcx + and ecx, 1FFh + call sum_down + mov qword ptr [rbx], rax + add rax, rsi + add rsp, 28h + pop rsi + pop rbx + ret +sum_export ENDP + +; trace[1] = is_even(x AND 0FFh), trace[2] = is_odd(y AND 0FFh); returns their sum. Both +; results are AL only, which MOVZX widens. +parity_export PROC FRAME + push rbx + .pushreg rbx + push rsi + .pushreg rsi + sub rsp, 28h + .allocstack 28h + .endprolog + mov rbx, r8 + mov rsi, rdx + movzx ecx, cl + call is_even + movzx eax, al + mov qword ptr [rbx+8], rax + movzx ecx, sil + call is_odd + movzx eax, al + mov qword ptr [rbx+10h], rax + add rax, qword ptr [rbx+8] + add rsp, 28h + pop rsi + pop rbx + ret +parity_export ENDP + +; trace[2] = walk_a(x AND 3Fh, y, x XOR y). +walk_export PROC FRAME + push rbx + .pushreg rbx + sub rsp, 20h + .allocstack 20h + .endprolog + mov rbx, r8 + mov r8, rcx + xor r8, rdx + and ecx, 3Fh + call walk_a + mov qword ptr [rbx+10h], rax + add rsp, 20h + pop rbx + ret +walk_export ENDP + +; fold_export(x, y, trace): y when x = 0, with trace[2] = y; otherwise fold_export(x SHR 1, +; 2 * y + (x AND 1), trace) + (x AND 1). It calls its own exported entry. +fold_export PROC FRAME + push rbx + .pushreg rbx + sub rsp, 20h + .allocstack 20h + .endprolog + test rcx, rcx + jnz fold_step + mov qword ptr [r8+10h], rdx + mov rax, rdx + jmp fold_done +fold_step: + mov ebx, ecx + and ebx, 1 + lea rdx, [rbx+rdx*2] + shr rcx, 1 + call fold_export + add rax, rbx +fold_done: + add rsp, 20h + pop rbx + ret +fold_export ENDP + +; Refused: tail_ping and tail_pong form a cycle of tail jumps, which the original runs in +; constant stack. +tail_ping PROC FRAME + .endprolog + test rcx, rcx + jz tail_ping_done + dec rcx + jmp tail_pong +tail_ping_done: + mov rax, rdx + ret +tail_ping ENDP + +tail_pong PROC FRAME + .endprolog + add rdx, 3 + jmp tail_ping +tail_pong ENDP + +; Refused: after is_even, is_odd returns only AL, so the full read of RAX is undefined. +wide_odd PROC FRAME + push rbx + .pushreg rbx + sub rsp, 20h + .allocstack 20h + .endprolog + mov rbx, rcx + call is_even + mov rcx, rbx + call is_odd + add rax, rbx + add rsp, 20h + pop rbx + ret +wide_odd ENDP + +; Refused: after walk_a, walk_c is called with R8 undefined, and the cycle reads it. +lost_k PROC FRAME + push rbx + .pushreg rbx + sub rsp, 20h + .allocstack 20h + .endprolog + mov rbx, rcx + call walk_a + mov rcx, rbx + mov rdx, rax + call walk_c + add rsp, 20h + pop rbx + ret +lost_k ENDP + +; Refused: bad_b, in a cycle with bad_a, executes CPUID, which the translator does not lower. +bad_a PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + xor eax, eax + test rcx, rcx + jz bad_a_done + dec rcx + call bad_b +bad_a_done: + add rsp, 28h + ret +bad_a ENDP + +bad_b PROC FRAME + push rbx + .pushreg rbx + sub rsp, 20h + .allocstack 20h + .endprolog + mov rbx, rcx + xor eax, eax + cpuid + mov rcx, rbx + call bad_a + add rsp, 20h + pop rbx + ret +bad_b ENDP + + +; Refused: stale_a reads all of RAX after stale_t, which returns only AL through the cycle +; stale_a -> stale_s -> stale_q -> stale_s -> stale_a. stale_t is translated after stale_s and +; stale_q are pending and reuses stale_q, so it is in the same cycle and must not be kept on its own. +stale_a PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + test rcx, rcx + jnz stale_a_step + mov al, 1 + add rsp, 28h + ret +stale_a_step: + dec rcx + jz stale_a_t + call stale_s + add rsp, 28h + ret +stale_a_t: + call stale_t + inc rax + add rsp, 28h + ret +stale_a ENDP + +stale_s PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + test rcx, rcx + jz stale_s_a + call stale_q + add rsp, 28h + ret +stale_s_a: + call stale_a + add rsp, 28h + ret +stale_s ENDP + +stale_q PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + dec rcx + call stale_s + add rsp, 28h + ret +stale_q ENDP + +stale_t PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + call stale_q + add rsp, 28h + ret +stale_t ENDP + +stale_e PROC FRAME + sub rsp, 28h + .allocstack 28h + .endprolog + call stale_a + add rsp, 28h + ret +stale_e ENDP + +END diff --git a/tests/cpu/recursion.def b/tests/cpu/recursion.def new file mode 100644 index 0000000000..70833bb20a --- /dev/null +++ b/tests/cpu/recursion.def @@ -0,0 +1,10 @@ +EXPORTS + sum_export + parity_export + walk_export + fold_export + tail_ping + wide_odd + lost_k + bad_a + stale_e diff --git a/tests/cpu/recursion_check.py b/tests/cpu/recursion_check.py new file mode 100644 index 0000000000..35b85251e6 --- /dev/null +++ b/tests/cpu/recursion_check.py @@ -0,0 +1,223 @@ +"""Differential checks for recursion through direct calls in the jump-table translator. + +Each export of tests/cpu/recursion.asm runs through the register probe. The source-built original +must match the Python reference, and the translation must match the original on the return value, +the guarded trace and the probe's RBX and RSI sentinels. The structure check reads the summaries +that the call cycles settle on. The refused exports must be refused with their stated reason, and +two of them must be accepted when the translator keeps the first summary of a cycle instead of +iterating, so the iteration is what refuses them. +""" + +import ctypes +from pathlib import Path +import random +import sys + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from direct_check import GUARDS, MASK, SENTINELS, observe, register_probe + +EXPORTS = ("sum_export", "parity_export", "walk_export", "fold_export") +# (export, expected refusal), translated alone. +REFUSED = ( + ("tail_ping", "callee at RVA {tail_pong:#x} refused: callee at RVA {tail_ping:#x} refused: " + "tail jump within a call cycle"), + ("wide_odd", "undefined register rax"), + ("lost_k", "callee argument r8 is undefined"), + ("bad_a", "callee at RVA {bad_b:#x} refused: unsupported instruction"), + ("stale_e", "callee at RVA {stale_a:#x} refused: undefined register rax"), +) +# Refused only because a cycle's first summary is translated again. +ITERATED = ("wide_odd", "lost_k") + + +def trace(first=MASK, second=MASK, third=MASK): + return (GUARDS[0], first & MASK, second & MASK, third & MASK, GUARDS[1]) + + +def sum_down(n, k): + return sum(i ^ k for i in range(1, n + 1)) & MASK + + +def count_down(n): + return sum(i & 3 for i in range(1, n + 1)) + + +def walk_a(n, v, k): + return v ^ k if n == 0 else (walk_b(n - 1, (v + n) & MASK, k) + 1) & MASK + + +def walk_b(n, v, k): + return v if n == 0 else walk_c(n - 1, 3 * v & MASK, k) ^ count_down(n) + + +def walk_c(n, v, k): + return v if n == 0 else walk_a(n - 1, (v + 5) & MASK, k) + + +def sum_export(x, y): + value = sum_down(x & 0x1ff, y) + return (value + x) & MASK, trace(value) + + +def parity_export(x, y): + even, odd = int((x & 0xff) % 2 == 0), int((y & 0xff) % 2 == 1) + return even + odd, trace(second=even, third=odd) + + +def walk_export(x, y): + value = walk_a(x & 0x3f, y, x ^ y) + return value, trace(third=value) + + +def fold(x, y): + if x == 0: + return y, y + value, base = fold(x >> 1, (2 * y + (x & 1)) & MASK) + return (value + (x & 1)) & MASK, base + + +def fold_export(x, y): + value, base = fold(x, y) + return value, trace(third=base) + + +REFERENCES = {name: globals()[name] for name in EXPORTS} + + +def inputs(): + """Boundary words for both arguments, plus seeded random pairs.""" + edges = (0, 1, 2, 3, 0x3f, 0x40, 0xff, 0x100, 0x1ff, 0x200, 0x7fffffff, 0x80000000, 0xffffffff, + 0x100000000, 0x8000000000000000, MASK - 1, MASK, 0x0123456789abcdef) + rng = random.Random(1221) + pairs = [(x, y) for x in edges for y in edges] + pairs += [(rng.getrandbits(64), rng.getrandbits(64)) for _ in range(160)] + return pairs + + +def run(probe, library, prefix=""): + observed = {} + for name in EXPORTS: + function = ctypes.cast(getattr(library, prefix + name), ctypes.c_void_p).value + observed[name] = [observe(probe, function, x, y) for x, y in inputs()] + return observed + + +def verify_reference(observed, label): + for name in EXPORTS: + for (x, y), (returned, words, registers) in zip(inputs(), observed[name]): + want = REFERENCES[name](x, y) + if (returned, words) != want or registers != SENTINELS: + raise AssertionError(f"{label} {name}({x:#x}, {y:#x}): {returned:#x} {words} {registers} " + f"!= {want[0]:#x} {want[1]} {SENTINELS}") + + +def tools(): + sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "tools")) + import pefile + from cpu_leaf_aot import export_rva + import cpu_switch_aot + return pefile, export_rva, cpu_switch_aot + + +def layout(pe, export_rva, aot): + """RVAs of the exports and of the functions their direct calls and tail jumps reach.""" + from iced_x86 import Decoder, FlowControl + ends = dict(aot.runtime_functions(pe)) + rvas = {name: export_rva(pe, name) for name in EXPORTS + tuple(name for name, _ in REFUSED)} + + def targets(rva): + found = [] + for ins in Decoder(64, pe.get_data(rva, ends[rva] - rva), ip=rva): + if ins.flow_control == FlowControl.CALL or (ins.flow_control == FlowControl.UNCONDITIONAL_BRANCH + and ins.near_branch_target in ends): + found.append(ins.near_branch_target) + return found + + rvas["sum_down"], = targets(rvas["sum_export"]) + rvas["is_even"], rvas["is_odd"] = targets(rvas["parity_export"]) + rvas["walk_a"], = targets(rvas["walk_export"]) + rvas["walk_b"], = targets(rvas["walk_a"]) + rvas["walk_c"], rvas["count_down"] = targets(rvas["walk_b"]) + rvas["tail_pong"], = targets(rvas["tail_ping"]) + rvas["bad_b"], = targets(rvas["bad_a"]) + rvas["stale_a"], = targets(rvas["stale_e"]) + return rvas + + +def check(probe_path, original_path, lifted_path): + probe = register_probe(probe_path) + original = run(probe, ctypes.CDLL(str(original_path))) + verify_reference(original, "source fixture") + translated = run(probe, ctypes.CDLL(str(lifted_path)), "lifted_") + for name in EXPORTS: + for (x, y), want, got in zip(inputs(), original[name], translated[name]): + if got != want: + raise AssertionError(f"translation {name}({x:#x}, {y:#x}): {got} != {want}") + print(f"{len(EXPORTS)} exports x {len(inputs())} inputs: the source fixture matches the reference and the " + "translation matches it on the return value, guarded trace, RBX and RSI") + + +def check_structure(original_path): + pefile, export_rva, aot = tools() + with pefile.PE(str(original_path), fast_load=True) as pe: + pe.parse_data_directories() + rvas = layout(pe, export_rva, aot) + program = aot.Program(pe) + functions = [aot.lift(pe, name, program=program) for name in EXPORTS] + source = "\n".join(program.sources + [text for text, _ in functions]) + internal = ("sum_down", "is_even", "is_odd", "count_down", "walk_a", "walk_b", "walk_c", "fold_export") + declaration = "static word fn_{:x}(word rcx, word rdx, word r8, word r9)" + for name in internal: + text = declaration.format(rvas[name]) + if source.count(text + " {") != 1 or source.count(text + ";") != 1: + raise AssertionError(f"{name} at RVA {rvas[name]:#x} is not declared once and defined once") + if source.count("static word fn_") != 2 * len(internal): + raise AssertionError(f"expected {len(internal)} declared internal functions") + widths = {name: program.callees[rvas[name]].return_width for name in internal} + want = dict.fromkeys(internal, 8) | {"is_even": 1, "is_odd": 1} + if widths != want: + raise AssertionError(f"return widths {widths} != {want}") + r8 = aot.R.R8 + demands = {name: program.callees[rvas[name]].demands.get(r8, 0) for name in internal} + want = dict.fromkeys(internal, 0) | {"walk_a": 8, "walk_b": 8, "walk_c": 8, "fold_export": 8} + if demands != want: + raise AssertionError(f"R8 demands {demands} != {want}") + print(f"{len(internal)} recursive functions declared and defined once; return widths {widths}; R8 demands {demands}") + + +def check_refusals(original_path): + pefile, export_rva, aot = tools() + with pefile.PE(str(original_path), fast_load=True) as pe: + pe.parse_data_directories() + rvas = layout(pe, export_rva, aot) + for name, reason in REFUSED: + reason = reason.format(**rvas) + try: + aot.translate(original_path, [name]) + except ValueError as error: + if reason not in str(error): + raise AssertionError(f"{name} refused for another reason: {error}") from error + else: + raise AssertionError(f"{name} accepted: {reason}") + print(f"control {name}: {reason}") + # The planted fault: keep a cycle's first summary, however it compares with the assumption. + iterate = aot.at_least_as_good + aot.at_least_as_good = lambda computed, assumed: True + try: + for name in ITERATED: + try: + aot.translate(original_path, [name]) + except ValueError as error: + raise AssertionError(f"{name} is refused without the iteration: {error}") from error + print(f"control {name}: accepted when the first summary of a cycle is kept") + finally: + aot.at_least_as_good = iterate + print(f"{len(REFUSED)} recursion rejection controls passed") + + +if __name__ == "__main__": + if len(sys.argv) != 4: + raise SystemExit("usage: recursion_check.py PROBE ORIGINAL LIFTED") + check(*sys.argv[1:]) + check_structure(sys.argv[2]) + check_refusals(sys.argv[2]) diff --git a/tools/cpu_switch_aot.py b/tools/cpu_switch_aot.py index bab83ebe27..f6df36601c 100644 --- a/tools/cpu_switch_aot.py +++ b/tools/cpu_switch_aot.py @@ -128,9 +128,8 @@ defined before its first caller. A target must be the first byte of a verified primary runtime function (unchained, version 1 or 2 unwind data, executable) or a non-forwarded code export that no other function's interval holds; chained -ranges, interior labels, forwarded and data exports are refused. A call -to the caller's own entry and any call cycle are refused, and a caller is -refused when any callee is. A callee records how many low bytes of each argument +ranges, interior labels, forwarded and data exports are refused. A caller +is refused when any callee is. A callee records how many low bytes of each argument register it may read before writing it, and the caller must define them at the call. After a call RAX holds the callee's return width of defined bytes; the other volatile registers, the flags and the callee's 32-byte home space at RSP @@ -144,6 +143,15 @@ width. The callee's frame is its own array, so no frame address crosses a call, and stack arguments stay refused. +A CALL may close a call cycle, an export's own entry included, which becomes an +internal function too. A call into a function whose translation is in progress +uses an assumed return width and demands, at first 8 bytes and none, and the +functions of the cycle are translated again from the meet of the assumed and +computed values until no computed width is lower and no demand higher. Each +function of a cycle is declared before the definitions. A tail jump that closes +a cycle is refused: the original runs such a cycle in constant stack. The host +stack bounds the depth of recursion, at a depth that differs from the original. + A target without unwind data or export is refused, with a message saying that a range binding is needed, unless the invoker supplies one: --bind-ranges names a JSON manifest of trusted [start, end) RVAs from the source labels of this @@ -526,8 +534,6 @@ def owns(self, ip): def callee(self, ins): """Validate the target of a direct CALL as the entry of another function in the image.""" target = ins.near_branch_target - if target == self.entry: - raise ValueError(f"self-recursion at RVA {ins.ip:#x}") if not 0 <= target < self.pe.OPTIONAL_HEADER.SizeOfImage: raise ValueError(f"call target outside the image at RVA {ins.ip:#x}") section = self.pe.get_section_by_rva(target) @@ -1820,9 +1826,30 @@ def demands(self): return dict(zip(ARGUMENT_REGISTERS, self.widths)) +class Assumed(NamedTuple): + """The summary that calls into a function still being translated use: its return width and + argument demands, assumed until its translation computes them.""" + entry: int + return_width: int + demands: dict + + +def at_least_as_good(computed, assumed): + """Whether a computed summary defines at least the assumed RAX bytes and demands no more.""" + return (computed.return_width >= assumed.return_width + and all(width <= assumed.demands.get(r, 0) for r, width in computed.demands.items())) + + class Program: """The functions of one image reached from the requested exports through direct calls and tail - jumps. Each callee is translated once, in internal mode, and its source precedes its callers'.""" + jumps. Each callee is translated once, in internal mode, and its source precedes its callers'. + + A call to an internal function whose translation is in progress closes a call cycle. It uses an + assumed summary, at first 8 defined RAX bytes and no demands. Each function of the cycle is + translated again with the meet of the assumed and computed summaries until each computed + summary defines at least the assumed bytes and demands no more. Its returns then define those + bytes and it reads no more, by induction on the depth of calls that return. The functions of a + cycle are kept once its first function is done, after declarations, so each may call any other.""" def __init__(self, pe, bindings=None, *, image_data=False, imports=None, host_cpu=False): self.pe = pe @@ -1830,7 +1857,11 @@ def __init__(self, pe, bindings=None, *, image_data=False, imports=None, host_cp self.host_cpu = host_cpu self.imports = imports or {} self.entries = Entries(pe, bindings) - self.active = [] + self.active = [] # entry of each translation in progress, outermost first + self.internal = [] # whether each of those is an internal function + self.lows = [] # per active translation: the lowest active depth it has used a summary from + self.assumed = {} + self.pending = [] # (entry, source, function, low) of cycle functions not yet kept self.callees = {} self.refused = {} self.sources = [] @@ -1838,33 +1869,76 @@ def __init__(self, pe, bindings=None, *, image_data=False, imports=None, host_cp def lift(self, entry, symbol, arguments, internal=False): self.active.append(entry) + self.internal.append(internal) + self.lows.append(len(self.active) - 1) try: return lift_function(self, entry, symbol, arguments, internal) finally: self.active.pop() + self.internal.pop() + self.low = self.lows.pop() + if self.lows: + self.lows[-1] = min(self.lows[-1], self.low) + + def depends(self, depth): + self.lows[-1] = min(self.lows[-1], depth) + + def committed(self, callee): + return isinstance(callee, HostImport) or self.callees.get(callee.entry) is callee def callee(self, target, ip): if target in self.refused: raise ValueError(f"callee at RVA {target:#x} refused: {self.refused[target]}") if target in self.callees: return self.callees[target] - if target in self.active: - cycle = self.active[self.active.index(target):] + [target] - raise ValueError(f"mutual recursion: call cycle {' -> '.join(f'{rva:#x}' for rva in cycle)} " - f"at RVA {ip:#x}") - if len(self.callees) >= MAX_CALLEES: + for entry, _, function, low in self.pending: + if entry == target: + self.depends(low) + return function + depth = next((d for d, (entry, internal) in enumerate(zip(self.active, self.internal)) + if internal and entry == target), None) + if depth is not None: + self.depends(depth) + return self.assumed.setdefault(target, Assumed(target, 8, {})) + if len(self.callees) + len(self.pending) >= MAX_CALLEES: raise ValueError(f"callee limit reached at RVA {ip:#x}") - try: - source, function = self.lift(target, f"fn_{target:x}", ARGUMENT_REGISTERS, internal=True) - except ValueError as error: - self.refused[target] = str(error) - raise ValueError(f"callee at RVA {target:#x} refused: {error}") from None - if function.return_width is None: - error = "no reachable normal return" - self.refused[target] = error - raise ValueError(f"callee at RVA {target:#x} refused: {error}") - self.callees[target] = function - self.sources.append(source) + depth = len(self.active) + start = len(self.pending) + while True: + try: + source, function = self.lift(target, f"fn_{target:x}", ARGUMENT_REGISTERS, internal=True) + if function.return_width is None: + raise ValueError("no reachable normal return") + except ValueError as error: + del self.pending[start:] + self.assumed.pop(target, None) + self.refused[target] = str(error) + raise ValueError(f"callee at RVA {target:#x} refused: {error}") from None + assumed = self.assumed.get(target) + if assumed is None or at_least_as_good(function, assumed): + break + # Translate the cycle again from a summary that both bounds. + demands = {r: max(width, function.demands.get(r, 0)) + for r, width in assumed.demands.items()} | { + r: width for r, width in function.demands.items() if r not in assumed.demands} + self.assumed[target] = Assumed(target, min(assumed.return_width, function.return_width), demands) + del self.pending[start:] + if self.low < depth: + # Part of a cycle through a function below it on the stack, which keeps it when that is done. + # The functions pending from its translation now depend on what it depends on: a later + # translation at this depth that reuses one is in the same cycle. + self.pending[start:] = [(e, t, f, min(l, self.low)) for e, t, f, l in self.pending[start:]] + self.pending.append((target, source, function, self.low)) + return function + members = [(entry, text, member) for entry, text, member, _ in self.pending[start:]] + [(target, source, function)] + del self.pending[start:] + cyclic = [self.assumed.pop(entry, None) for entry, _, _ in members] + if any(cyclic) or len(members) > 1: + self.sources.append("\n".join(f"static word fn_{entry:x}({', '.join(f'word {NAMES[r]}' for r in ARGUMENT_REGISTERS)});" + for entry, _, _ in sorted(members, key=lambda m: m[0]))) + for entry, text, member in members: + self.callees[entry] = member + self.sources.append(text) return function @@ -1932,6 +2006,10 @@ def lift_function(program, entry, symbol, arguments, internal): callees = {ip: (function.host_calls[ip] if ip in function.host_calls else program.callee(target, ip)) for ip, target in sorted({**function.calls, **function.tails}.items())} + for ip in sorted(function.tails): + if not program.committed(callees[ip]): + # The original runs a cycle of tail jumps in constant stack; the host call does not. + raise ValueError(f"tail jump within a call cycle at RVA {ip:#x}") loads = {sequence[0]: index for index, _, sequence, _, _, _ in function.dispatches.values()} skipped = {ip for _, _, sequence, _, _, _ in function.dispatches.values() for ip in sequence} body = {}