1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Main entry point for a DLL that can be instructed to crash on
6 // load or unload by setting an environment variable appropriately.
8 // Note: This code has no CRT to lean on, because some versions of the CRT
9 // have a bug whereby they leave dangling state after taking an exception
10 // during DLL_PROCESS_ATTACH. This in turn causes the loading process to
11 // crash on exit. To work around this, this DLL has its entrypoint set
12 // to the DllMain routine and does not link with the CRT.
16 #include "crash_dll.h"
19 char* null_pointer = reinterpret_cast<char*>(kCrashAddress);
24 void CrashConditionally(const wchar_t* name) {
26 DWORD ret = ::GetEnvironmentVariable(name, value, ARRAYSIZE(value));
27 if (ret != 0 || ERROR_ENVVAR_NOT_FOUND != ::GetLastError())
31 extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason,
33 if (reason == DLL_PROCESS_ATTACH)
34 CrashConditionally(kCrashOnLoadMode);
35 else if (reason == DLL_PROCESS_DETACH)
36 CrashConditionally(kCrashOnUnloadMode);