summaryrefslogtreecommitdiffstats
path: root/chrome_frame/crash_reporting
diff options
context:
space:
mode:
Diffstat (limited to 'chrome_frame/crash_reporting')
-rw-r--r--chrome_frame/crash_reporting/crash_dll.cc12
-rw-r--r--chrome_frame/crash_reporting/crash_dll.h14
-rw-r--r--chrome_frame/crash_reporting/nt_loader_unittest.cc19
-rw-r--r--chrome_frame/crash_reporting/vectored_handler_unittest.cc12
4 files changed, 35 insertions, 22 deletions
diff --git a/chrome_frame/crash_reporting/crash_dll.cc b/chrome_frame/crash_reporting/crash_dll.cc
index 97f41c9..0fc1048 100644
--- a/chrome_frame/crash_reporting/crash_dll.cc
+++ b/chrome_frame/crash_reporting/crash_dll.cc
@@ -1,7 +1,7 @@
// 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.
//
@@ -10,7 +10,9 @@
// 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() {
@@ -26,14 +28,12 @@ void CrashConditionally(const wchar_t* name) {
Crash();
}
-extern "C" BOOL WINAPI DllMain(HINSTANCE instance,
- DWORD reason,
+extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason,
LPVOID reserved) {
- if (reason == DLL_PROCESS_ATTACH) {
+ if (reason == DLL_PROCESS_ATTACH)
CrashConditionally(kCrashOnLoadMode);
- } else if (reason == DLL_PROCESS_DETACH) {
+ else if (reason == DLL_PROCESS_DETACH)
CrashConditionally(kCrashOnUnloadMode);
- }
return 1;
}
diff --git a/chrome_frame/crash_reporting/crash_dll.h b/chrome_frame/crash_reporting/crash_dll.h
index ca38e15..f87766f 100644
--- a/chrome_frame/crash_reporting/crash_dll.h
+++ b/chrome_frame/crash_reporting/crash_dll.h
@@ -1,14 +1,16 @@
// 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.
-#ifndef CHROME_FRAME_CRASH_REPORT_CRASH_DLL_H_
-#define CHROME_FRAME_CRASH_REPORT_CRASH_DLL_H_
+
+#ifndef CHROME_FRAME_CRASH_REPORTING_CRASH_DLL_H_
+#define CHROME_FRAME_CRASH_REPORTING_CRASH_DLL_H_
+#pragma once
// Set either of these environment variables to
// crash at load or unload time, respectively.
-static const wchar_t* kCrashDllName = L"crash_dll.dll";
-static const wchar_t* kCrashOnLoadMode = L"CRASH_DLL_CRASH_ON_LOAD";
-static const wchar_t* kCrashOnUnloadMode = L"CRASH_DLL_CRASH_ON_UNLOAD";
+static const wchar_t kCrashDllName[] = L"crash_dll.dll";
+static const wchar_t kCrashOnLoadMode[] = L"CRASH_DLL_CRASH_ON_LOAD";
+static const wchar_t kCrashOnUnloadMode[] = L"CRASH_DLL_CRASH_ON_UNLOAD";
static const DWORD kCrashAddress = 0x42;
-#endif // CHROME_FRAME_CRASH_REPORT_CRASH_DLL_H_
+#endif // CHROME_FRAME_CRASH_REPORTING_CRASH_DLL_H_
diff --git a/chrome_frame/crash_reporting/nt_loader_unittest.cc b/chrome_frame/crash_reporting/nt_loader_unittest.cc
index a73fb9f..2c46eab 100644
--- a/chrome_frame/crash_reporting/nt_loader_unittest.cc
+++ b/chrome_frame/crash_reporting/nt_loader_unittest.cc
@@ -6,11 +6,14 @@
#include <tlhelp32.h>
#include <winnt.h>
#include <base/at_exit.h>
+#include <base/environment.h>
#include <base/message_loop.h>
#include <base/scoped_handle.h>
+#include <base/scoped_ptr.h>
#include <base/string_util.h>
#include <base/sys_info.h>
#include <base/thread.h>
+#include <base/utf_string_conversions.h>
#include "chrome_frame/crash_reporting/crash_dll.h"
#include "gtest/gtest.h"
@@ -191,8 +194,9 @@ class NtLoaderTest: public testing::Test {
EXPECT_TRUE(veh_id_ != NULL);
// Clear the crash DLL environment.
- ::SetEnvironmentVariable(kCrashOnLoadMode, NULL);
- ::SetEnvironmentVariable(kCrashOnUnloadMode, NULL);
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->UnSetVar(WideToASCII(kCrashOnLoadMode).c_str());
+ env->UnSetVar(WideToASCII(kCrashOnUnloadMode).c_str());
}
void TearDown() {
@@ -200,8 +204,9 @@ class NtLoaderTest: public testing::Test {
EXPECT_NE(0, ::RemoveVectoredExceptionHandler(veh_id_));
// Clear the crash DLL environment.
- ::SetEnvironmentVariable(kCrashOnLoadMode, NULL);
- ::SetEnvironmentVariable(kCrashOnUnloadMode, NULL);
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->UnSetVar(WideToASCII(kCrashOnLoadMode).c_str());
+ env->UnSetVar(WideToASCII(kCrashOnUnloadMode).c_str());
}
void set_exception_function(ExceptionFunction func) {
@@ -259,7 +264,8 @@ TEST_F(NtLoaderTest, CrashOnLoadLibrary) {
set_exception_function(OnCrashDuringLoadLibrary);
// Setup to crash on load.
- ::SetEnvironmentVariable(kCrashOnLoadMode, L"1");
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->SetVar(WideToASCII(kCrashOnLoadMode).c_str(), "1");
// And load it.
HMODULE module = ::LoadLibrary(kCrashDllName);
@@ -294,7 +300,8 @@ static void OnCrashDuringUnloadLibrary(EXCEPTION_POINTERS* ex_ptrs) {
TEST_F(NtLoaderTest, CrashOnUnloadLibrary) {
// Setup to crash on unload.
- ::SetEnvironmentVariable(kCrashOnUnloadMode, L"1");
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->SetVar(WideToASCII(kCrashOnUnloadMode).c_str(), "1");
// And load it.
HMODULE module = ::LoadLibrary(kCrashDllName);
diff --git a/chrome_frame/crash_reporting/vectored_handler_unittest.cc b/chrome_frame/crash_reporting/vectored_handler_unittest.cc
index d17847b..4153646 100644
--- a/chrome_frame/crash_reporting/vectored_handler_unittest.cc
+++ b/chrome_frame/crash_reporting/vectored_handler_unittest.cc
@@ -1,10 +1,13 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
#include <atlbase.h>
+#include "base/environment.h"
#include "base/logging.h"
+#include "base/scoped_ptr.h"
+#include "base/utf_string_conversions.h"
#include "chrome_frame/crash_reporting/crash_dll.h"
#include "chrome_frame/crash_reporting/nt_loader.h"
#include "chrome_frame/crash_reporting/vectored_handler-impl.h"
@@ -138,18 +141,19 @@ TEST(ChromeFrame, ExceptionReport) {
g_mock_veh = &veh;
void* id = ::AddVectoredExceptionHandler(FALSE, VEH);
- EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnLoadMode, L"1"));
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ EXPECT_TRUE(env->SetVar(WideToUTF8(kCrashOnLoadMode).c_str(), "1"));
long exceptions_seen = veh.get_exceptions_seen();
HMODULE module = ::LoadLibrary(kCrashDllName);
EXPECT_EQ(NULL, module);
testing::Mock::VerifyAndClearExpectations(&api);
EXPECT_EQ(exceptions_seen + 1, veh.get_exceptions_seen());
- EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnLoadMode, NULL));
+ EXPECT_TRUE(env->UnSetVar(WideToUTF8(kCrashOnLoadMode).c_str()));
// Exception in an unloading module, we are on the stack/
// Make sure we report it.
- EXPECT_TRUE(::SetEnvironmentVariable(kCrashOnUnloadMode, L"1"));
+ EXPECT_TRUE(env->SetVar(WideToUTF8(kCrashOnUnloadMode).c_str(), "1"));
module = ::LoadLibrary(kCrashDllName);