diff options
author | siggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-11 18:01:55 +0000 |
---|---|---|
committer | siggi@chromium.org <siggi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-11 18:01:55 +0000 |
commit | b438c4a50990c32e11e8b9a4d806c8a7bc2b8746 (patch) | |
tree | 593ef9d3b446c624b9e6d2dc5de74d8050087aa1 /chrome_frame/crash_reporting/crash_dll.cc | |
parent | 66eabe1f06ce4bc35eb619aa2f2e4695255137fa (diff) | |
download | chromium_src-b438c4a50990c32e11e8b9a4d806c8a7bc2b8746.zip chromium_src-b438c4a50990c32e11e8b9a4d806c8a7bc2b8746.tar.gz chromium_src-b438c4a50990c32e11e8b9a4d806c8a7bc2b8746.tar.bz2 |
Utility functions to interact with the NT loader's data structures and associated tests.
This is in preparation for squelching false positive crash reports during DLL load.
BUG=31980
TEST=Unittests in this change.
Review URL: http://codereview.chromium.org/882001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41289 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/crash_reporting/crash_dll.cc')
-rw-r--r-- | chrome_frame/crash_reporting/crash_dll.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/chrome_frame/crash_reporting/crash_dll.cc b/chrome_frame/crash_reporting/crash_dll.cc new file mode 100644 index 0000000..97f41c9 --- /dev/null +++ b/chrome_frame/crash_reporting/crash_dll.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// Main entry point for a DLL that can be instructed to crash on +// load or unload by setting an environment variable appropriately. +// +// Note: This code has no CRT to lean on, because some versions of the CRT +// have a bug whereby they leave dangling state after taking an exception +// during DLL_PROCESS_ATTACH. This in turn causes the loading process to +// crash on exit. To work around this, this DLL has its entrypoint set +// to the DllMain routine and does not link with the CRT. +#include <windows.h> +#include "crash_dll.h" + +void Crash() { + char* null_pointer = reinterpret_cast<char*>(kCrashAddress); + + *null_pointer = '\0'; +} + +void CrashConditionally(const wchar_t* name) { + wchar_t value[1024]; + DWORD ret = ::GetEnvironmentVariable(name, value, ARRAYSIZE(value)); + if (ret != 0 || ERROR_ENVVAR_NOT_FOUND != ::GetLastError()) + Crash(); +} + +extern "C" BOOL WINAPI DllMain(HINSTANCE instance, + DWORD reason, + LPVOID reserved) { + if (reason == DLL_PROCESS_ATTACH) { + CrashConditionally(kCrashOnLoadMode); + } else if (reason == DLL_PROCESS_DETACH) { + CrashConditionally(kCrashOnUnloadMode); + } + + return 1; +} |