[PATCH] D22111: [compiler-rt] Refactor the interception code on windows.

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 15:59:21 PDT 2016


rnk added inline comments.

================
Comment at: lib/interception/interception_win.cc:38
@@ -37,11 +37,3 @@
 
-#if SANITIZER_WINDOWS64
-static void WriteIndirectJumpInstruction(char *jmp_from, uptr *indirect_target) {  // NOLINT
-  // jmp [rip + XXYYZZWW] = FF 25 WW ZZ YY XX, where
-  // XXYYZZWW is an offset from jmp_from.
-  // The displacement is still 32-bit in x64, so indirect_target must be located
-  // within +/- 2GB range.
-  int offset = (int)(indirect_target - (uptr *)jmp_from);
-  jmp_from[0] = '\xFF';
-  jmp_from[1] = '\x25';
-  *(int*)(jmp_from + 2) = offset;
+bool ChangeMemoryProtection(uptr address, uptr size, DWORD* old_protection) {
+  return ::VirtualProtect((void *)address, size,
----------------
static

================
Comment at: lib/interception/interception_win.cc:44
@@ +43,3 @@
+
+bool RestoreMemoryProtection(uptr address, uptr size, DWORD old_protection) {
+  DWORD unused;
----------------
static

================
Comment at: lib/interception/interception_win.cc:51
@@ +50,3 @@
+
+static bool FunctionHasPadding(uptr address, uptr size) {
+  u8* function = (u8*)address;
----------------
Doesn't this scan forwards, and aren't we trying to scan backwards?

================
Comment at: lib/interception/interception_win.cc:355
@@ +354,3 @@
+  // Check if the targetd address can be encoded in the function padding.
+  uptr IndirectAddress = 0;
+#if SANITIZER_WINDOWS64
----------------
These local variables should probably follow google naming conventions, which is the prevailing local style in the sanitizer libraries.


http://reviews.llvm.org/D22111





More information about the llvm-commits mailing list