fix(fex): free host signal state when a guest leaves its handler (#3052)

* fix(fex): free host signal state when a guest leaves its handler

FEX keeps each signal's host context on the host stack and frees it only
on rt_sigreturn. A guest that leaves its handler another way (siglongjmp,
or CoreCLR resuming a catch after a NullReferenceException) left about
2 KB of host stack and one SignalHandlerRefCounter count behind. Some
3500 such exceptions on one thread overran the guard-less 8 MB host
stack, and the CurseForge agent died with "Internal CLR error.
(0x80131506)" and "Stack overflow occurred on the same thread again!"
at the start of its second addon scan.

0009 chains each thread's signal frames with the guest frame range and
alternate stack they used. A signal that arrives in JIT code at the host
level of the newest frame, after the guest stack pointer has left that
frame, drops the left frames and stores its context where the newest
live frame (or the dispatcher entry) left the host stack. rt_sigreturn
pops its frame and any newer ones it skips; thread stop clears the
chain. Signals inside system calls or thunk callbacks are left alone.
This follows the approach suggested in FEX-Emu/FEX#2487.

0008 now restores InSyscallInfo only for signals that interrupted JIT
code, the only case that saves it. Restoring 0 for a signal that
interrupted a system call cleared the mark while the call was still
running; an itimer loop around time() crashed in 15 of 15 runs.

Pocket FIT Elite: siglongjmp out of a SIGSEGV handler died after about
3500 iterations under FEX-2611.1 with and without 0008 and finishes
200000 with 0009; the new probe (350000 escapes on and off the alternate
stack, mixed with returning handlers and nested handlers) finishes under
0009 and crashes before 2000 iterations without it. The 0008 probe
still reports no stale registers.

* test(fex): check every delivery hunk of the 0009 patch

* fix(fex): reset the host stack when a system call ends a block

* fix(fex): thunk calls mark the guest state as spilled

* fix(fex): signal returns apply the handler's register changes

* docs(fex): describe patches 0010 to 0012 and credit the upstream fix

* test(fex): require AVX2 for the ymm probe and keep vdso canaries live
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-23 07:20:33 -05:00
1 parent 6400a9ef09
commit 2478c44948
16 files changed
+1234 -12

No files matched your search

@@ -0,0 +1,117 @@
import platform
import re
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
FEX = Path(__file__).resolve().parents[1] / "fex"
PATCH = FEX / "patches/0009-signal-handler-escape-frees-host-stack.patch"
PROBE = FEX / "probes/signal-handler-escape.c"
DELEGATOR = "Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp"
CONTEXT = "Source/Tools/LinuxEmulation/ArchHelpers/MContext.h"
THREADS = "Source/Tools/LinuxEmulation/LinuxSyscalls/ThreadManager.h"
FIELDS = ["PrevGuestFrame", "GuestFrameEnd", "GuestInterruptedSP", "GuestAltBase", "GuestAltEnd"]
def files():
sections = re.split(r"^diff --git a/(\S+) \S+\n", PATCH.read_text(), flags=re.M)
return {sections[i]: sections[i + 1] for i in range(1, len(sections), 2)}
def hunks(section):
return re.findall(r"^@@ [^@]+ @@ ?(.*)\n((?:[ +\-].*\n?)*)", section, re.M)
def added(body):
return [line[1:].strip() for line in body.splitlines() if line.startswith("+") and not line.startswith("+++")]
def removed(body):
return [line for line in body.splitlines() if line.startswith("-") and not line.startswith("---")]
class SignalHandlerEscapeTest(unittest.TestCase):
def test_only_signal_state_files_change(self):
self.assertEqual(sorted(files()), sorted([CONTEXT, DELEGATOR, THREADS]))
def test_nothing_is_removed(self):
for name, section in files().items():
self.assertEqual(removed(section), [], name)
def test_added_code_has_no_comments(self):
for name, section in files().items():
for line in added(section):
self.assertFalse("//" in line or "/*" in line, f"{name}: {line}")
def test_both_context_backups_record_the_guest_frame(self):
lines = added(files()[CONTEXT])
self.assertEqual(lines, [f"uint64_t {field};" for field in FIELDS] * 2)
def test_each_thread_keeps_its_frame_chain(self):
self.assertEqual([line for line in added(files()[THREADS]) if line], ["uint64_t GuestFrames {};", "uint32_t GuestFrameCount {};"])
def test_delivery_pushes_and_reclaims_only_left_frames_at_the_dispatch_level(self):
found = hunks(files()[DELEGATOR])
delivery = "".join(body for function, body in found if "HandleDispatcherGuestSignal" in function)
lines = added(delivery)
self.assertIn("#ifdef ARCHITECTURE_arm64", lines)
gate = " ".join(lines)
self.assertIn("WasInJIT && Newest && ContextBackup->PrevSP == SignalInfo.GuestFrames", gate)
self.assertIn("Frame->SignalHandlerRefCounter == SignalInfo.GuestFrameCount + 1", gate)
self.assertIn("GuestLeftFrame(Newest, OldGuestSP", gate)
self.assertIn("ContextBackup->PrevSP = HostTop;", lines)
self.assertIn("Frame->SignalHandlerRefCounter -= LeftFrames;", lines)
self.assertIn("SignalInfo.GuestFrames = reinterpret_cast<uint64_t>(ContextBackup);", lines)
self.assertIn("++SignalInfo.GuestFrameCount;", lines)
self.assertLess(lines.index("#endif"), lines.index("ContextBackup->PrevGuestFrame = SignalInfo.GuestFrames;"))
def test_signal_return_pops_its_frame_and_any_newer_ones(self):
found = hunks(files()[DELEGATOR])
restore = "".join(body for function, body in found if "RestoreThreadState" in function)
lines = added(restore)
self.assertIn("if (Entry == OldSP) {", lines)
self.assertIn("SignalInfo.GuestFrames = EntryBackup->PrevGuestFrame;", lines)
self.assertIn("Thread->CurrentFrame->SignalHandlerRefCounter -= Depth - 1;", lines)
self.assertNotIn("TYPE_PAUSE", " ".join(lines))
def test_thread_stop_clears_the_chain(self):
found = hunks(files()[DELEGATOR])
pause = "".join(body for function, body in found if "HandleSignalPause" in function)
self.assertEqual(added(pause), ["ThreadObject->SignalInfo.GuestFrames = 0;", "ThreadObject->SignalInfo.GuestFrameCount = 0;"])
def test_patch_follows_the_syscall_state_patch_on_every_release(self):
names = sorted(path.name for path in (FEX / "patches").glob("*.patch"))
self.assertEqual(names[names.index(PATCH.name) - 1], "0008-signal-return-restores-syscall-state.patch")
self.assertNotIn("Fixed-upstream", PATCH.read_text())
self.assertIn("tools/fex/patches/*.patch", (FEX / "build-in-arch.sh").read_text())
@unittest.skipUnless(platform.machine() == "x86_64", "the probe is x86-64 code")
class SignalHandlerEscapeProbeTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
compiler = shutil.which("cc") or shutil.which("gcc") or shutil.which("clang")
if not compiler:
raise unittest.SkipTest("no C compiler")
cls.tmp = Path(tempfile.mkdtemp(prefix="fex-signal-escape-"))
cls.binary = cls.tmp / "probe"
subprocess.run([compiler, "-O2", "-o", str(cls.binary), str(PROBE)], check=True, capture_output=True, text=True)
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.tmp, ignore_errors=True)
def test_native_kernel_survives_every_escape(self):
result = subprocess.run([str(self.binary), "20000"], capture_output=True, text=True, timeout=120)
self.assertEqual(result.returncode, 0, result.stdout)
counts = dict(part.split("=") for part in result.stdout.split())
for phase in ("onstack", "offstack", "mixed", "returns", "outer"):
self.assertEqual(counts[phase], "20000", phase)
self.assertEqual(counts["nested"], "60000")
self.assertEqual(counts["wrong"], "0")
if __name__ == "__main__":
unittest.main()
@@ -0,0 +1,134 @@
import platform
import re
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
FEX = Path(__file__).resolve().parents[1] / "fex"
PATCH = FEX / "patches/0012-signal-return-applies-guest-registers.patch"
PROBE = FEX / "probes/signal-register-update.c"
HEADER = "Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.h"
FRAMES = "Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp"
X64_ORDER = ["RAX", "RCX", "RDX", "RBX", "RSP", "RBP", "RSI", "RDI", "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15"]
def files():
sections = re.split(r"^diff --git a/(\S+) \S+\n", PATCH.read_text(), flags=re.M)
return {sections[i]: sections[i + 1] for i in range(1, len(sections), 2)}
def added(section):
return [line[1:].strip() for line in section.splitlines() if line.startswith("+") and not line.startswith("+++")]
def removed(section):
return [line[1:].strip() for line in section.splitlines() if line.startswith("-") and not line.startswith("---")]
def helper():
lines = added(files()[FRAMES])
start = next(i for i, line in enumerate(lines) if line.startswith("void SignalDelegator::ResumeWithGuestGPRs("))
end = lines.index("#endif", start)
return lines[start:end + 1]
class SignalRegisterUpdateTest(unittest.TestCase):
def test_only_signal_frame_files_change(self):
self.assertEqual(sorted(files()), sorted([FRAMES, HEADER]))
def test_patch_only_adds_code(self):
for name, section in files().items():
self.assertEqual(removed(section), [], name)
def test_added_code_has_no_comments(self):
for name, section in files().items():
for line in added(section):
self.assertNotIn("//", line, name)
self.assertNotIn("/*", line, name)
def test_helper_is_declared_once(self):
self.assertEqual(sum(line.startswith("void ResumeWithGuestGPRs(") for line in added(files()[HEADER])), 1)
def test_only_changed_registers_are_written_back(self):
body = helper()
self.assertIn("if (((Delivered ^ GuestGPRs[i]) & Mask) == 0) {", body)
self.assertEqual(body[body.index("if (((Delivered ^ GuestGPRs[i]) & Mask) == 0) {") + 1], "continue;")
def test_spilled_registers_go_to_the_frame_and_live_ones_to_host_registers(self):
body = helper()
self.assertIn("const bool InFrame = AllSpilled || (Spilled & (1U << HostReg));", body)
self.assertIn("Frame->State.gregs[i] = GuestGPRs[i];", body)
self.assertIn("ArchHelpers::Context::SetArmReg(ucontext, HostReg, GuestGPRs[i]);", body)
self.assertIn("for (size_t i = 0; i < Count && i < Config.SRAGPRCount; i++) {", body)
def test_signals_outside_jit_code_are_left_alone(self):
body = helper()
guard = body.index("if (!AllSpilled && !(Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT)) {")
self.assertEqual(body[guard + 1], "return;")
self.assertEqual(body[2], "#ifdef ARCHITECTURE_arm64")
def test_every_frame_type_applies_registers_when_rip_is_unchanged(self):
lines = added(files()[FRAMES])
calls = [line for line in lines if line.startswith("ResumeWithGuestGPRs(")]
self.assertEqual(calls, [
"ResumeWithGuestGPRs(Context, Frame, ucontext, GuestGPRs, FEXCore::Core::CPUState::NUM_GPRS, ~0ULL);",
"ResumeWithGuestGPRs(Context, Frame, ucontext, GuestGPRs, 8, 0xFFFF'FFFFULL);",
"ResumeWithGuestGPRs(Context, Frame, ucontext, GuestGPRs, 8, 0xFFFF'FFFFULL);",
])
branches = [lines[i + 1] for i, line in enumerate(lines[:-1]) if line == "} else {" and lines[i + 1].startswith("uint64_t GuestGPRs[")]
self.assertEqual(branches, ["uint64_t GuestGPRs[FEXCore::Core::CPUState::NUM_GPRS];", "uint64_t GuestGPRs[8];", "uint64_t GuestGPRs[8];"])
def test_registers_are_stored_by_guest_register_index(self):
lines = added(files()[FRAMES])
x64 = [m.group(1) for line in lines for m in [re.fullmatch(r"COPY_REG\((\w+)\);", line)] if m]
self.assertEqual(sorted(x64), sorted(X64_ORDER))
self.assertIn("#define COPY_REG(x) GuestGPRs[FEXCore::X86State::REG_##x] = guest_uctx->uc_mcontext.gregs[FEXCore::x86_64::FEX_REG_##x];", lines)
legacy = re.findall(r"GuestGPRs\[FEXCore::X86State::REG_(\w+)\] = guest_uctx->sc\.(\w+);", "\n".join(lines))
self.assertEqual(sorted(legacy), sorted((r, r[1:].lower()) for r in X64_ORDER[:8]))
rt = re.findall(r"GuestGPRs\[FEXCore::X86State::REG_(\w+)\] = guest_uctx->uc\.uc_mcontext\.gregs\[FEXCore::x86::FEX_REG_(\w+)\];", "\n".join(lines))
self.assertEqual(sorted(rt), sorted((r, r) for r in X64_ORDER[:8]))
def test_patch_follows_the_thunk_patch_on_every_release(self):
names = sorted(path.name for path in (FEX / "patches").glob("*.patch"))
self.assertEqual(names[names.index(PATCH.name) - 1], "0011-thunk-calls-mark-spilled-state.patch")
self.assertNotIn("Fixed-upstream", PATCH.read_text())
@unittest.skipUnless(platform.machine() == "x86_64", "the probe is x86 code")
class SignalRegisterUpdateProbeTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.compiler = shutil.which("cc") or shutil.which("gcc") or shutil.which("clang")
if not cls.compiler:
raise unittest.SkipTest("no C compiler")
cls.tmp = Path(tempfile.mkdtemp(prefix="fex-signal-regs-"))
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.tmp, ignore_errors=True)
def build(self, *flags):
binary = self.tmp / ("probe" + "".join(flags))
result = subprocess.run([self.compiler, "-O2", *flags, "-o", str(binary), str(PROBE)], capture_output=True, text=True)
return binary if result.returncode == 0 else None
def check(self, binary, *args):
result = subprocess.run([str(binary), *args], capture_output=True, text=True, timeout=60)
self.assertEqual(result.returncode, 0, result.stdout)
self.assertIn("seen=1", result.stdout)
def test_native_kernel_applies_handler_register_changes(self):
self.check(self.build())
def test_native_kernel_applies_handler_register_changes_in_32_bit_frames(self):
binary = self.build("-m32")
if binary is None:
self.skipTest("no 32-bit toolchain")
self.check(binary)
self.check(binary, "legacy")
if __name__ == "__main__":
unittest.main()
+7 -5
View File
@@ -24,7 +24,7 @@ class SignalReturnSyscallStateTest(unittest.TestCase):
self.assertEqual(files, ["Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp"])
self.assertEqual(len(found), 1)
def test_every_guest_frame_return_restores_the_interrupted_syscall_state(self):
def test_only_returns_to_jit_code_restore_the_saved_syscall_state(self):
_, found = hunks()
function, body = found[0]
self.assertIn("SignalDelegator::RestoreThreadState", function)
@@ -34,10 +34,12 @@ class SignalReturnSyscallStateTest(unittest.TestCase):
self.assertEqual(added, [RESTORE])
self.assertEqual(removed, [])
context = [line[1:].strip() for line in lines]
guest_frame = context.index("if (Context->UContextLocation) {")
self.assertEqual(context[guest_frame + 1], "auto Frame = Thread->CurrentFrame;")
self.assertEqual(context[guest_frame + 2], RESTORE)
self.assertLess(context.index(RESTORE), context.index("if (Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT) {"))
self.assertEqual(context[0], "auto Frame = Thread->CurrentFrame;")
in_jit = context.index("if (Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT) {")
restore = context.index(RESTORE)
self.assertLess(in_jit, restore)
self.assertEqual(context[restore + 1], "}")
self.assertLess(restore, context.index("RestoreFrame_x64(Thread, Context, Frame, ucontext);"))
def test_thread_pause_returns_are_untouched(self):
_, found = hunks()
@@ -0,0 +1,67 @@
import platform
import re
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
FEX = Path(__file__).resolve().parents[1] / "fex"
PATCH = FEX / "patches/0010-syscall-exit-resets-host-stack.patch"
PROBE = FEX / "probes/syscall-host-stack.c"
BRANCH_OPS = "FEXCore/Source/Interface/Core/JIT/BranchOps.cpp"
def hunks():
text = PATCH.read_text()
files = re.findall(r"^diff --git a/(\S+) ", text, re.M)
return files, re.findall(r"^@@ [^@]+ @@ ?(.*)\n((?:[ +\-].*\n?)*)", text, re.M)
class SyscallHostStackTest(unittest.TestCase):
def test_only_the_branch_ops_change(self):
files, found = hunks()
self.assertEqual(files, [BRANCH_OPS])
self.assertEqual(len(found), 2)
def test_both_ops_that_leave_the_block_reset_the_stack_after_spilling(self):
_, found = hunks()
for (function, body), op in zip(found, ("DEF_OP(Syscall)", "DEF_OP(ThreadRemoveCodeEntry)")):
lines = body.splitlines()
added = [line[1:].strip() for line in lines if line.startswith("+")]
self.assertEqual([line for line in added if line], ["ResetStack();"], op)
self.assertEqual([line for line in lines if line.startswith("-")], [], op)
context = [line[1:].strip() for line in lines]
self.assertIn(op, function + " " + " ".join(context))
self.assertLess(context.index("SpillStaticRegs(TMP1);"), context.index("ResetStack();"), op)
def test_patch_is_skipped_once_upstream_ships_it(self):
self.assertEqual(PATCH.read_text().splitlines()[0], "Fixed-upstream: FEX-2612")
self.assertIn("Fixed-upstream: FEX-", (FEX / "build-in-arch.sh").read_text())
@unittest.skipUnless(platform.machine() == "x86_64", "the probe is x86-64 code")
class SyscallHostStackProbeTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
compiler = shutil.which("cc") or shutil.which("gcc") or shutil.which("clang")
if not compiler:
raise unittest.SkipTest("no C compiler")
cls.tmp = Path(tempfile.mkdtemp(prefix="fex-syscall-stack-"))
cls.binary = cls.tmp / "probe"
subprocess.run([compiler, "-O2", "-o", str(cls.binary), str(PROBE)], check=True, capture_output=True, text=True)
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.tmp, ignore_errors=True)
def test_native_kernel_runs_every_syscall(self):
result = subprocess.run([str(self.binary), "200000"], capture_output=True, text=True, timeout=120)
self.assertEqual(result.returncode, 0, result.stdout)
counts = dict(part.split("=") for part in result.stdout.split())
self.assertIn(counts["mode"], ("avx", "mmx"))
self.assertEqual(counts["syscalls"], "200000")
if __name__ == "__main__":
unittest.main()
+124
View File
@@ -0,0 +1,124 @@
import platform
import re
import shutil
import subprocess
import tempfile
import unittest
from pathlib import Path
FEX = Path(__file__).resolve().parents[1] / "fex"
PATCH = FEX / "patches/0011-thunk-calls-mark-spilled-state.patch"
PROBE = FEX / "probes/vdso-signal-state.c"
CORE = "FEXCore/Source/Interface/Core/Core.cpp"
BRANCH_OPS = "FEXCore/Source/Interface/Core/JIT/BranchOps.cpp"
DELEGATOR = "Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator.cpp"
FRAMES = "Source/Tools/LinuxEmulation/LinuxSyscalls/SignalDelegator/GuestFramesManagement.cpp"
MARK = "str(TMP1, STATE, offsetof(FEXCore::Core::CpuStateFrame, InSyscallInfo));"
CLEAR = "str(ARMEmitter::XReg::zr, STATE, offsetof(FEXCore::Core::CpuStateFrame, InSyscallInfo));"
RESTORE = "Frame->InSyscallInfo = Context->InSyscallInfo;"
def files():
sections = re.split(r"^diff --git a/(\S+) \S+\n", PATCH.read_text(), flags=re.M)
return {sections[i]: sections[i + 1] for i in range(1, len(sections), 2)}
def hunks(section):
return re.findall(r"^@@ [^@]+ @@ ?(.*)\n((?:[ +\-].*\n?)*)", section, re.M)
def added(body):
return [line[1:].strip() for line in body.splitlines() if line.startswith("+") and not line.startswith("+++")]
def removed(body):
return [line[1:].strip() for line in body.splitlines() if line.startswith("-") and not line.startswith("---")]
def context(body):
return [line[1:].strip() for line in body.splitlines() if line[:1] in (" ", "+")]
class ThunkSignalStateTest(unittest.TestCase):
def test_only_signal_state_files_change(self):
self.assertEqual(sorted(files()), sorted([BRANCH_OPS, CORE, DELEGATOR, FRAMES]))
def test_added_code_has_no_new_comments(self):
for name, section in files().items():
moved = set(removed(section))
for line in added(section):
if "//" in line or "/*" in line:
self.assertIn(line, moved, f"{name}: {line}")
def test_thunk_call_marks_all_state_spilled_until_the_refill(self):
section = files()[BRANCH_OPS]
lines = context(section)
self.assertEqual([line for line in added(section) if line], ["LoadConstant(ARMEmitter::Size::i64Bit, TMP1, 0xFFFF);", MARK, CLEAR])
self.assertEqual(removed(section), [])
self.assertLess(lines.index("PushDynamicRegs(TMP1);"), lines.index(MARK))
self.assertLess(lines.index(MARK), lines.index("InsertNamedThunkRelocation(ARMEmitter::Reg::r2, Op->ThunkNameHash);"))
refill = lines.index("FillStaticRegs({")
self.assertEqual(lines[refill + 1:refill + 3], [".NZCV = false,", "});"])
self.assertLess(refill, lines.index(CLEAR))
def test_fully_spilled_state_is_never_respilled_from_host_registers(self):
found = hunks(files()[DELEGATOR])
spill = "".join(body for function, body in found if "SpillSRA" in function or "IgnoreMask" in body)
lines = context(spill)
guard = lines.index("if ((IgnoreMask & 0xFFFF) == 0xFFFF) {")
self.assertIn("RestoreRIPFromHostPC", lines[guard - 2])
self.assertEqual(lines[guard + 1], "return;")
self.assertIn("for (size_t i = 0; i < Config.SRAGPRCount; i++) {", lines[guard + 2:guard + 5])
def test_every_guest_signal_saves_and_clears_the_mark(self):
section = files()[DELEGATOR]
lines = added(section)
self.assertIn("ContextBackup->InSyscallInfo = Frame->InSyscallInfo;", lines)
self.assertIn("Frame->InSyscallInfo = 0;", lines)
self.assertIn(RESTORE, lines)
self.assertIn("if (Context->Flags & ArchHelpers::Context::ContextFlags::CONTEXT_FLAG_INJIT) {", removed(section))
self.assertNotIn("TYPE_PAUSE", " ".join(lines))
def test_redirected_returns_restart_with_no_mark(self):
section = files()[FRAMES]
self.assertEqual(added(section), ["Frame->InSyscallInfo = 0;"] * 3)
self.assertEqual(removed(section), [RESTORE] * 3)
def test_guest_callbacks_run_with_no_mark(self):
lines = added(files()[CORE])
self.assertEqual(lines[1:3], ["const auto InSyscallInfo = Frame->InSyscallInfo;", "Frame->InSyscallInfo = 0;"])
self.assertEqual(lines[-1], "Frame->InSyscallInfo = InSyscallInfo;")
self.assertIn("ExecuteJITCallback(Frame, RIP);", lines[-2])
def test_patch_follows_the_host_stack_patch_on_every_release(self):
names = sorted(path.name for path in (FEX / "patches").glob("*.patch"))
self.assertEqual(names[names.index(PATCH.name) - 1], "0010-syscall-exit-resets-host-stack.patch")
self.assertNotIn("Fixed-upstream", PATCH.read_text())
@unittest.skipUnless(platform.machine() == "x86_64", "the probe is x86-64 code")
class VdsoSignalStateProbeTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
compiler = shutil.which("cc") or shutil.which("gcc") or shutil.which("clang")
if not compiler:
raise unittest.SkipTest("no C compiler")
cls.tmp = Path(tempfile.mkdtemp(prefix="fex-vdso-signal-"))
cls.binary = cls.tmp / "probe"
subprocess.run([compiler, "-O2", "-o", str(cls.binary), str(PROBE)], check=True, capture_output=True, text=True)
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.tmp, ignore_errors=True)
def test_native_kernel_keeps_registers_across_interrupted_clock_calls(self):
result = subprocess.run([str(self.binary), "1"], capture_output=True, text=True, timeout=60)
self.assertEqual(result.returncode, 0, result.stdout)
counts = dict(part.split("=") for part in result.stdout.split())
self.assertGreater(int(counts["calls"]), 0)
self.assertGreater(int(counts["alarms"]), 0)
self.assertEqual(counts["bad"], "0")
if __name__ == "__main__":
unittest.main()