Skip to content

Commit 3a3fe2b

Browse files
committed
crash report fix for win
1 parent 0f941e0 commit 3a3fe2b

6 files changed

Lines changed: 177 additions & 40 deletions

File tree

nw.gypi

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
'dependencies': [
1818
'<(DEPTH)/base/base.gyp:base',
1919
'<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
20-
'<(DEPTH)/breakpad/breakpad.gyp:breakpad_client',
21-
'<(DEPTH)/components/components.gyp:breakpad_component',
2220
'<(DEPTH)/components/components.gyp:autofill_content_renderer',
2321
'<(DEPTH)/components/components.gyp:browser_context_keyed_service',
2422
'<(DEPTH)/content/content.gyp:content_app_browser',
@@ -216,19 +214,17 @@
216214
'src/browser/shell_toolbar_delegate_mac.mm',
217215
'src/browser/standard_menus_mac.h',
218216
'src/browser/standard_menus_mac.mm',
217+
'src/chrome_breakpad_client.cc',
218+
'src/chrome_breakpad_client.h',
219219
'src/common/print_messages.cc',
220220
'src/common/print_messages.h',
221221
'src/common/shell_switches.cc',
222222
'src/common/shell_switches.h',
223-
'src/breakpad_linux.cc',
224-
'src/breakpad_linux.h',
225223
'src/breakpad_linux_impl.h',
226224
'src/breakpad_win.cc',
227225
'src/breakpad_win.h',
228-
'src/chrome_breakpad_client.cc',
229-
'src/chrome_breakpad_client.h',
230-
'src/crash_handler_host_linux.cc',
231-
'src/crash_handler_host_linux.h',
226+
'src/hard_error_handler_win.cc',
227+
'src/hard_error_handler_win.h',
232228
'src/geolocation/shell_access_token_store.cc',
233229
'src/geolocation/shell_access_token_store.h',
234230
'src/media/media_internals.cc',
@@ -302,6 +298,25 @@
302298
'<(DEPTH)/base/allocator/allocator.gyp:allocator',
303299
],
304300
}],
301+
['OS=="win"', {
302+
'dependencies': [
303+
'<(DEPTH)/breakpad/breakpad.gyp:breakpad_handler',
304+
'<(DEPTH)/breakpad/breakpad.gyp:breakpad_sender',
305+
'<(DEPTH)/components/components.gyp:breakpad_component',
306+
],
307+
}],
308+
['os_posix==1 and OS != "mac" and OS != "ios"', {
309+
'sources': [
310+
'src/breakpad_linux.cc',
311+
'src/breakpad_linux.h',
312+
'src/crash_handler_host_linux.cc',
313+
'src/crash_handler_host_linux.h',
314+
],
315+
'dependencies': [
316+
'<(DEPTH)/breakpad/breakpad.gyp:breakpad_client',
317+
'<(DEPTH)/components/components.gyp:breakpad_component',
318+
],
319+
}],
305320
['toolkit_uses_gtk == 1', {
306321
'dependencies': [
307322
# For FT_Init_FreeType and friends.

src/breakpad_win.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "components/breakpad/breakpad_client.h"
3535
#include "content/public/common/content_switches.h"
3636
#include "content/public/common/result_codes.h"
37-
#include "policy/policy_constants.h"
37+
//#include "policy/policy_constants.h"
3838
#include "sandbox/win/src/nt_internals.h"
3939
#include "sandbox/win/src/sidestep/preamble_patcher.h"
4040

@@ -288,6 +288,7 @@ void SetPluginPath(const std::wstring& path) {
288288
// indicates whether policy data was successfully read. If it is true, |result|
289289
// contains the value set by policy.
290290
static bool MetricsReportingControlledByPolicy(bool* result) {
291+
#if 0
291292
string16 key_name = UTF8ToUTF16(policy::key::kMetricsReportingEnabled);
292293
DWORD value = 0;
293294
base::win::RegKey hklm_policy_key(HKEY_LOCAL_MACHINE,
@@ -303,7 +304,7 @@ static bool MetricsReportingControlledByPolicy(bool* result) {
303304
*result = value != 0;
304305
return true;
305306
}
306-
307+
#endif
307308
return false;
308309
}
309310

src/chrome_breakpad_client.cc

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@ void ChromeBreakpadClient::GetProductNameAndVersion(
108108
*product_name = base::ASCIIToUTF16("Chrome");
109109
*version = base::ASCIIToUTF16("0.0.0.0-devel");
110110
}
111-
112-
std::wstring channel_string;
113-
GoogleUpdateSettings::GetChromeChannelAndModifiers(
114-
!GetIsPerUserInstall(exe_path), &channel_string);
115-
*channel_name = base::WideToUTF16(channel_string);
116111
}
117112

118113
bool ChromeBreakpadClient::ShouldShowRestartDialog(base::string16* title,
@@ -153,35 +148,20 @@ bool ChromeBreakpadClient::AboutToRestart() {
153148

154149
base::string16 ChromeBreakpadClient::GetCrashGUID() {
155150
std::wstring guid;
156-
GoogleUpdateSettings::GetMetricsId(&guid);
151+
// GoogleUpdateSettings::GetMetricsId(&guid);
157152
return base::WideToUTF16(guid);
158153
}
159154

160-
bool ChromeBreakpadClient::GetDeferredUploadsSupported(
161-
bool is_per_user_install) {
162-
Version update_version = GoogleUpdateSettings::GetGoogleUpdateVersion(
163-
!is_per_user_install);
164-
if (!update_version.IsValid() ||
165-
update_version.IsOlderThan(std::string(kMinUpdateVersion)))
166-
return false;
167-
168-
return true;
155+
bool ChromeBreakpadClient::GetDeferredUploadsSupported(bool) {
156+
return false;
169157
}
170158

171159
bool ChromeBreakpadClient::GetIsPerUserInstall(const base::FilePath& exe_path) {
172-
return InstallUtil::IsPerUserInstall(exe_path.value().c_str());
160+
return false;
173161
}
174162

175163
bool ChromeBreakpadClient::GetShouldDumpLargerDumps(bool is_per_user_install) {
176-
base::string16 channel_name(base::WideToUTF16(
177-
GoogleUpdateSettings::GetChromeChannel(!is_per_user_install)));
178-
179-
// Capture more detail in crash dumps for beta and dev channel builds.
180-
if (channel_name == base::ASCIIToUTF16("dev") ||
181-
channel_name == base::ASCIIToUTF16("beta") ||
182-
channel_name == GoogleChromeSxSDistribution::ChannelName())
183-
return true;
184-
return false;
164+
return true;
185165
}
186166

187167
int ChromeBreakpadClient::GetResultCodeRespawnFailed() {
@@ -246,7 +226,7 @@ bool ChromeBreakpadClient::IsRunningUnattended() {
246226

247227
#if defined(OS_WIN) || defined(OS_MACOSX)
248228
bool ChromeBreakpadClient::GetCollectStatsConsent() {
249-
return GoogleUpdateSettings::GetCollectStatsConsent();
229+
return false;
250230
}
251231
#endif
252232

src/hard_error_handler_win.cc

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) 2009 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.
4+
5+
#include "chrome/app/hard_error_handler_win.h"
6+
7+
#if defined(_WIN32_WINNT_WIN8) && _MSC_VER < 1700
8+
// The Windows 8 SDK defines FACILITY_VISUALCPP in winerror.h, and in
9+
// delayimp.h previous to VS2012.
10+
#undef FACILITY_VISUALCPP
11+
#endif
12+
#include <DelayIMP.h>
13+
#include <winternl.h>
14+
15+
#include "base/basictypes.h"
16+
#include "base/strings/string_util.h"
17+
#include "components/breakpad/breakpad_client.h"
18+
19+
namespace {
20+
const DWORD kExceptionModuleNotFound = VcppException(ERROR_SEVERITY_ERROR,
21+
ERROR_MOD_NOT_FOUND);
22+
const DWORD kExceptionEntryPtNotFound = VcppException(ERROR_SEVERITY_ERROR,
23+
ERROR_PROC_NOT_FOUND);
24+
// This is defined in <ntstatus.h> but we can't include this file here.
25+
const DWORD FACILITY_GRAPHICS_KERNEL = 0x1E;
26+
const DWORD NT_STATUS_ENTRYPOINT_NOT_FOUND = 0xC0000139;
27+
const DWORD NT_STATUS_DLL_NOT_FOUND = 0xC0000135;
28+
29+
// We assume that exception codes are NT_STATUS codes.
30+
DWORD FacilityFromException(DWORD exception_code) {
31+
return (exception_code >> 16) & 0x0FFF;
32+
}
33+
34+
// This is not a generic function. It only works with some |nt_status| values.
35+
// Check the strings here http://msdn.microsoft.com/en-us/library/cc704588.aspx
36+
// before attempting to use this function.
37+
void RaiseHardErrorMsg(long nt_status, const std::string& p1,
38+
const std::string& p2) {
39+
// If headless just exit silently.
40+
if (breakpad::GetBreakpadClient()->IsRunningUnattended())
41+
return;
42+
43+
HMODULE ntdll = ::GetModuleHandleA("NTDLL.DLL");
44+
wchar_t* msg_template = NULL;
45+
size_t count = ::FormatMessage(
46+
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS |
47+
FORMAT_MESSAGE_FROM_HMODULE,
48+
ntdll,
49+
nt_status,
50+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
51+
reinterpret_cast<wchar_t*>(&msg_template),
52+
0,
53+
NULL);
54+
55+
if (!count)
56+
return;
57+
count += p1.size() + p2.size() + 1;
58+
string16 message;
59+
::wsprintf(WriteInto(&message, count), msg_template, p1.c_str(), p2.c_str());
60+
// The MB_SERVICE_NOTIFICATION causes this message to be displayed by
61+
// csrss. This means that we are not creating windows or pumping WM messages
62+
// in this process.
63+
::MessageBox(NULL, message.c_str(),
64+
L"chrome.exe",
65+
MB_OK | MB_SERVICE_NOTIFICATION);
66+
::LocalFree(msg_template);
67+
}
68+
69+
void ModuleNotFoundHardError(const EXCEPTION_RECORD* ex_record) {
70+
DelayLoadInfo* dli = reinterpret_cast<DelayLoadInfo*>(
71+
ex_record->ExceptionInformation[0]);
72+
if (!dli->szDll)
73+
return;
74+
RaiseHardErrorMsg(NT_STATUS_DLL_NOT_FOUND, dli->szDll, std::string());
75+
}
76+
77+
void EntryPointNotFoundHardError(const EXCEPTION_RECORD* ex_record) {
78+
DelayLoadInfo* dli = reinterpret_cast<DelayLoadInfo*>(
79+
ex_record->ExceptionInformation[0]);
80+
if (!dli->dlp.fImportByName)
81+
return;
82+
if (!dli->dlp.szProcName)
83+
return;
84+
if (!dli->szDll)
85+
return;
86+
RaiseHardErrorMsg(NT_STATUS_ENTRYPOINT_NOT_FOUND,
87+
dli->dlp.szProcName, dli->szDll);
88+
}
89+
90+
} // namespace
91+
92+
bool HardErrorHandler(EXCEPTION_POINTERS* ex_info) {
93+
if (!ex_info)
94+
return false;
95+
if (!ex_info->ExceptionRecord)
96+
return false;
97+
98+
long exception = ex_info->ExceptionRecord->ExceptionCode;
99+
if (exception == kExceptionModuleNotFound) {
100+
ModuleNotFoundHardError(ex_info->ExceptionRecord);
101+
return true;
102+
} else if (exception == kExceptionEntryPtNotFound) {
103+
EntryPointNotFoundHardError(ex_info->ExceptionRecord);
104+
return true;
105+
} else if (FacilityFromException(exception) == FACILITY_GRAPHICS_KERNEL) {
106+
#if defined(USE_AURA)
107+
RaiseHardErrorMsg(exception, std::string(), std::string());
108+
return true;
109+
#else
110+
return false;
111+
#endif
112+
}
113+
return false;
114+
}

src/hard_error_handler_win.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2009 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.
4+
5+
#ifndef CHROME_APP_HARD_ERROR_HANDLER_WIN_H_
6+
#define CHROME_APP_HARD_ERROR_HANDLER_WIN_H_
7+
8+
#include <windows.h>
9+
10+
// This function is in charge of displaying a dialog box that informs the
11+
// user of a fatal condition in chrome. It is meant to be called from
12+
// breakpad's unhandled exception handler after the crash dump has been
13+
// created. The return value will be true if we are to retry launching
14+
// chrome (and show the 'chrome has crashed' dialog) or to silently exit.
15+
//
16+
// This function only handles a few known exceptions, currently:
17+
// - Failure to load a delayload dll.
18+
// - Failure to bind to a delayloaded import.
19+
// - Fatal Graphics card failure (aura build only).
20+
//
21+
// If any of these conditions are encountered, a message box shown by
22+
// the operating system CSRSS process via NtRaiseHardError is invoked.
23+
// The wording and localization is up to the operating system.
24+
//
25+
// Do not call this function for memory related errors like heap corruption
26+
// or stack exahustion. This function assumes that memory allocations are
27+
// possible.
28+
bool HardErrorHandler(EXCEPTION_POINTERS* ex_info);
29+
30+
#endif // CHROME_APP_HARD_ERROR_HANDLER_WIN_H_
31+

src/shell_main_delegate.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,8 @@ const GUID kContentShellProviderName = {
8888
{ 0x84, 0x13, 0xec, 0x94, 0xd8, 0xc2, 0xa4, 0xb6 } };
8989
#endif
9090

91-
#if defined(OS_POSIX)
9291
base::LazyInstance<chrome::ChromeBreakpadClient>::Leaky
9392
g_chrome_breakpad_client = LAZY_INSTANCE_INITIALIZER;
94-
#endif
9593

9694
void InitLogging() {
9795
base::FilePath log_filename;
@@ -135,9 +133,7 @@ bool ShellMainDelegate::BasicStartupComplete(int* exit_code) {
135133
}
136134

137135
void ShellMainDelegate::PreSandboxStartup() {
138-
#if defined(OS_POSIX)
139136
breakpad::SetBreakpadClient(g_chrome_breakpad_client.Pointer());
140-
#endif
141137

142138
#if defined(OS_MACOSX)
143139
OverrideFrameworkBundlePath();

0 commit comments

Comments
 (0)