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

Side by Side Diff: chrome_elf/chrome_elf_main.cc

Issue 2279943002: Don't check for chrome.exe when initializing crash reporting (Closed)
Patch Set: . Created 4 years, 3 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
« no previous file with comments | « no previous file | chrome_elf/elf_imports_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "chrome_elf/chrome_elf_main.h" 5 #include "chrome_elf/chrome_elf_main.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/win/iat_patch_function.h" 12 #include "base/win/iat_patch_function.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/app/chrome_crash_reporter_client_win.h" 14 #include "chrome/app/chrome_crash_reporter_client_win.h"
15 #include "chrome/install_static/install_util.h" 15 #include "chrome/install_static/install_util.h"
16 #include "chrome_elf/blacklist/blacklist.h" 16 #include "chrome_elf/blacklist/blacklist.h"
17 #include "chrome_elf/blacklist/crashpad_helper.h" 17 #include "chrome_elf/blacklist/crashpad_helper.h"
18 #include "chrome_elf/chrome_elf_constants.h" 18 #include "chrome_elf/chrome_elf_constants.h"
19 #include "components/crash/content/app/crashpad.h" 19 #include "components/crash/content/app/crashpad.h"
20 #include "components/crash/core/common/crash_keys.h" 20 #include "components/crash/core/common/crash_keys.h"
21 21
22 namespace { 22 namespace {
23 23
24 base::LazyInstance<std::vector<crash_reporter::Report>>::Leaky g_crash_reports = 24 base::LazyInstance<std::vector<crash_reporter::Report>>::Leaky g_crash_reports =
25 LAZY_INSTANCE_INITIALIZER; 25 LAZY_INSTANCE_INITIALIZER;
26 26
27 // Gets the exe name from the full path of the exe.
28 base::string16 GetExeName() {
29 wchar_t file_path[MAX_PATH] = {};
30 if (!::GetModuleFileName(nullptr, file_path, arraysize(file_path))) {
31 assert(false);
32 return base::string16();
33 }
34 base::string16 file_name_string = file_path;
35 size_t last_slash_pos = file_name_string.find_last_of(L'\\');
36 if (last_slash_pos != base::string16::npos) {
37 file_name_string = file_name_string.substr(
38 last_slash_pos + 1, file_name_string.length() - last_slash_pos);
39 }
40 std::transform(file_name_string.begin(), file_name_string.end(),
41 file_name_string.begin(), ::tolower);
42 return file_name_string;
43 }
44
45 void InitializeCrashReportingForProcess() {
46 // We want to initialize crash reporting only in chrome.exe
47 if (GetExeName() != L"chrome.exe")
48 return;
49 ChromeCrashReporterClient::InitializeCrashReportingForProcess();
50 }
51
52 #if !defined(ADDRESS_SANITIZER) 27 #if !defined(ADDRESS_SANITIZER)
53 // chrome_elf loads early in the process and initializes Crashpad. That in turn 28 // chrome_elf loads early in the process and initializes Crashpad. That in turn
54 // uses the SetUnhandledExceptionFilter API to set a top level exception 29 // uses the SetUnhandledExceptionFilter API to set a top level exception
55 // handler for the process. When the process eventually initializes, CRT sets 30 // handler for the process. When the process eventually initializes, CRT sets
56 // an exception handler which calls TerminateProcess which effectively bypasses 31 // an exception handler which calls TerminateProcess which effectively bypasses
57 // us. Ideally we want to be at the top of the unhandled exception filter 32 // us. Ideally we want to be at the top of the unhandled exception filter
58 // chain. However we don't have a good way of intercepting the 33 // chain. However we don't have a good way of intercepting the
59 // SetUnhandledExceptionFilter API in the sandbox. EAT patching kernel32 or 34 // SetUnhandledExceptionFilter API in the sandbox. EAT patching kernel32 or
60 // kernelbase should ideally work. However the kernel32 kernelbase dlls are 35 // kernelbase should ideally work. However the kernel32 kernelbase dlls are
61 // prebound which causes EAT patching to not work. Sidestep works. However it 36 // prebound which causes EAT patching to not work. Sidestep works. However it
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // This helper is invoked by debugging code in chrome to register the client 78 // This helper is invoked by debugging code in chrome to register the client
104 // id. 79 // id.
105 extern "C" __declspec(dllexport) void SetMetricsClientId( 80 extern "C" __declspec(dllexport) void SetMetricsClientId(
106 const char* client_id) { 81 const char* client_id) {
107 if (client_id) 82 if (client_id)
108 crash_keys::SetMetricsClientIdFromGUID(client_id); 83 crash_keys::SetMetricsClientIdFromGUID(client_id);
109 } 84 }
110 85
111 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { 86 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) {
112 if (reason == DLL_PROCESS_ATTACH) { 87 if (reason == DLL_PROCESS_ATTACH) {
113 InitializeCrashReportingForProcess(); 88 ChromeCrashReporterClient::InitializeCrashReportingForProcess();
114 // CRT on initialization installs an exception filter which calls 89 // CRT on initialization installs an exception filter which calls
115 // TerminateProcess. We need to hook CRT's attempt to set an exception 90 // TerminateProcess. We need to hook CRT's attempt to set an exception
116 // handler and ignore it. Don't do this when ASan is present, or ASan will 91 // handler and ignore it. Don't do this when ASan is present, or ASan will
117 // fail to install its own unhandled exception filter. 92 // fail to install its own unhandled exception filter.
118 #if !defined(ADDRESS_SANITIZER) 93 #if !defined(ADDRESS_SANITIZER)
119 DisableSetUnhandledExceptionFilter(); 94 DisableSetUnhandledExceptionFilter();
120 #endif 95 #endif
121 96
122 install_static::InitializeProcessType(); 97 install_static::InitializeProcessType();
123 98
124 __try { 99 __try {
125 blacklist::Initialize(false); // Don't force, abort if beacon is present. 100 blacklist::Initialize(false); // Don't force, abort if beacon is present.
126 } __except(GenerateCrashDump(GetExceptionInformation())) { 101 } __except(GenerateCrashDump(GetExceptionInformation())) {
127 } 102 }
128 } 103 }
129 return TRUE; 104 return TRUE;
130 } 105 }
OLDNEW
« no previous file with comments | « no previous file | chrome_elf/elf_imports_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698