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
This commit is contained in:
kalaposfos13 2025-07-16 17:06:58 +02:00 committed by GitHub
parent 161aa49f37
commit fddded8d20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -753,6 +753,10 @@ static bool PatchesIllegalInstructionHandler(void* context) {
ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT]; ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT];
const auto status = const auto status =
Common::Decoder::Instance()->decodeInstruction(instruction, operands, code_address); 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, LOG_ERROR(Core, "Failed to patch address {:x} -- mnemonic: {}", (u64)code_address,
ZYAN_SUCCESS(status) ? ZydisMnemonicGetString(instruction.mnemonic) ZYAN_SUCCESS(status) ? ZydisMnemonicGetString(instruction.mnemonic)
: "Failed to decode"); : "Failed to decode");