summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 06:03:11 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 06:03:11 +0000
commitc912db5ede05f45e5346b745da9da97b833922a8 (patch)
treef2c4c70fb9581433ce34ef69fe48e060473916b2 /base
parentfaf7de70c5fbea47af48558a1f83acddedd63adf (diff)
downloadchromium_src-c912db5ede05f45e5346b745da9da97b833922a8.zip
chromium_src-c912db5ede05f45e5346b745da9da97b833922a8.tar.gz
chromium_src-c912db5ede05f45e5346b745da9da97b833922a8.tar.bz2
[windows] Make calls to exit(), _exit(), abort(), and ExitProcess() from the renderer process result in a crash.
BUG=118665 Review URL: http://codereview.chromium.org/9803002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128701 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/win/dllmain.cc11
-rw-r--r--base/win/win_util.cc12
-rw-r--r--base/win/win_util.h10
3 files changed, 29 insertions, 4 deletions
diff --git a/base/win/dllmain.cc b/base/win/dllmain.cc
index fad9519..15437e0 100644
--- a/base/win/dllmain.cc
+++ b/base/win/dllmain.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -26,7 +26,8 @@
#include <windows.h>
-#include "base/logging.h"
+#include "base/compiler_specific.h"
+#include "base/win/win_util.h"
// Indicate if another service is scanning the callbacks. When this becomes
// set to true, then DllMain() will stop supporting the callback service. This
@@ -83,10 +84,16 @@ PIMAGE_TLS_CALLBACK p_thread_callback_dllmain_typical_entry = on_callback;
#endif // _WIN64
} // extern "C"
+NOINLINE static void CrashOnProcessDetach() {
+ *((int*)0) = 0x356;
+}
// Make DllMain call the listed callbacks. This way any third parties that are
// linked in will also be called.
BOOL WINAPI DllMain(PVOID h, DWORD reason, PVOID reserved) {
+ if (DLL_PROCESS_DETACH == reason && base::win::ShouldCrashOnProcessDetach())
+ CrashOnProcessDetach();
+
if (DLL_THREAD_DETACH != reason && DLL_PROCESS_DETACH != reason)
return true; // We won't service THREAD_ATTACH calls.
diff --git a/base/win/win_util.cc b/base/win/win_util.cc
index 15a6445..8dd5afc 100644
--- a/base/win/win_util.cc
+++ b/base/win/win_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -23,6 +23,8 @@
namespace base {
namespace win {
+static bool g_crash_on_process_detach = false;
+
#define NONCLIENTMETRICS_SIZE_PRE_VISTA \
SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(NONCLIENTMETRICS, lfMessageFont)
@@ -148,6 +150,14 @@ bool ReadCommandFromAutoRun(HKEY root_key,
return (autorun_key.ReadValue(name.c_str(), command) == ERROR_SUCCESS);
}
+void SetShouldCrashOnProcessDetach(bool crash) {
+ g_crash_on_process_detach = crash;
+}
+
+bool ShouldCrashOnProcessDetach() {
+ return g_crash_on_process_detach;
+}
+
} // namespace win
} // namespace base
diff --git a/base/win/win_util.h b/base/win/win_util.h
index 66c5016..733f2092 100644
--- a/base/win/win_util.h
+++ b/base/win/win_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -93,6 +93,14 @@ BASE_EXPORT bool ReadCommandFromAutoRun(HKEY root_key,
const string16& name,
string16* command);
+// Sets whether to crash the process during exit. This is inspected by DLLMain
+// and used to intercept unexpected terminations of the process (via calls to
+// exit(), abort(), _exit(), ExitProcess()) and convert them into crashes.
+// Note that not all mechanisms for terminating the process are covered by
+// this. In particular, TerminateProcess() is not caught.
+BASE_EXPORT void SetShouldCrashOnProcessDetach(bool crash);
+BASE_EXPORT bool ShouldCrashOnProcessDetach();
+
// Get the size of a struct up to and including the specified member.
// This is necessary to set compatible struct sizes for different versions
// of certain Windows APIs (e.g. SystemParametersInfo).