From fddded8d204374febcba210b8e2e325973f973b2 Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Wed, 16 Jul 2025 17:06:58 +0200 Subject: [PATCH] Add an unreachable on hitting ud2 instead of getting stuck in an infinite loop (#3257) * Add an unreachable on hitting ud2 instead of getting stuck in an infinite loop * Add [[unlikely]] to get ahead of the inevitable PR review comment --- src/core/cpu_patches.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/cpu_patches.cpp b/src/core/cpu_patches.cpp index e4f65cd31..8c0897a48 100644 --- a/src/core/cpu_patches.cpp +++ b/src/core/cpu_patches.cpp @@ -753,6 +753,10 @@ static bool PatchesIllegalInstructionHandler(void* context) { ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT]; const auto status = Common::Decoder::Instance()->decodeInstruction(instruction, operands, code_address); + if (ZYAN_SUCCESS(status) && instruction.mnemonic == ZydisMnemonic::ZYDIS_MNEMONIC_UD2) + [[unlikely]] { + UNREACHABLE_MSG("ud2 at code address {:#x}", (u64)code_address); + } LOG_ERROR(Core, "Failed to patch address {:x} -- mnemonic: {}", (u64)code_address, ZYAN_SUCCESS(status) ? ZydisMnemonicGetString(instruction.mnemonic) : "Failed to decode");