gecko/xpcom/build/mozPoisonWriteWin.cpp
Rafael Ávila de Espíndola 4f71ab18da Revert fa1f52704c9e. r=bustage.
--HG--
extra : rebase_source : 0902425782990758102c17fbfb6918b36aba39af
2013-02-13 08:54:32 -05:00

58 lines
1.5 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 ci et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <stdio.h>
#include <windows.h>
#include <winternl.h> // NTSTATUS
#include "nsWindowsDllInterceptor.h"
#include "mozilla/mozPoisonWrite.h"
#include "mozPoisonWriteBase.h"
#include "mozilla/Assertions.h"
namespace mozilla {
static WindowsDllInterceptor sNtDllInterceptor;
void AbortOnBadWrite();
bool ValidWriteAssert(bool ok);
typedef NTSTATUS (WINAPI* FlushBuffersFile_fn)(HANDLE, PIO_STATUS_BLOCK);
FlushBuffersFile_fn gOriginalFlushBuffersFile;
NTSTATUS WINAPI
patched_FlushBuffersFile(HANDLE aFileHandle, PIO_STATUS_BLOCK aIoStatusBlock)
{
AbortOnBadWrite();
return gOriginalFlushBuffersFile(aFileHandle, aIoStatusBlock);
}
void AbortOnBadWrite()
{
if (!PoisonWriteEnabled())
return;
ValidWriteAssert(false);
}
void PoisonWrite() {
// Quick sanity check that we don't poison twice.
static bool WritesArePoisoned = false;
MOZ_ASSERT(!WritesArePoisoned);
if (WritesArePoisoned)
return;
WritesArePoisoned = true;
if (!PoisonWriteEnabled())
return;
PoisonWriteBase();
sNtDllInterceptor.Init("ntdll.dll");
sNtDllInterceptor.AddHook("NtFlushBuffersFile", reinterpret_cast<intptr_t>(patched_FlushBuffersFile), reinterpret_cast<void**>(&gOriginalFlushBuffersFile));
}
}