| OLD | NEW |
| 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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 return file_name_string; | 43 return file_name_string; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void InitializeCrashReportingForProcess() { | 46 void InitializeCrashReportingForProcess() { |
| 47 // We want to initialize crash reporting only in chrome.exe | 47 // We want to initialize crash reporting only in chrome.exe |
| 48 if (GetExeName() != L"chrome.exe") | 48 if (GetExeName() != L"chrome.exe") |
| 49 return; | 49 return; |
| 50 ChromeCrashReporterClient::InitializeCrashReportingForProcess(); | 50 ChromeCrashReporterClient::InitializeCrashReportingForProcess(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 #if !defined(ADDRESS_SANITIZER) |
| 53 // chrome_elf loads early in the process and initializes Crashpad. That in turn | 54 // chrome_elf loads early in the process and initializes Crashpad. That in turn |
| 54 // uses the SetUnhandledExceptionFilter API to set a top level exception | 55 // uses the SetUnhandledExceptionFilter API to set a top level exception |
| 55 // handler for the process. When the process eventually initializes, CRT sets | 56 // handler for the process. When the process eventually initializes, CRT sets |
| 56 // an exception handler which calls TerminateProcess which effectively bypasses | 57 // an exception handler which calls TerminateProcess which effectively bypasses |
| 57 // us. Ideally we want to be at the top of the unhandled exception filter | 58 // 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 | 59 // chain. However we don't have a good way of intercepting the |
| 59 // SetUnhandledExceptionFilter API in the sandbox. EAT patching kernel32 or | 60 // SetUnhandledExceptionFilter API in the sandbox. EAT patching kernel32 or |
| 60 // kernelbase should ideally work. However the kernel32 kernelbase dlls are | 61 // kernelbase should ideally work. However the kernel32 kernelbase dlls are |
| 61 // prebound which causes EAT patching to not work. Sidestep works. However it | 62 // prebound which causes EAT patching to not work. Sidestep works. However it |
| 62 // is only supported for 32 bit. For now we use IAT patching for the | 63 // is only supported for 32 bit. For now we use IAT patching for the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 73 } | 74 } |
| 74 | 75 |
| 75 // Please refer above to more information about why we intercept the | 76 // Please refer above to more information about why we intercept the |
| 76 // SetUnhandledExceptionFilter API. | 77 // SetUnhandledExceptionFilter API. |
| 77 void DisableSetUnhandledExceptionFilter() { | 78 void DisableSetUnhandledExceptionFilter() { |
| 78 DWORD patched = g_set_unhandled_exception_filter.PatchFromModule( | 79 DWORD patched = g_set_unhandled_exception_filter.PatchFromModule( |
| 79 GetModuleHandle(nullptr), "kernel32.dll", "SetUnhandledExceptionFilter", | 80 GetModuleHandle(nullptr), "kernel32.dll", "SetUnhandledExceptionFilter", |
| 80 SetUnhandledExceptionFilterPatch); | 81 SetUnhandledExceptionFilterPatch); |
| 81 CHECK(patched == 0); | 82 CHECK(patched == 0); |
| 82 } | 83 } |
| 84 #endif // !defined(ADDRESS_SANITIZER) |
| 83 | 85 |
| 84 } // namespace | 86 } // namespace |
| 85 | 87 |
| 86 void SignalChromeElf() { | 88 void SignalChromeElf() { |
| 87 blacklist::ResetBeacon(); | 89 blacklist::ResetBeacon(); |
| 88 } | 90 } |
| 89 | 91 |
| 90 // This helper is invoked by code in chrome.dll to retrieve the crash reports. | 92 // This helper is invoked by code in chrome.dll to retrieve the crash reports. |
| 91 // See CrashUploadListCrashpad. Note that we do not pass an std::vector here, | 93 // See CrashUploadListCrashpad. Note that we do not pass an std::vector here, |
| 92 // because we do not want to allocate/free in different modules. The returned | 94 // because we do not want to allocate/free in different modules. The returned |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 const char* client_id) { | 107 const char* client_id) { |
| 106 if (client_id) | 108 if (client_id) |
| 107 crash_keys::SetMetricsClientIdFromGUID(client_id); | 109 crash_keys::SetMetricsClientIdFromGUID(client_id); |
| 108 } | 110 } |
| 109 | 111 |
| 110 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { | 112 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { |
| 111 if (reason == DLL_PROCESS_ATTACH) { | 113 if (reason == DLL_PROCESS_ATTACH) { |
| 112 InitializeCrashReportingForProcess(); | 114 InitializeCrashReportingForProcess(); |
| 113 // CRT on initialization installs an exception filter which calls | 115 // CRT on initialization installs an exception filter which calls |
| 114 // TerminateProcess. We need to hook CRT's attempt to set an exception | 116 // TerminateProcess. We need to hook CRT's attempt to set an exception |
| 115 // handler and ignore it. | 117 // handler and ignore it. Don't do this when ASan is present, or ASan will |
| 118 // fail to install its own unhandled exception filter. |
| 119 #if !defined(ADDRESS_SANITIZER) |
| 116 DisableSetUnhandledExceptionFilter(); | 120 DisableSetUnhandledExceptionFilter(); |
| 121 #endif |
| 117 | 122 |
| 118 install_static::InitializeProcessType(); | 123 install_static::InitializeProcessType(); |
| 119 if (install_static::g_process_type == | 124 if (install_static::g_process_type == |
| 120 install_static::ProcessType::BROWSER_PROCESS) | 125 install_static::ProcessType::BROWSER_PROCESS) |
| 121 EarlyBrowserSecurity(); | 126 EarlyBrowserSecurity(); |
| 122 | 127 |
| 123 __try { | 128 __try { |
| 124 blacklist::Initialize(false); // Don't force, abort if beacon is present. | 129 blacklist::Initialize(false); // Don't force, abort if beacon is present. |
| 125 } __except(GenerateCrashDump(GetExceptionInformation())) { | 130 } __except(GenerateCrashDump(GetExceptionInformation())) { |
| 126 } | 131 } |
| 127 } | 132 } |
| 128 return TRUE; | 133 return TRUE; |
| 129 } | 134 } |
| OLD | NEW |