Bug 1460022: Part 12 - Update XPCOM to use revised DLL interceptor interface; r=froydnj
authorAaron Klotz <aklotz@mozilla.com>
Wed, 27 Jun 2018 11:52:18 -0600
changeset 424942 1cdba0bde1857d2c8611fceaaa5f1d9fc6168ff6
parent 424941 c95140bcd817476c28d70fc2f749ae94b4abc3e6
child 424943 ff25e66da36e4c95363e684880085f99d845da2a
push id104944
push useraklotz@mozilla.com
push dateWed, 04 Jul 2018 02:23:52 +0000
treeherdermozilla-inbound@ff25e66da36e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1460022
milestone63.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 1460022: Part 12 - Update XPCOM to use revised DLL interceptor interface; r=froydnj
xpcom/base/AvailableMemoryTracker.cpp
xpcom/build/PoisonIOInterposerWin.cpp
--- a/xpcom/base/AvailableMemoryTracker.cpp
+++ b/xpcom/base/AvailableMemoryTracker.cpp
@@ -79,26 +79,24 @@ bool sHooksActive = false;
 
 // Alas, we'd like to use mozilla::TimeStamp, but we can't, because it acquires
 // a lock!
 volatile bool sUnderMemoryPressure = false;
 volatile PRIntervalTime sLastLowMemoryNotificationTime;
 
 // These are function pointers to the functions we wrap in Init().
 
-void* (WINAPI* sVirtualAllocOrig)(LPVOID aAddress, SIZE_T aSize,
-                                  DWORD aAllocationType, DWORD aProtect);
+static WindowsDllInterceptor::FuncHookType<decltype(&VirtualAlloc)>
+  sVirtualAllocOrig;
 
-void* (WINAPI* sMapViewOfFileOrig)(HANDLE aFileMappingObject,
-                                   DWORD aDesiredAccess, DWORD aFileOffsetHigh,
-                                   DWORD aFileOffsetLow, SIZE_T aNumBytesToMap);
+static WindowsDllInterceptor::FuncHookType<decltype(&MapViewOfFile)>
+  sMapViewOfFileOrig;
 
-HBITMAP(WINAPI* sCreateDIBSectionOrig)(HDC aDC, const BITMAPINFO* aBitmapInfo,
-                                       UINT aUsage, VOID** aBits,
-                                       HANDLE aSection, DWORD aOffset);
+static WindowsDllInterceptor::FuncHookType<decltype(&CreateDIBSection)>
+  sCreateDIBSectionOrig;
 
 /**
  * Fire a memory pressure event if we were not under memory pressure yet, or
  * fire an ongoing one if it's been long enough since the last one we
  * fired.
  */
 bool
 MaybeScheduleMemoryPressureEvent()
@@ -640,27 +638,22 @@ Init()
 
 #if defined(XP_WIN) && !defined(HAVE_64BIT_BUILD)
   // Don't register the hooks if we're a build instrumented for PGO: If we're
   // an instrumented build, the compiler adds function calls all over the place
   // which may call VirtualAlloc; this makes it hard to prevent
   // VirtualAllocHook from reentering itself.
   if (!PR_GetEnv("MOZ_PGO_INSTRUMENTED")) {
     sKernel32Intercept.Init("Kernel32.dll");
-    sKernel32Intercept.AddHook("VirtualAlloc",
-                               reinterpret_cast<intptr_t>(VirtualAllocHook),
-                               reinterpret_cast<void**>(&sVirtualAllocOrig));
-    sKernel32Intercept.AddHook("MapViewOfFile",
-                               reinterpret_cast<intptr_t>(MapViewOfFileHook),
-                               reinterpret_cast<void**>(&sMapViewOfFileOrig));
+    sVirtualAllocOrig.Set(sKernel32Intercept, "VirtualAlloc", &VirtualAllocHook);
+    sMapViewOfFileOrig.Set(sKernel32Intercept, "MapViewOfFile", &MapViewOfFileHook);
 
     sGdi32Intercept.Init("Gdi32.dll");
-    sGdi32Intercept.AddHook("CreateDIBSection",
-                            reinterpret_cast<intptr_t>(CreateDIBSectionHook),
-                            reinterpret_cast<void**>(&sCreateDIBSectionOrig));
+    sCreateDIBSectionOrig.Set(sGdi32Intercept, "CreateDIBSection",
+                              &CreateDIBSectionHook);
   }
 
   sInitialized = true;
 #endif // defined(XP_WIN) && !defined(HAVE_64BIT_BUILD)
 }
 
 } // namespace AvailableMemoryTracker
 } // namespace mozilla
--- a/xpcom/build/PoisonIOInterposerWin.cpp
+++ b/xpcom/build/PoisonIOInterposerWin.cpp
@@ -204,23 +204,30 @@ WinIOAutoObservation::Filename(nsAString
   mHasQueriedFilename = true;
 
   aFilename = mFilename;
 }
 
 /*************************** IO Interposing Methods ***************************/
 
 // Function pointers to original functions
