[compiler-rt] r353483 - [compiler rt] Win64 GetInstructionSize additional register MOV + stack alignment AND

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 7 15:56:37 PST 2019


Author: rnk
Date: Thu Feb  7 15:56:37 2019
New Revision: 353483

URL: http://llvm.org/viewvc/llvm-project?rev=353483&view=rev
Log:
[compiler rt] Win64 GetInstructionSize additional register MOV + stack alignment AND

Current interception code does not cover all of the required registers
on Windows for a specific flavor of MOV, so this patch adds cases to
identify the following 5-byte instructions on 64-bit Windows:

mov QWORD PTR [rsp + XX], rdx  <- second integer argument
mov QWORD PTR [rsp + XX], r9    <- third integer argument
mov QWORD PTR [rsp + XX], r8    <- fourth integer argument

The instruction for MOV [...] RCX is already covered in the previous
version.

Patch by Matthew McGovern!

Reviewers: rnk

Differential Revision: https://reviews.llvm.org/D57339

Modified:
    compiler-rt/trunk/lib/interception/interception_win.cc
    compiler-rt/trunk/lib/interception/tests/interception_win_test.cc

Modified: compiler-rt/trunk/lib/interception/interception_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/interception_win.cc?rev=353483&r1=353482&r2=353483&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/interception_win.cc (original)
+++ compiler-rt/trunk/lib/interception/interception_win.cc Thu Feb  7 15:56:37 2019
@@ -523,6 +523,7 @@ static size_t GetInstructionSize(uptr ad
     case 0xd18b48:    // 48 8b d1 : mov rdx, rcx
     case 0xdc8b4c:    // 4c 8b dc : mov r11, rsp
     case 0xd18b4c:    // 4c 8b d1 : mov r10, rcx
+    case 0xE0E483:    // 83 E4 E0 : and esp, 0xFFFFFFE0
       return 3;
 
     case 0xec8348:    // 48 83 ec XX : sub rsp, XX
@@ -554,6 +555,9 @@ static size_t GetInstructionSize(uptr ad
     case 0x245c8948:  // 48 89 5c 24 XX : mov QWORD PTR [rsp + XX], rbx
     case 0x24748948:  // 48 89 74 24 XX : mov QWORD PTR [rsp + XX], rsi
     case 0x244C8948:  // 48 89 4C 24 XX : mov QWORD PTR [rsp + XX], rcx
+    case 0x24548948:  // 48 89 54 24 XX : mov QWORD PTR [rsp + XX], rdx
+    case 0x244c894c:  // 4c 89 4c 24 XX : mov QWORD PTR [rsp + XX], r9
+    case 0x2444894c:  // 4c 89 44 24 XX : mov QWORD PTR [rsp + XX], r8
       return 5;
     case 0x24648348:  // 48 83 64 24 XX : and QWORD PTR [rsp + XX], YY
       return 6;

Modified: compiler-rt/trunk/lib/interception/tests/interception_win_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/interception/tests/interception_win_test.cc?rev=353483&r1=353482&r2=353483&view=diff
==============================================================================
--- compiler-rt/trunk/lib/interception/tests/interception_win_test.cc (original)
+++ compiler-rt/trunk/lib/interception/tests/interception_win_test.cc Thu Feb  7 15:56:37 2019
@@ -208,6 +208,24 @@ const u8 kUnpatchableCode6[] = {
     0x90, 0x90, 0x90, 0x90,
 };
 
+const u8 kPatchableCode6[] = {
+    0x48, 0x89, 0x54, 0x24, 0xBB, // mov QWORD PTR [rsp + 0xBB], rdx
+    0x33, 0xC9,                   // xor ecx,ecx
+    0xC3,                         // ret
+};
+
+const u8 kPatchableCode7[] = {
+    0x4c, 0x89, 0x4c, 0x24, 0xBB,  // mov QWORD PTR [rsp + 0xBB], r9
+    0x33, 0xC9,                   // xor ecx,ecx
+    0xC3,                         // ret
+};
+
+const u8 kPatchableCode8[] = {
+    0x4c, 0x89, 0x44, 0x24, 0xBB, // mov QWORD PTR [rsp + 0xBB], r8
+    0x33, 0xC9,                   // xor ecx,ecx
+    0xC3,                         // ret
+};
+
 // A buffer holding the dynamically generated code under test.
 u8* ActiveCode;
 const size_t ActiveCodeLength = 4096;
@@ -507,7 +525,6 @@ TEST(Interception, PatchableFunction) {
 #endif
   EXPECT_TRUE(TestFunctionPatching(kPatchableCode4, override));
   EXPECT_TRUE(TestFunctionPatching(kPatchableCode5, override));
-
 #if SANITIZER_WINDOWS64
   EXPECT_TRUE(TestFunctionPatching(kLoadGlobalCode, override));
 #endif
@@ -572,7 +589,11 @@ TEST(Interception, PatchableFunctionWith
   EXPECT_FALSE(TestFunctionPatching(kPatchableCode2, override, prefix));
   EXPECT_FALSE(TestFunctionPatching(kPatchableCode3, override, prefix));
   EXPECT_FALSE(TestFunctionPatching(kPatchableCode4, override, prefix));
-
+#ifdef _WIN64
+  EXPECT_TRUE(TestFunctionPatching(kPatchableCode6, override, prefix));
+  EXPECT_TRUE(TestFunctionPatching(kPatchableCode7, override, prefix));
+  EXPECT_TRUE(TestFunctionPatching(kPatchableCode8, override, prefix));
+#endif
   EXPECT_FALSE(TestFunctionPatching(kUnpatchableCode1, override, prefix));
   EXPECT_TRUE(TestFunctionPatching(kUnpatchableCode2, override, prefix));
   EXPECT_FALSE(TestFunctionPatching(kUnpatchableCode3, override, prefix));




More information about the llvm-commits mailing list