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 <assert.h> | 7 #include <assert.h> |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include "chrome/install_static/install_details.h" | 10 #include "chrome/install_static/install_details.h" |
11 #include "chrome/install_static/install_util.h" | 11 #include "chrome/install_static/install_util.h" |
12 #include "chrome/install_static/product_install_details.h" | 12 #include "chrome/install_static/product_install_details.h" |
13 #include "chrome/install_static/user_data_dir.h" | 13 #include "chrome/install_static/user_data_dir.h" |
14 #include "chrome_elf/blacklist/blacklist.h" | 14 #include "chrome_elf/blacklist/blacklist.h" |
15 #include "chrome_elf/crash/crash_helper.h" | 15 #include "chrome_elf/crash/crash_helper.h" |
16 | 16 |
| 17 // This function is a temporary workaround for https://crbug.com/655788. We |
| 18 // need to come up with a better way to initialize crash reporting that can |
| 19 // happen inside DllMain(). |
| 20 void SignalInitializeCrashReporting() { |
| 21 if (!elf_crash::InitializeCrashReporting()) { |
| 22 #ifdef _DEBUG |
| 23 assert(false); |
| 24 #endif // _DEBUG |
| 25 } |
| 26 } |
| 27 |
17 void SignalChromeElf() { | 28 void SignalChromeElf() { |
18 blacklist::ResetBeacon(); | 29 blacklist::ResetBeacon(); |
19 } | 30 } |
20 | 31 |
21 extern "C" void GetUserDataDirectoryThunk(wchar_t* user_data_dir, | 32 extern "C" void GetUserDataDirectoryThunk(wchar_t* user_data_dir, |
22 size_t user_data_dir_length, | 33 size_t user_data_dir_length, |
23 wchar_t* invalid_user_data_dir, | 34 wchar_t* invalid_user_data_dir, |
24 size_t invalid_user_data_dir_length) { | 35 size_t invalid_user_data_dir_length) { |
25 std::wstring user_data_dir_str, invalid_user_data_dir_str; | 36 std::wstring user_data_dir_str, invalid_user_data_dir_str; |
26 bool ret = install_static::GetUserDataDirectory(&user_data_dir_str, | 37 bool ret = install_static::GetUserDataDirectory(&user_data_dir_str, |
27 &invalid_user_data_dir_str); | 38 &invalid_user_data_dir_str); |
28 assert(ret); | 39 assert(ret); |
29 install_static::IgnoreUnused(ret); | 40 install_static::IgnoreUnused(ret); |
30 wcsncpy_s(user_data_dir, user_data_dir_length, user_data_dir_str.c_str(), | 41 wcsncpy_s(user_data_dir, user_data_dir_length, user_data_dir_str.c_str(), |
31 _TRUNCATE); | 42 _TRUNCATE); |
32 wcsncpy_s(invalid_user_data_dir, invalid_user_data_dir_length, | 43 wcsncpy_s(invalid_user_data_dir, invalid_user_data_dir_length, |
33 invalid_user_data_dir_str.c_str(), _TRUNCATE); | 44 invalid_user_data_dir_str.c_str(), _TRUNCATE); |
34 } | 45 } |
35 | 46 |
36 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { | 47 BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved) { |
37 if (reason == DLL_PROCESS_ATTACH) { | 48 if (reason == DLL_PROCESS_ATTACH) { |
38 install_static::InitializeProductDetailsForPrimaryModule(); | 49 install_static::InitializeProductDetailsForPrimaryModule(); |
39 | 50 |
40 if (!elf_crash::InitializeCrashReporting()) { | |
41 assert(false); | |
42 } | |
43 | |
44 // CRT on initialization installs an exception filter which calls | 51 // CRT on initialization installs an exception filter which calls |
45 // TerminateProcess. We need to hook CRT's attempt to set an exception. | 52 // TerminateProcess. We need to hook CRT's attempt to set an exception. |
46 elf_crash::DisableSetUnhandledExceptionFilter(); | 53 elf_crash::DisableSetUnhandledExceptionFilter(); |
47 | 54 |
48 install_static::InitializeProcessType(); | 55 install_static::InitializeProcessType(); |
49 | 56 |
50 __try { | 57 __try { |
51 blacklist::Initialize(false); // Don't force, abort if beacon is present. | 58 blacklist::Initialize(false); // Don't force, abort if beacon is present. |
52 } __except (elf_crash::GenerateCrashDump(GetExceptionInformation())) { | 59 } __except (elf_crash::GenerateCrashDump(GetExceptionInformation())) { |
53 } | 60 } |
54 } else if (reason == DLL_PROCESS_DETACH) { | 61 } else if (reason == DLL_PROCESS_DETACH) { |
55 elf_crash::ShutdownCrashReporting(); | 62 elf_crash::ShutdownCrashReporting(); |
56 } | 63 } |
57 return TRUE; | 64 return TRUE; |
58 } | 65 } |
OLD | NEW |