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

Side by Side Diff: components/crash/content/app/fallback_crash_handler_win.cc

Issue 2638433002: Integrate fallback crash handling in chrome (Closed)
Patch Set: Fix signedness comparison goof. Created 3 years, 11 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/fallback_crash_handler_win.h" 5 #include "components/crash/content/app/fallback_crash_handler_win.h"
6 6
7 #include <dbghelp.h> 7 #include <dbghelp.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 return false; 154 return false;
155 155
156 // Seek to the tail of the file, where we're going to extend it. 156 // Seek to the tail of the file, where we're going to extend it.
157 FilePosition next_available_byte = file_->Seek(base::File::FROM_END, 0); 157 FilePosition next_available_byte = file_->Seek(base::File::FROM_END, 0);
158 if (next_available_byte == kInvalidFilePos) 158 if (next_available_byte == kInvalidFilePos)
159 return false; 159 return false;
160 160
161 // Write the key/value pairs and collect their locations. 161 // Write the key/value pairs and collect their locations.
162 std::vector<crashpad::MinidumpSimpleStringDictionaryEntry> entries; 162 std::vector<crashpad::MinidumpSimpleStringDictionaryEntry> entries;
163 for (const auto& kv : crash_keys) { 163 for (const auto& kv : crash_keys) {
164 // The key of a key/value pair should never be empty.
165 DCHECK(!kv.first.empty());
166
164 crashpad::MinidumpSimpleStringDictionaryEntry entry = {0}; 167 crashpad::MinidumpSimpleStringDictionaryEntry entry = {0};
165 168
166 entry.key = next_available_byte; 169 // Skip this key/value if the value is empty.
167 uint32_t key_len = base::saturated_cast<uint32_t>(kv.first.size()); 170 if (!kv.second.empty()) {
168 if (!WriteAndAdvance(&key_len, sizeof(key_len), &next_available_byte) || 171 entry.key = next_available_byte;
169 !WriteAndAdvance(&kv.first[0], key_len, &next_available_byte)) { 172 uint32_t key_len = base::saturated_cast<uint32_t>(kv.first.size());
170 return false; 173 if (!WriteAndAdvance(&key_len, sizeof(key_len), &next_available_byte) ||
174 !WriteAndAdvance(&kv.first[0], key_len, &next_available_byte)) {
175 return false;
176 }
177
178 entry.value = next_available_byte;
179 uint32_t value_len = base::saturated_cast<uint32_t>(kv.second.size());
180 if (!WriteAndAdvance(&value_len, sizeof(value_len),
181 &next_available_byte) ||
182 !WriteAndAdvance(&kv.second[0], value_len, &next_available_byte)) {
183 return false;
184 }
185
186 entries.push_back(entry);
171 } 187 }
172
173 entry.value = next_available_byte;
174 uint32_t value_len = base::saturated_cast<uint32_t>(kv.second.size());
175 if (!WriteAndAdvance(&value_len, sizeof(value_len), &next_available_byte) ||
176 !WriteAndAdvance(&kv.second[0], value_len, &next_available_byte)) {
177 return false;
178 }
179
180 entries.push_back(entry);
181 } 188 }
182 189
183 // Write the dictionary array itself - note the array is count-prefixed. 190 // Write the dictionary array itself - note the array is count-prefixed.
184 FilePosition dict_pos = next_available_byte; 191 FilePosition dict_pos = next_available_byte;
185 uint32_t entry_count = base::saturated_cast<uint32_t>(entries.size()); 192 uint32_t entry_count = base::saturated_cast<uint32_t>(entries.size());
186 if (!WriteAndAdvance(&entry_count, sizeof(entry_count), 193 if (!WriteAndAdvance(&entry_count, sizeof(entry_count),
187 &next_available_byte) || 194 &next_available_byte) ||
188 !WriteAndAdvance(&entries[0], entry_count * sizeof(entries[0]), 195 !WriteAndAdvance(&entries[0], entry_count * sizeof(entries[0]),
189 &next_available_byte)) { 196 &next_available_byte)) {
190 return false; 197 return false;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 return false; 340 return false;
334 } 341 }
335 342
336 // Before taking ownership of the supposed handle, see whether it's really 343 // Before taking ownership of the supposed handle, see whether it's really
337 // a process handle. 344 // a process handle.
338 base::ProcessHandle process_handle = base::win::Uint32ToHandle(uint_process); 345 base::ProcessHandle process_handle = base::win::Uint32ToHandle(uint_process);
339 if (base::GetProcId(process_handle) == base::kNullProcessId) 346 if (base::GetProcId(process_handle) == base::kNullProcessId)
340 return false; 347 return false;
341 348
342 // Retrieve the thread id argument. 349 // Retrieve the thread id argument.
343 unsigned thread_id = 0; 350 unsigned int thread_id = 0;
344 if (!base::StringToUint(cmd_line.GetSwitchValueASCII("thread"), &thread_id)) { 351 if (!base::StringToUint(cmd_line.GetSwitchValueASCII("thread"), &thread_id)) {
345 return false; 352 return false;
346 } 353 }
354 thread_id_ = thread_id;
347 355
348 // Retrieve the "exception-pointers" argument. 356 // Retrieve the "exception-pointers" argument.
349 uint64_t uint_exc_ptrs = 0; 357 uint64_t uint_exc_ptrs = 0;
350 if (!base::StringToUint64(cmd_line.GetSwitchValueASCII("exception-pointers"), 358 if (!base::StringToUint64(cmd_line.GetSwitchValueASCII("exception-pointers"),
351 &uint_exc_ptrs)) { 359 &uint_exc_ptrs)) {
352 return false; 360 return false;
353 } 361 }
354 exception_ptrs_ = static_cast<uintptr_t>(uint_exc_ptrs); 362 exception_ptrs_ = static_cast<uintptr_t>(uint_exc_ptrs);
355 363
356 // Retrieve the "database" argument. 364 // Retrieve the "database" argument.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 451
444 crashpad::UUID report_id = {}; 452 crashpad::UUID report_id = {};
445 status = database->FinishedWritingCrashReport(report, &report_id); 453 status = database->FinishedWritingCrashReport(report, &report_id);
446 if (status != crashpad::CrashReportDatabase::kNoError) 454 if (status != crashpad::CrashReportDatabase::kNoError)
447 return false; 455 return false;
448 456
449 return true; 457 return true;
450 } 458 }
451 459
452 } // namespace crash_reporter 460 } // namespace crash_reporter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698