OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app/breakpad_win.h" | 5 #include "chrome/app/breakpad_win.h" |
6 | 6 |
7 #include <shellapi.h> | 7 #include <shellapi.h> |
8 #include <tchar.h> | 8 #include <tchar.h> |
9 #include <userenv.h> | 9 #include <userenv.h> |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 EXCEPTION_POINTERS g_surrogate_exception_pointers = {0}; | 99 EXCEPTION_POINTERS g_surrogate_exception_pointers = {0}; |
100 EXCEPTION_RECORD g_surrogate_exception_record = {0}; | 100 EXCEPTION_RECORD g_surrogate_exception_record = {0}; |
101 CONTEXT g_surrogate_context = {0}; | 101 CONTEXT g_surrogate_context = {0}; |
102 | 102 |
103 typedef NTSTATUS (WINAPI* NtTerminateProcessPtr)(HANDLE ProcessHandle, | 103 typedef NTSTATUS (WINAPI* NtTerminateProcessPtr)(HANDLE ProcessHandle, |
104 NTSTATUS ExitStatus); | 104 NTSTATUS ExitStatus); |
105 char* g_real_terminate_process_stub = NULL; | 105 char* g_real_terminate_process_stub = NULL; |
106 | 106 |
107 static size_t g_client_id_offset = 0; | 107 static size_t g_client_id_offset = 0; |
108 static size_t g_printer_info_offset = 0; | |
109 static size_t g_num_switches_offset = 0; | 108 static size_t g_num_switches_offset = 0; |
110 static size_t g_switches_offset = 0; | 109 static size_t g_switches_offset = 0; |
111 static size_t g_dynamic_keys_offset = 0; | 110 static size_t g_dynamic_keys_offset = 0; |
112 typedef std::map<std::wstring, google_breakpad::CustomInfoEntry*> | 111 typedef std::map<std::wstring, google_breakpad::CustomInfoEntry*> |
113 DynamicEntriesMap; | 112 DynamicEntriesMap; |
114 DynamicEntriesMap* g_dynamic_entries = NULL; | 113 DynamicEntriesMap* g_dynamic_entries = NULL; |
115 // Allow for 128 entries. POSIX uses 64 entries of 256 bytes, so Windows needs | 114 // Allow for 128 entries. POSIX uses 64 entries of 256 bytes, so Windows needs |
116 // 256 entries of 64 bytes to match. See CustomInfoEntry::kValueMaxLength in | 115 // 256 entries of 64 bytes to match. See CustomInfoEntry::kValueMaxLength in |
117 // Breakpad. | 116 // Breakpad. |
118 const size_t kMaxDynamicEntries = 256; | 117 const size_t kMaxDynamicEntries = 256; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 L"profile-type", GetProfileType().c_str())); | 450 L"profile-type", GetProfileType().c_str())); |
452 | 451 |
453 if (g_deferred_crash_uploads) | 452 if (g_deferred_crash_uploads) |
454 g_custom_entries->push_back( | 453 g_custom_entries->push_back( |
455 google_breakpad::CustomInfoEntry(L"deferred-upload", L"true")); | 454 google_breakpad::CustomInfoEntry(L"deferred-upload", L"true")); |
456 | 455 |
457 if (!special_build.empty()) | 456 if (!special_build.empty()) |
458 g_custom_entries->push_back(google_breakpad::CustomInfoEntry( | 457 g_custom_entries->push_back(google_breakpad::CustomInfoEntry( |
459 L"special", UTF16ToWide(special_build).c_str())); | 458 L"special", UTF16ToWide(special_build).c_str())); |
460 | 459 |
461 // Add empty values for the prn_info-*. We'll put the actual values when we | |
462 // collect them at this location. | |
463 g_printer_info_offset = g_custom_entries->size(); | |
464 // one-based index for the name suffix. | |
465 for (size_t i = 1; i <= kMaxReportedPrinterRecords; ++i) { | |
466 g_custom_entries->push_back( | |
467 google_breakpad::CustomInfoEntry( | |
468 base::StringPrintf(L"prn-info-%d", i).c_str(), L"")); | |
469 } | |
470 | |
471 // Read the id from registry. If reporting has never been enabled | 460 // Read the id from registry. If reporting has never been enabled |
472 // the result will be empty string. Its OK since when user enables reporting | 461 // the result will be empty string. Its OK since when user enables reporting |
473 // we will insert the new value at this location. | 462 // we will insert the new value at this location. |
474 std::wstring guid = | 463 std::wstring guid = |
475 base::UTF16ToWide(breakpad::GetBreakpadClient()->GetCrashGUID()); | 464 base::UTF16ToWide(breakpad::GetBreakpadClient()->GetCrashGUID()); |
476 g_client_id_offset = g_custom_entries->size(); | 465 g_client_id_offset = g_custom_entries->size(); |
477 g_custom_entries->push_back( | 466 g_custom_entries->push_back( |
478 google_breakpad::CustomInfoEntry(L"guid", guid.c_str())); | 467 google_breakpad::CustomInfoEntry(L"guid", guid.c_str())); |
479 | 468 |
480 // Add empty values for the command line switches. We will fill them with | 469 // Add empty values for the command line switches. We will fill them with |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 return; | 635 return; |
647 | 636 |
648 if (!g_custom_entries) | 637 if (!g_custom_entries) |
649 return; | 638 return; |
650 | 639 |
651 base::wcslcpy((*g_custom_entries)[g_client_id_offset].value, | 640 base::wcslcpy((*g_custom_entries)[g_client_id_offset].value, |
652 client_id, | 641 client_id, |
653 google_breakpad::CustomInfoEntry::kValueMaxLength); | 642 google_breakpad::CustomInfoEntry::kValueMaxLength); |
654 } | 643 } |
655 | 644 |
656 extern "C" void __declspec(dllexport) __cdecl SetPrinterInfo( | |
657 const wchar_t* printer_info) { | |
658 if (!g_custom_entries) | |
659 return; | |
660 std::vector<string16> info; | |
661 base::SplitString(printer_info, L';', &info); | |
662 DCHECK_LE(info.size(), kMaxReportedPrinterRecords); | |
663 info.resize(kMaxReportedPrinterRecords); | |
664 for (size_t i = 0; i < info.size(); ++i) { | |
665 base::wcslcpy((*g_custom_entries)[g_printer_info_offset + i].value, | |
666 info[i].c_str(), | |
667 google_breakpad::CustomInfoEntry::kValueMaxLength); | |
668 } | |
669 } | |
670 | |
671 // NOTE: This function is used by SyzyASAN to annotate crash reports. If you | 645 // NOTE: This function is used by SyzyASAN to annotate crash reports. If you |
672 // change the name or signature of this function you will break SyzyASAN | 646 // change the name or signature of this function you will break SyzyASAN |
673 // instrumented releases of Chrome. Please contact syzygy-team@chromium.org | 647 // instrumented releases of Chrome. Please contact syzygy-team@chromium.org |
674 // before doing so! | 648 // before doing so! |
675 extern "C" void __declspec(dllexport) __cdecl SetCrashKeyValueImpl( | 649 extern "C" void __declspec(dllexport) __cdecl SetCrashKeyValueImpl( |
676 const wchar_t* key, const wchar_t* value) { | 650 const wchar_t* key, const wchar_t* value) { |
677 // CustomInfoEntry limits the length of key and value. If they exceed | 651 // CustomInfoEntry limits the length of key and value. If they exceed |
678 // their maximum length the underlying string handling functions raise | 652 // their maximum length the underlying string handling functions raise |
679 // an exception and prematurely trigger a crash. Truncate here. | 653 // an exception and prematurely trigger a crash. Truncate here. |
680 std::wstring safe_key(std::wstring(key).substr( | 654 std::wstring safe_key(std::wstring(key).substr( |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 previous_filter = SetUnhandledExceptionFilter(filter); | 1006 previous_filter = SetUnhandledExceptionFilter(filter); |
1033 } | 1007 } |
1034 | 1008 |
1035 void StringVectorToCStringVector(const std::vector<std::wstring>& wstrings, | 1009 void StringVectorToCStringVector(const std::vector<std::wstring>& wstrings, |
1036 std::vector<const wchar_t*>* cstrings) { | 1010 std::vector<const wchar_t*>* cstrings) { |
1037 cstrings->clear(); | 1011 cstrings->clear(); |
1038 cstrings->reserve(wstrings.size()); | 1012 cstrings->reserve(wstrings.size()); |
1039 for (size_t i = 0; i < wstrings.size(); ++i) | 1013 for (size_t i = 0; i < wstrings.size(); ++i) |
1040 cstrings->push_back(wstrings[i].c_str()); | 1014 cstrings->push_back(wstrings[i].c_str()); |
1041 } | 1015 } |
OLD | NEW |