# HG changeset patch # User Aaron Klotz # Date 1530121938 21600 # Node ID 1cdba0bde1857d2c8611fceaaa5f1d9fc6168ff6 # Parent a0535dab6dbc06b9235638ac03495374646141a1 Bug 1460022: Part 12 - Update XPCOM to use revised DLL interceptor interface; r=froydnj diff --git a/xpcom/base/AvailableMemoryTracker.cpp b/xpcom/base/AvailableMemoryTracker.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 + sVirtualAllocOrig; -void* (WINAPI* sMapViewOfFileOrig)(HANDLE aFileMappingObject, - DWORD aDesiredAccess, DWORD aFileOffsetHigh, - DWORD aFileOffsetLow, SIZE_T aNumBytesToMap); +static WindowsDllInterceptor::FuncHookType + sMapViewOfFileOrig; -HBITMAP(WINAPI* sCreateDIBSectionOrig)(HDC aDC, const BITMAPINFO* aBitmapInfo, - UINT aUsage, VOID** aBits, - HANDLE aSection, DWORD aOffset); +static WindowsDllInterceptor::FuncHookType + 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(VirtualAllocHook), - reinterpret_cast(&sVirtualAllocOrig)); - sKernel32Intercept.AddHook("MapViewOfFile", - reinterpret_cast(MapViewOfFileHook), - reinterpret_cast(&sMapViewOfFileOrig)); + sVirtualAllocOrig.Set(sKernel32Intercept, "VirtualAlloc", &VirtualAllocHook); + sMapViewOfFileOrig.Set(sKernel32Intercept, "MapViewOfFile", &MapViewOfFileHook); sGdi32Intercept.Init("Gdi32.dll"); - sGdi32Intercept.AddHook("CreateDIBSection", - reinterpret_cast(CreateDIBSectionHook), - reinterpret_cast(&sCreateDIBSectionOrig)); + sCreateDIBSectionOrig.Set(sGdi32Intercept, "CreateDIBSection", + &CreateDIBSectionHook); } sInitialized = true; #endif // defined(XP_WIN) && !defined(HAVE_64BIT_BUILD) } } // namespace AvailableMemoryTracker } // namespace mozilla diff --git a/xpcom/build/PoisonIOInterposerWin.cpp b/xpcom/build/PoisonIOInterposerWin.cpp --- 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 + gOriginalNtCreateFile; +static WindowsDllInterceptor::FuncHookType + gOriginalNtReadFile; +static WindowsDllInterceptor::FuncHookType + gOriginalNtReadFileScatter; +static WindowsDllInterceptor::FuncHookType + gOriginalNtWriteFile; +static WindowsDllInterceptor::FuncHookType + gOriginalNtWriteFileGather; +static WindowsDllInterceptor::FuncHookType + gOriginalNtFlushBuffersFile; +static WindowsDllInterceptor::FuncHookType + 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(InterposedNtCreateFile), - reinterpret_cast(&gOriginalNtCreateFile)); - sNtDllInterceptor.AddHook( - "NtReadFile", - reinterpret_cast(InterposedNtReadFile), - reinterpret_cast(&gOriginalNtReadFile)); - sNtDllInterceptor.AddHook( - "NtReadFileScatter", - reinterpret_cast(InterposedNtReadFileScatter), - reinterpret_cast(&gOriginalNtReadFileScatter)); - sNtDllInterceptor.AddHook( - "NtWriteFile", - reinterpret_cast(InterposedNtWriteFile), - reinterpret_cast(&gOriginalNtWriteFile)); - sNtDllInterceptor.AddHook( - "NtWriteFileGather", - reinterpret_cast(InterposedNtWriteFileGather), - reinterpret_cast(&gOriginalNtWriteFileGather)); - sNtDllInterceptor.AddHook( - "NtFlushBuffersFile", - reinterpret_cast(InterposedNtFlushBuffersFile), - reinterpret_cast(&gOriginalNtFlushBuffersFile)); - sNtDllInterceptor.AddHook( - "NtQueryFullAttributesFile", - reinterpret_cast(InterposedNtQueryFullAttributesFile), - reinterpret_cast(&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