Bug 1382251: Part 1 - Add x64 opcodes to nsWindowsDllInterceptor needed for plugin process SSL brokering r=aklotz
☠☠ backed out by 398fb8533bcb ☠ ☠
authorDavid Parks <dparks@mozilla.com>
Wed, 19 Jul 2017 09:12:12 -0700
changeset 454118 d2f531c6a6d8cb4d638799c0bea3b5e13a1a631c
parent 454117 818803bab44d71f2415a138ce4c34dc8e7e8f2d6
child 454119 5f33ad77c5b468c73b29a056780fdae9ea397a57
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1382251
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1382251: Part 1 - Add x64 opcodes to nsWindowsDllInterceptor needed for plugin process SSL brokering r=aklotz Adds "LEA reg, opcode", "mov word ptr [reg+disp8], reg", "and [reg+disp8], imm8" and "MOV r/m8, imm8" to DLLInterceptor.
xpcom/build/nsWindowsDllInterceptor.h
--- a/xpcom/build/nsWindowsDllInterceptor.h
+++ b/xpcom/build/nsWindowsDllInterceptor.h
@@ -1038,16 +1038,41 @@ protected:
             nTrampBytes = jump.GenerateJump(tramp);
             nOrigBytes += 6;
             foundJmp = true;
           } else {
             // not support yet!
             MOZ_ASSERT_UNREACHABLE("Unrecognized opcode sequence");
             return;
           }
+        } else if (origBytes[nOrigBytes] == 0x8d) {
+          // LEA reg, addr
+          if ((origBytes[nOrigBytes + 1] & kMaskMod) == 0x0 &&
+              (origBytes[nOrigBytes + 1] & kMaskRm) == 0x5) {
+            // [rip+disp32]
+            // convert 32bit offset to 64bit direct and convert instruction
+            // to a simple 64-bit mov
+            BYTE reg = (origBytes[nOrigBytes + 1] & kMaskReg) >> kRegFieldShift;
+            intptr_t absAddr =
+              reinterpret_cast<intptr_t>(origBytes + nOrigBytes + 6 +
+                                         *reinterpret_cast<int32_t*>(origBytes + nOrigBytes + 2));
+            nOrigBytes += 6;
+            tramp[nTrampBytes] = 0xb8 + reg;    // mov
+            ++nTrampBytes;
+            intptr_t* trampOperandPtr = reinterpret_cast<intptr_t*>(tramp + nTrampBytes);
+            *trampOperandPtr = absAddr;
+            nTrampBytes += 8;
+          } else {
+            // Above we dealt with RIP-relative instructions.  Any other
+            // operand form can simply be copied.
+            int len = CountModRmSib(origBytes + nOrigBytes + 1);
+            // We handled the kModOperand64 -- ie RIP-relative -- case above
+            MOZ_ASSERT(len > 0);
+            COPY_CODES(len + 1);
+          }
         } else if (origBytes[nOrigBytes] == 0x63 &&
                    (origBytes[nOrigBytes + 1] & kMaskMod) == kModReg) {
           // movsxd r64, r32 (move + sign extend)
           COPY_CODES(2);
         } else {
           // not support yet!
           MOZ_ASSERT_UNREACHABLE("Unrecognized opcode sequence");
           return;
@@ -1072,16 +1097,27 @@ protected:
               // REG=r, R/M=[r + disp8]
               COPY_CODES(3);
             }
           } else {
             // complex MOV, bail
             MOZ_ASSERT_UNREACHABLE("Unrecognized MOV opcode sequence");
             return;
           }
+        } else if (origBytes[nOrigBytes] == 0x44 &&
+                   origBytes[nOrigBytes+1] == 0x89) {
+          // mov word ptr [reg+disp8], reg
+          COPY_CODES(2);
+          int len = CountModRmSib(origBytes + nOrigBytes);
+          if (len < 0) {
+            // no way to support this yet.
+            MOZ_ASSERT_UNREACHABLE("Unrecognized opcode sequence");
+            return;
+          }
+          COPY_CODES(len);
         }
       } else if ((origBytes[nOrigBytes] & 0xf0) == 0x50) {
         // 1-byte push/pop
         COPY_CODES(1);
       } else if (origBytes[nOrigBytes] == 0x65) {
         // GS prefix
         //
         // The entry of GetKeyState on Windows 10 has the following code.
@@ -1217,16 +1253,29 @@ protected:
           nOrigBytes += 6;
         } else if ((origBytes[nOrigBytes + 1] & (kMaskMod|kMaskReg)) == BuildModRmByte(kModReg, 2, 0)) {
           // CALL reg (ff nn)
           COPY_CODES(2);
         } else {
           MOZ_ASSERT_UNREACHABLE("Unrecognized opcode sequence");
           return;
         }
+      } else if (origBytes[nOrigBytes] == 0x83 &&
+                 (origBytes[nOrigBytes + 1] & 0xf8) == 0x60) {
+        // and [r+d], imm8
+        COPY_CODES(5);
+      } else if (origBytes[nOrigBytes] == 0xc6) {
+        // mov [r+d], imm8
+        int len = CountModRmSib(&origBytes[nOrigBytes + 1]);
+        if (len < 0) {
+          // RIP-relative not yet supported
+          MOZ_ASSERT_UNREACHABLE("Unrecognized opcode sequence");
+          return;
+        }
+        COPY_CODES(len + 1);
       } else {
         MOZ_ASSERT_UNREACHABLE("Unrecognized opcode sequence");
         return;
       }
     }
 #else
 #error "Unknown processor type"
 #endif