From 4b834fba4167a823990904c63864bb598a32230f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernhard=20=C3=9Cbelacker?= Date: Thu, 20 Mar 2025 18:34:18 +0100 Subject: [PATCH] [win/asan] GetInstructionSize: Detect `66 90` two-byte NOP at 32-bit too. Observed in Wine when trying to intercept `ExitThread`, which forwards to `ntdll.RtlExitUserThread`. `gdb` interprets it as `xchg %ax,%ax`. `llvm-mc` outputs simply `nop`. --- compiler-rt/lib/interception/interception_win.cpp | 2 +- compiler-rt/lib/interception/tests/interception_win_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/interception/interception_win.cpp b/compiler-rt/lib/interception/interception_win.cpp index 002b37468a200..b2974cf1934fb 100644 --- a/compiler-rt/lib/interception/interception_win.cpp +++ b/compiler-rt/lib/interception/interception_win.cpp @@ -646,6 +646,7 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) { case 0xC033: // 33 C0 : xor eax, eax case 0xC933: // 33 C9 : xor ecx, ecx case 0xD233: // 33 D2 : xor edx, edx + case 0x9066: // 66 90 : xchg %ax,%ax (Two-byte NOP) case 0xDB84: // 84 DB : test bl,bl case 0xC084: // 84 C0 : test al,al case 0xC984: // 84 C9 : test cl,cl @@ -726,7 +727,6 @@ static size_t GetInstructionSize(uptr address, size_t* rel_offset = nullptr) { case 0x5541: // push r13 case 0x5641: // push r14 case 0x5741: // push r15 - case 0x9066: // Two-byte NOP case 0xc084: // test al, al case 0x018a: // mov al, byte ptr [rcx] return 2; diff --git a/compiler-rt/lib/interception/tests/interception_win_test.cpp b/compiler-rt/lib/interception/tests/interception_win_test.cpp index 2a7549d230ae2..893f346d73b8a 100644 --- a/compiler-rt/lib/interception/tests/interception_win_test.cpp +++ b/compiler-rt/lib/interception/tests/interception_win_test.cpp @@ -845,6 +845,7 @@ const struct InstructionSizeData { { 2, {0x33, 0xC0}, 0, "33 C0 : xor eax, eax"}, { 2, {0x33, 0xC9}, 0, "33 C9 : xor ecx, ecx"}, { 2, {0x33, 0xD2}, 0, "33 D2 : xor edx, edx"}, + { 2, {0x66, 0x90}, 0, "66 90 : xchg %ax,%ax (Two-byte NOP)"}, { 2, {0x6A, 0x71}, 0, "6A XX : push XX"}, { 2, {0x84, 0xC0}, 0, "84 C0 : test al,al"}, { 2, {0x84, 0xC9}, 0, "84 C9 : test cl,cl"}, @@ -887,7 +888,6 @@ const struct InstructionSizeData { { 2, {0x41, 0x55}, 0, "41 55 : push r13"}, { 2, {0x41, 0x56}, 0, "41 56 : push r14"}, { 2, {0x41, 0x57}, 0, "41 57 : push r15"}, - { 2, {0x66, 0x90}, 0, "66 90 : Two-byte NOP"}, { 2, {0x84, 0xc0}, 0, "84 c0 : test al, al"}, { 2, {0x8a, 0x01}, 0, "8a 01 : mov al, byte ptr [rcx]"}, { 3, {0x0f, 0xb6, 0x01}, 0, "0f b6 01 : movzx eax, BYTE PTR [rcx]"},