From 83d8c900830284046bf868bcc6ce89015503cc58 Mon Sep 17 00:00:00 2001 From: Ilya Luchinkin Date: Fri, 26 Jun 2026 22:58:07 -0300 Subject: [PATCH] bdshemu: Fix MOVS/STOS/LODS/SCAS/CMPS silent no-op at MaxInstructionsCount boundary --- bdshemu/bdshemu_x86.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bdshemu/bdshemu_x86.c b/bdshemu/bdshemu_x86.c index c174c12..cb56c80 100644 --- a/bdshemu/bdshemu_x86.c +++ b/bdshemu/bdshemu_x86.c @@ -2640,8 +2640,9 @@ ShemuX86Emulate( case ND_INS_LODS: case ND_INS_STOS: case ND_INS_MOVS: - // Fetch the rCX register, which is the third operand in case of repeated instructions. - while (Context->InstructionsCount < Context->MaxInstructionsCount) + // do/while: outer loop already gated this dispatch on a budget slot, + // so iteration #1 must run even at MaxInstructionsCount == 1. + do { // Get the RCX value. GET_OP(Context, 2, &dst); @@ -2667,12 +2668,13 @@ ShemuX86Emulate( } Context->InstructionsCount++; - } + } while (Context->InstructionsCount < Context->MaxInstructionsCount); break; case ND_INS_SCAS: case ND_INS_CMPS: - while (Context->InstructionsCount < Context->MaxInstructionsCount) + // Same budget contract as MOVS above. + do { // Get the RCX value. GET_OP(Context, 2, &dst); @@ -2717,7 +2719,7 @@ ShemuX86Emulate( } Context->InstructionsCount++; - } + } while (Context->InstructionsCount < Context->MaxInstructionsCount); break; case ND_INS_MUL: