| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/crash/content/app/crashpad.h" | 5 #include "components/crash/content/app/crashpad.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #if BUILDFLAG(ENABLE_KASKO) | 10 #if BUILDFLAG(ENABLE_KASKO) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "third_party/crashpad/crashpad/client/settings.h" | 35 #include "third_party/crashpad/crashpad/client/settings.h" |
| 36 #include "third_party/crashpad/crashpad/client/simple_string_dictionary.h" | 36 #include "third_party/crashpad/crashpad/client/simple_string_dictionary.h" |
| 37 #include "third_party/crashpad/crashpad/client/simulate_crash.h" | 37 #include "third_party/crashpad/crashpad/client/simulate_crash.h" |
| 38 | 38 |
| 39 #if defined(OS_POSIX) | 39 #if defined(OS_POSIX) |
| 40 #include <unistd.h> | 40 #include <unistd.h> |
| 41 #endif // OS_POSIX | 41 #endif // OS_POSIX |
| 42 | 42 |
| 43 #if BUILDFLAG(ENABLE_KASKO) | 43 #if BUILDFLAG(ENABLE_KASKO) |
| 44 #include "base/win/scoped_handle.h" | 44 #include "base/win/scoped_handle.h" |
| 45 #include "base/win/win_util.h" | |
| 46 #include "third_party/crashpad/crashpad/snapshot/api/module_annotations_win.h" | 45 #include "third_party/crashpad/crashpad/snapshot/api/module_annotations_win.h" |
| 47 #endif | 46 #endif |
| 48 | 47 |
| 49 namespace crash_reporter { | 48 namespace crash_reporter { |
| 50 | 49 |
| 51 namespace { | 50 namespace { |
| 52 | 51 |
| 53 crashpad::SimpleStringDictionary* g_simple_string_dictionary; | 52 crashpad::SimpleStringDictionary* g_simple_string_dictionary; |
| 54 crashpad::CrashReportDatabase* g_database; | 53 crashpad::CrashReportDatabase* g_database; |
| 55 | 54 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Rather than including the code to force the crash here, allow the caller to | 97 // Rather than including the code to force the crash here, allow the caller to |
| 99 // do it. | 98 // do it. |
| 100 return false; | 99 return false; |
| 101 } | 100 } |
| 102 | 101 |
| 103 void DumpWithoutCrashing() { | 102 void DumpWithoutCrashing() { |
| 104 CRASHPAD_SIMULATE_CRASH(); | 103 CRASHPAD_SIMULATE_CRASH(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 #if BUILDFLAG(ENABLE_KASKO) | 106 #if BUILDFLAG(ENABLE_KASKO) |
| 107 // TODO(ananta) |
| 108 // We cannot depend on functionality in base which pulls in dependencies on |
| 109 // user32 directly or indirectly. The GetLoadedModulesSnapshot is a copy of the |
| 110 // function in base/win/win_util.cc. Depending on the base function pulls in |
| 111 // dependencies on user32 due to other functionality in win_util.cc. This |
| 112 // function should be removed when KASKO is removed. |
| 113 bool GetLoadedModulesSnapshot(HANDLE process, std::vector<HMODULE>* snapshot) { |
| 114 DCHECK(snapshot); |
| 115 DCHECK_EQ(0u, snapshot->size()); |
| 116 snapshot->resize(128); |
| 117 |
| 118 // We will retry at least once after first determining |bytes_required|. If |
| 119 // the list of modules changes after we receive |bytes_required| we may retry |
| 120 // more than once. |
| 121 int retries_remaining = 5; |
| 122 do { |
| 123 DWORD bytes_required = 0; |
| 124 // EnumProcessModules returns 'success' even if the buffer size is too |
| 125 // small. |
| 126 DCHECK_GE(std::numeric_limits<DWORD>::max(), |
| 127 snapshot->size() * sizeof(HMODULE)); |
| 128 if (!::EnumProcessModules( |
| 129 process, &(*snapshot)[0], |
| 130 static_cast<DWORD>(snapshot->size() * sizeof(HMODULE)), |
| 131 &bytes_required)) { |
| 132 DPLOG(ERROR) << "::EnumProcessModules failed."; |
| 133 return false; |
| 134 } |
| 135 DCHECK_EQ(0u, bytes_required % sizeof(HMODULE)); |
| 136 size_t num_modules = bytes_required / sizeof(HMODULE); |
| 137 if (num_modules <= snapshot->size()) { |
| 138 // Buffer size was too big, presumably because a module was unloaded. |
| 139 snapshot->erase(snapshot->begin() + num_modules, snapshot->end()); |
| 140 return true; |
| 141 } else if (num_modules == 0) { |
| 142 DLOG(ERROR) << "Can't determine the module list size."; |
| 143 return false; |
| 144 } else { |
| 145 // Buffer size was too small. Try again with a larger buffer. A little |
| 146 // more room is given to avoid multiple expensive calls to |
| 147 // ::EnumProcessModules() just because one module has been added. |
| 148 snapshot->resize(num_modules + 8, NULL); |
| 149 } |
| 150 } while (--retries_remaining); |
| 151 |
| 152 DLOG(ERROR) << "Failed to enumerate modules."; |
| 153 return false; |
| 154 } |
| 155 |
| 108 HMODULE GetModuleInProcess(base::ProcessHandle process, | 156 HMODULE GetModuleInProcess(base::ProcessHandle process, |
| 109 const wchar_t* module_name) { | 157 const wchar_t* module_name) { |
| 110 std::vector<HMODULE> modules_snapshot; | 158 std::vector<HMODULE> modules_snapshot; |
| 111 if (!base::win::GetLoadedModulesSnapshot(process, &modules_snapshot)) | 159 if (!GetLoadedModulesSnapshot(process, &modules_snapshot)) |
| 112 return nullptr; | 160 return nullptr; |
| 113 | 161 |
| 114 for (HMODULE module : modules_snapshot) { | 162 for (HMODULE module : modules_snapshot) { |
| 115 wchar_t current_module_name[MAX_PATH]; | 163 wchar_t current_module_name[MAX_PATH]; |
| 116 if (!::GetModuleBaseName(process, module, current_module_name, MAX_PATH)) | 164 if (!::GetModuleBaseName(process, module, current_module_name, MAX_PATH)) |
| 117 continue; | 165 continue; |
| 118 | 166 |
| 119 if (std::wcscmp(module_name, current_module_name) == 0) | 167 if (std::wcscmp(module_name, current_module_name) == 0) |
| 120 return module; | 168 return module; |
| 121 } | 169 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 base::UTF16ToUTF8(value)); | 455 base::UTF16ToUTF8(value)); |
| 408 } | 456 } |
| 409 | 457 |
| 410 void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl(const wchar_t* key) { | 458 void __declspec(dllexport) __cdecl ClearCrashKeyValueImpl(const wchar_t* key) { |
| 411 crash_reporter::ClearCrashKey(base::UTF16ToUTF8(key)); | 459 crash_reporter::ClearCrashKey(base::UTF16ToUTF8(key)); |
| 412 } | 460 } |
| 413 | 461 |
| 414 } // extern "C" | 462 } // extern "C" |
| 415 | 463 |
| 416 #endif // OS_WIN | 464 #endif // OS_WIN |
| OLD | NEW |