Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$<TARGET_FILE:cpu_register_probe>"
"$<TARGET_FILE:cpu_calls>" "$<TARGET_FILE:cpu_calls_lifted>")
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" "$<TARGET_FILE:cpu_register_probe>"
"$<TARGET_FILE:cpu_recursion>" "$<TARGET_FILE:cpu_recursion_lifted>")
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
Expand Down
8 changes: 6 additions & 2 deletions docs/experiments.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/cpu/bare_calls_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]


Expand Down
18 changes: 14 additions & 4 deletions tests/cpu/calls_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ctypes
from pathlib import Path
import random
import re
import struct
import sys

Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Loading
Loading