Bug 1460022: Part 12 - Update XPCOM to use revised DLL interceptor interface; r=froydnj

This commit is contained in:
Aaron Klotz 2018-06-27 11:52:18 -06:00
Родитель 75d2812072
Коммит 230d3ee242
2 изменённых файлов: 39 добавлений и 52 удалений

Просмотреть файл

@ -84,16 +84,14 @@ 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
@ -645,17 +643,12 @@ Init()
// 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;

Просмотреть файл

@ -209,13 +209,20 @@ WinIOAutoObservation::Filename(nsAString& aFilename)
/*************************** 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,
@ -448,34 +455,21 @@ InitPoisonIOInterposer()
// 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