-static NtCreateFileFn         gOriginalNtCreateFile;
-static NtReadFileFn           gOriginalNtReadFile;
-static NtReadFileScatterFn    gOriginalNtReadFileScatter;
-static NtWriteFileFn          gOriginalNtWriteFile;
-static NtWriteFileGatherFn    gOriginalNtWriteFileGather;
-static NtFlushBuffersFileFn   gOriginalNtFlushBuffersFile;
-static NtQueryFullAttributesFileFn gOriginalNtQueryFullAttributesFile;
+static WindowsDllInterceptor::FuncHookType<NtCreateFileFn>
+  gOriginalNtCreateFile;
+static WindowsDllInterceptor::FuncHookType<NtReadFileFn>
+  gOriginalNtReadFile;
+static WindowsDllInterceptor::FuncHookType<NtReadFileScatterFn>
+  gOriginalNtReadFileScatter;
+static WindowsDllInterceptor::FuncHookType<NtWriteFileFn>
+  gOriginalNtWriteFile;
+static WindowsDllInterceptor::FuncHookType<NtWriteFileGatherFn>
+  gOriginalNtWriteFileGather;
+static WindowsDllInterceptor::FuncHookType<NtFlushBuffersFileFn>
+  gOriginalNtFlushBuffersFile;
+static WindowsDllInterceptor::FuncHookType<NtQueryFullAttributesFileFn>
+  gOriginalNtQueryFullAttributesFile;
 
 static NTSTATUS NTAPI
 InterposedNtCreateFile(PHANDLE aFileHandle,
                        ACCESS_MASK aDesiredAccess,
                        POBJECT_ATTRIBUTES aObjectAttributes,
                        PIO_STATUS_BLOCK aIoStatusBlock,
                        PLARGE_INTEGER aAllocationSize,
                        ULONG aFileAttributes,
@@ -443,44 +450,31 @@ InitPoisonIOInterposer()
   // at any moment, so the instance needs to persist longer than the scope
   // of this functions.
   static DebugFdRegistry registry;
   ReplaceMalloc::InitDebugFd(registry);
 #endif
 
   // Initialize dll interceptor and add hooks
   sNtDllInterceptor.Init("ntdll.dll");
-  sNtDllInterceptor.AddHook(
-    "NtCreateFile",
-    reinterpret_cast<intptr_t>(InterposedNtCreateFile),
-    reinterpret_cast<void**>(&gOriginalNtCreateFile));
-  sNtDllInterceptor.AddHook(
-    "NtReadFile",
-    reinterpret_cast<intptr_t>(InterposedNtReadFile),
-    reinterpret_cast<void**>(&gOriginalNtReadFile));
-  sNtDllInterceptor.AddHook(
-    "NtReadFileScatter",
-    reinterpret_cast<intptr_t>(InterposedNtReadFileScatter),
-    reinterpret_cast<void**>(&gOriginalNtReadFileScatter));
-  sNtDllInterceptor.AddHook(
-    "NtWriteFile",
-    reinterpret_cast<intptr_t>(InterposedNtWriteFile),
-    reinterpret_cast<void**>(&gOriginalNtWriteFile));
-  sNtDllInterceptor.AddHook(
-    "NtWriteFileGather",
-    reinterpret_cast<intptr_t>(InterposedNtWriteFileGather),
-    reinterpret_cast<void**>(&gOriginalNtWriteFileGather));
-  sNtDllInterceptor.AddHook(
-    "NtFlushBuffersFile",
-    reinterpret_cast<intptr_t>(InterposedNtFlushBuffersFile),
-    reinterpret_cast<void**>(&gOriginalNtFlushBuffersFile));
-  sNtDllInterceptor.AddHook(
-    "NtQueryFullAttributesFile",
-    reinterpret_cast<intptr_t>(InterposedNtQueryFullAttributesFile),
-    reinterpret_cast<void**>(&gOriginalNtQueryFullAttributesFile));
+  gOriginalNtCreateFile.Set(sNtDllInterceptor, "NtCreateFile",
+                            &InterposedNtCreateFile);
+  gOriginalNtReadFile.Set(sNtDllInterceptor, "NtReadFile",
+                          &InterposedNtReadFile);
+  gOriginalNtReadFileScatter.Set(sNtDllInterceptor, "NtReadFileScatter",
+                                 &InterposedNtReadFileScatter);
+  gOriginalNtWriteFile.Set(sNtDllInterceptor, "NtWriteFile",
+                           &InterposedNtWriteFile);
+  gOriginalNtWriteFileGather.Set(sNtDllInterceptor, "NtWriteFileGather",
+                                 &InterposedNtWriteFileGather);
+  gOriginalNtFlushBuffersFile.Set(sNtDllInterceptor, "NtFlushBuffersFile",
+                                  &InterposedNtFlushBuffersFile);
+  gOriginalNtQueryFullAttributesFile.Set(sNtDllInterceptor,
+                                         "NtQueryFullAttributesFile",
+                                         &InterposedNtQueryFullAttributesFile);
 }
 
 void
 ClearPoisonIOInterposer()
 {
   MOZ_ASSERT(false);
   if (sIOPoisoned) {
     // Destroy the DLL interceptor