Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome_frame/crash_reporting/crash_dll.cc

Issue 3076042: Use Environment::SetVar in more places. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: rebased to ToT Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4
5 // Main entry point for a DLL that can be instructed to crash on 5 // Main entry point for a DLL that can be instructed to crash on
6 // load or unload by setting an environment variable appropriately. 6 // load or unload by setting an environment variable appropriately.
7 // 7 //
8 // Note: This code has no CRT to lean on, because some versions of the CRT 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 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 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 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. 12 // to the DllMain routine and does not link with the CRT.
13
13 #include <windows.h> 14 #include <windows.h>
15
14 #include "crash_dll.h" 16 #include "crash_dll.h"
15 17
16 void Crash() { 18 void Crash() {
17 char* null_pointer = reinterpret_cast<char*>(kCrashAddress); 19 char* null_pointer = reinterpret_cast<char*>(kCrashAddress);
18 20
19 *null_pointer = '\0'; 21 *null_pointer = '\0';
20 } 22 }
21 23
22 void CrashConditionally(const wchar_t* name) { 24 void CrashConditionally(const wchar_t* name) {
23 wchar_t value[1024]; 25 wchar_t value[1024];
24 DWORD ret = ::GetEnvironmentVariable(name, value, ARRAYSIZE(value)); 26 DWORD ret = ::GetEnvironmentVariable(name, value, ARRAYSIZE(value));
25 if (ret != 0 || ERROR_ENVVAR_NOT_FOUND != ::GetLastError()) 27 if (ret != 0 || ERROR_ENVVAR_NOT_FOUND != ::GetLastError())
26 Crash(); 28 Crash();
27 } 29 }
28 30
29 extern "C" BOOL WINAPI DllMain(HINSTANCE instance, 31 extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason,
30 DWORD reason,
31 LPVOID reserved) { 32 LPVOID reserved) {
32 if (reason == DLL_PROCESS_ATTACH) { 33 if (reason == DLL_PROCESS_ATTACH)
33 CrashConditionally(kCrashOnLoadMode); 34 CrashConditionally(kCrashOnLoadMode);
34 } else if (reason == DLL_PROCESS_DETACH) { 35 else if (reason == DLL_PROCESS_DETACH)
35 CrashConditionally(kCrashOnUnloadMode); 36 CrashConditionally(kCrashOnUnloadMode);
36 }
37 37
38 return 1; 38 return 1;
39 } 39 }
OLDNEW
« no previous file with comments | « chrome_frame/crash_reporting/crash_dll.h ('k') | chrome_frame/crash_reporting/nt_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698