From 0b05d20c0a4994fe0e340f850f5bb724416fc29e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 12 Feb 2023 13:01:30 -0800 Subject: [PATCH] riscv: Fix poison with compressed instructions. --- Common/RiscVEmitter.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Common/RiscVEmitter.cpp b/Common/RiscVEmitter.cpp index 6f4ad8ac79..b061486f37 100644 --- a/Common/RiscVEmitter.cpp +++ b/Common/RiscVEmitter.cpp @@ -1021,8 +1021,12 @@ void RiscVEmitter::ReserveCodeSpace(u32 bytes) { _assert_msg_((bytes & 3) == 0 || SupportsCompressed(), "Code space should be aligned (no compressed)"); for (u32 i = 0; i < bytes / 4; i++) EBREAK(); - if (bytes & 2) - Write16(0); + if (bytes & 2) { + if (SupportsCompressed()) + C_EBREAK(); + else + Write16(0); + } } const u8 *RiscVEmitter::AlignCode16() { @@ -4285,9 +4289,11 @@ void RiscVCodeBlock::PoisonMemory(int offset) { u32 *ptr = (u32 *)(region + offset + writable); u32 *maxptr = (u32 *)(region + region_size - offset + writable); // This will only write an even multiple of u32, but not much else to do. - // RiscV: 0x00100073 = EBREAK - while (ptr < maxptr) + // RiscV: 0x00100073 = EBREAK, 0x9002 = C.EBREAK + while (ptr + 1 <= maxptr) *ptr++ = 0x00100073; + if (SupportsCompressed() && ptr < maxptr && (intptr_t)maxptr - (intptr_t)ptr >= 2) + *(u16 *)ptr = 0x9002; } };