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 // For linux_syscall_support.h. This makes it safe to call embedded system | 5 // For linux_syscall_support.h. This makes it safe to call embedded system |
6 // calls when in seccomp mode. | 6 // calls when in seccomp mode. |
7 #define SYS_SYSCALL_ENTRYPOINT "playground$syscallEntryPoint" | 7 #define SYS_SYSCALL_ENTRYPOINT "playground$syscallEntryPoint" |
8 | 8 |
9 #include "chrome/app/breakpad_linux.h" | 9 #include "chrome/app/breakpad_linuxish.h" |
10 | 10 |
11 #include <fcntl.h> | 11 #include <fcntl.h> |
12 #include <poll.h> | 12 #include <poll.h> |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 #include <sys/socket.h> | 14 #include <sys/socket.h> |
15 #include <sys/time.h> | 15 #include <sys/time.h> |
16 #include <sys/types.h> | 16 #include <sys/types.h> |
17 #include <sys/wait.h> | 17 #include <sys/wait.h> |
18 #include <sys/uio.h> | 18 #include <sys/uio.h> |
19 #include <time.h> | 19 #include <time.h> |
(...skipping 14 matching lines...) Expand all Loading... |
34 #include "breakpad/src/common/linux/linux_libc_support.h" | 34 #include "breakpad/src/common/linux/linux_libc_support.h" |
35 #include "breakpad/src/common/memory.h" | 35 #include "breakpad/src/common/memory.h" |
36 #include "chrome/browser/crash_upload_list.h" | 36 #include "chrome/browser/crash_upload_list.h" |
37 #include "chrome/common/child_process_logging.h" | 37 #include "chrome/common/child_process_logging.h" |
38 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
39 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
40 #include "chrome/common/chrome_version_info_posix.h" | 40 #include "chrome/common/chrome_version_info_posix.h" |
41 #include "chrome/common/env_vars.h" | 41 #include "chrome/common/env_vars.h" |
42 #include "chrome/common/logging_chrome.h" | 42 #include "chrome/common/logging_chrome.h" |
43 #include "content/common/chrome_descriptors.h" | 43 #include "content/common/chrome_descriptors.h" |
| 44 |
| 45 #if defined(OS_ANDROID) |
| 46 #include <android/log.h> |
| 47 #include <sys/stat.h> |
| 48 #include "base/android/path_utils.h" |
| 49 #include "base/android/build_info.h" |
| 50 #include "third_party/lss/linux_syscall_support.h" |
| 51 #else |
44 #include "seccompsandbox/linux_syscall_support.h" | 52 #include "seccompsandbox/linux_syscall_support.h" |
| 53 #endif |
45 | 54 |
46 #ifndef PR_SET_PTRACER | 55 #ifndef PR_SET_PTRACER |
47 #define PR_SET_PTRACER 0x59616d61 | 56 #define PR_SET_PTRACER 0x59616d61 |
48 #endif | 57 #endif |
49 | 58 |
50 // Some versions of gcc are prone to warn about unused return values. In cases | 59 // Some versions of gcc are prone to warn about unused return values. In cases |
51 // where we either a) know the call cannot fail, or b) there is nothing we | 60 // where we either a) know the call cannot fail, or b) there is nothing we |
52 // can do when a call fails, we mark the return code as ignored. This avoids | 61 // can do when a call fails, we mark the return code as ignored. This avoids |
53 // spurious compiler warnings. | 62 // spurious compiler warnings. |
54 #define IGNORE_RET(x) do { if (x); } while (0) | 63 #define IGNORE_RET(x) do { if (x); } while (0) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 116 } |
108 | 117 |
109 // uint64_t version of my_itos() from | 118 // uint64_t version of my_itos() from |
110 // breakpad/src/common/linux/linux_libc_support.h. Convert a non-negative | 119 // breakpad/src/common/linux/linux_libc_support.h. Convert a non-negative |
111 // integer to a string (not null-terminated). | 120 // integer to a string (not null-terminated). |
112 static void my_uint64tos(char* output, uint64_t i, unsigned i_len) { | 121 static void my_uint64tos(char* output, uint64_t i, unsigned i_len) { |
113 for (unsigned index = i_len; index; --index, i /= 10) | 122 for (unsigned index = i_len; index; --index, i /= 10) |
114 output[index - 1] = '0' + (i % 10); | 123 output[index - 1] = '0' + (i % 10); |
115 } | 124 } |
116 | 125 |
| 126 static char* my_strncpy(char* dst, const char* src, size_t len) { |
| 127 int i = len; |
| 128 char* p = dst; |
| 129 if (!dst || !src) |
| 130 return dst; |
| 131 while (i != 0 && *src != '\0') { |
| 132 *p++ = *src++; |
| 133 i--; |
| 134 } |
| 135 while (i != 0) { |
| 136 *p++ = '\0'; |
| 137 i--; |
| 138 } |
| 139 return dst; |
| 140 } |
| 141 |
| 142 static char* my_strncat(char *dest, const char *src, size_t len) { |
| 143 char *ret = dest; |
| 144 while (*dest) |
| 145 dest++; |
| 146 while (len--) |
| 147 if (!(*dest++ = *src++)) |
| 148 return ret; |
| 149 *dest = 0; |
| 150 return ret; |
| 151 } |
| 152 |
117 namespace { | 153 namespace { |
118 | 154 |
119 // MIME substrings. | 155 // MIME substrings. |
120 static const char g_rn[] = "\r\n"; | 156 static const char g_rn[] = "\r\n"; |
121 static const char g_form_data_msg[] = "Content-Disposition: form-data; name=\""; | 157 static const char g_form_data_msg[] = "Content-Disposition: form-data; name=\""; |
122 static const char g_quote_msg[] = "\""; | 158 static const char g_quote_msg[] = "\""; |
123 static const char g_dashdash_msg[] = "--"; | 159 static const char g_dashdash_msg[] = "--"; |
124 static const char g_dump_msg[] = "upload_file_minidump\"; filename=\"dump\""; | 160 static const char g_dump_msg[] = "upload_file_minidump\"; filename=\"dump\""; |
125 static const char g_content_type_msg[] = | 161 static const char g_content_type_msg[] = |
126 "Content-Type: application/octet-stream"; | 162 "Content-Type: application/octet-stream"; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 size--; | 330 size--; |
295 } | 331 } |
296 AddItem(base, size); | 332 AddItem(base, size); |
297 } | 333 } |
298 | 334 |
299 void DumpProcess() { | 335 void DumpProcess() { |
300 if (g_breakpad) | 336 if (g_breakpad) |
301 g_breakpad->WriteMinidump(); | 337 g_breakpad->WriteMinidump(); |
302 } | 338 } |
303 | 339 |
| 340 size_t log(const char* buf, size_t nbytes) { |
| 341 #if defined(OS_ANDROID) |
| 342 return __android_log_write(ANDROID_LOG_WARN, "google-breakpad", buf); |
| 343 #else |
| 344 return sys_write(2, buf, nbytes) |
| 345 #endif |
| 346 } |
| 347 |
304 } // namespace | 348 } // namespace |
305 | 349 |
306 void HandleCrashDump(const BreakpadInfo& info) { | 350 void HandleCrashDump(const BreakpadInfo& info) { |
307 // WARNING: this code runs in a compromised context. It may not call into | 351 // WARNING: this code runs in a compromised context. It may not call into |
308 // libc nor allocate memory normally. | 352 // libc nor allocate memory normally. |
309 | 353 |
310 const int dumpfd = sys_open(info.filename, O_RDONLY, 0); | 354 const int dumpfd = sys_open(info.filename, O_RDONLY, 0); |
311 if (dumpfd < 0) { | 355 if (dumpfd < 0) { |
312 static const char msg[] = "Cannot upload crash dump: failed to open\n"; | 356 static const char msg[] = "Cannot upload crash dump: failed to open\n"; |
313 sys_write(2, msg, sizeof(msg)); | 357 log(msg, sizeof(msg)); |
314 return; | 358 return; |
315 } | 359 } |
| 360 #if defined(OS_ANDROID) |
| 361 struct stat st; |
| 362 if (fstat(dumpfd, &st) != 0) { |
| 363 #else |
316 struct kernel_stat st; | 364 struct kernel_stat st; |
317 if (sys_fstat(dumpfd, &st) != 0) { | 365 if (sys_fstat(dumpfd, &st) != 0) { |
| 366 #endif |
318 static const char msg[] = "Cannot upload crash dump: stat failed\n"; | 367 static const char msg[] = "Cannot upload crash dump: stat failed\n"; |
319 sys_write(2, msg, sizeof(msg)); | 368 log(msg, sizeof(msg)); |
320 IGNORE_RET(sys_close(dumpfd)); | 369 IGNORE_RET(sys_close(dumpfd)); |
321 return; | 370 return; |
322 } | 371 } |
323 | 372 |
324 google_breakpad::PageAllocator allocator; | 373 google_breakpad::PageAllocator allocator; |
325 | 374 |
326 uint8_t* dump_data = reinterpret_cast<uint8_t*>(allocator.Alloc(st.st_size)); | 375 uint8_t* dump_data = reinterpret_cast<uint8_t*>(allocator.Alloc(st.st_size)); |
327 if (!dump_data) { | 376 if (!dump_data) { |
328 static const char msg[] = "Cannot upload crash dump: cannot alloc\n"; | 377 static const char msg[] = "Cannot upload crash dump: cannot alloc\n"; |
329 sys_write(2, msg, sizeof(msg)); | 378 log(msg, sizeof(msg)); |
330 IGNORE_RET(sys_close(dumpfd)); | 379 IGNORE_RET(sys_close(dumpfd)); |
331 return; | 380 return; |
332 } | 381 } |
333 | 382 |
334 sys_read(dumpfd, dump_data, st.st_size); | 383 sys_read(dumpfd, dump_data, st.st_size); |
335 IGNORE_RET(sys_close(dumpfd)); | 384 IGNORE_RET(sys_close(dumpfd)); |
336 | 385 |
337 // We need to build a MIME block for uploading to the server. Since we are | 386 // We need to build a MIME block for uploading to the server. Since we are |
338 // going to fork and run wget, it needs to be written to a temp file. | 387 // going to fork and run wget, it needs to be written to a temp file. |
339 | 388 |
340 const int ufd = sys_open("/dev/urandom", O_RDONLY, 0); | 389 const int ufd = sys_open("/dev/urandom", O_RDONLY, 0); |
341 if (ufd < 0) { | 390 if (ufd < 0) { |
342 static const char msg[] = "Cannot upload crash dump because /dev/urandom" | 391 static const char msg[] = "Cannot upload crash dump because /dev/urandom" |
343 " is missing\n"; | 392 " is missing\n"; |
344 sys_write(2, msg, sizeof(msg) - 1); | 393 log(msg, sizeof(msg) - 1); |
345 return; | 394 return; |
346 } | 395 } |
347 | 396 |
348 static const char temp_file_template[] = | 397 static const char temp_file_template[] = |
349 "/tmp/chromium-upload-XXXXXXXXXXXXXXXX"; | 398 "/tmp/chromium-upload-XXXXXXXXXXXXXXXX"; |
350 char temp_file[sizeof(temp_file_template)]; | 399 char temp_file[sizeof(temp_file_template)]; |
351 int temp_file_fd = -1; | 400 int temp_file_fd = -1; |
352 if (info.upload) { | 401 if (info.upload) { |
353 memcpy(temp_file, temp_file_template, sizeof(temp_file_template)); | 402 memcpy(temp_file, temp_file_template, sizeof(temp_file_template)); |
354 | 403 |
355 for (unsigned i = 0; i < 10; ++i) { | 404 for (unsigned i = 0; i < 10; ++i) { |
356 uint64_t t; | 405 uint64_t t; |
357 sys_read(ufd, &t, sizeof(t)); | 406 sys_read(ufd, &t, sizeof(t)); |
358 write_uint64_hex(temp_file + sizeof(temp_file) - (16 + 1), t); | 407 write_uint64_hex(temp_file + sizeof(temp_file) - (16 + 1), t); |
359 | 408 |
360 temp_file_fd = sys_open(temp_file, O_WRONLY | O_CREAT | O_EXCL, 0600); | 409 temp_file_fd = sys_open(temp_file, O_WRONLY | O_CREAT | O_EXCL, 0600); |
361 if (temp_file_fd >= 0) | 410 if (temp_file_fd >= 0) |
362 break; | 411 break; |
363 } | 412 } |
364 | 413 |
365 if (temp_file_fd < 0) { | 414 if (temp_file_fd < 0) { |
366 static const char msg[] = "Failed to create temporary file in /tmp: " | 415 static const char msg[] = "Failed to create temporary file in /tmp: " |
367 "cannot upload crash dump\n"; | 416 "cannot upload crash dump\n"; |
368 sys_write(2, msg, sizeof(msg) - 1); | 417 log(msg, sizeof(msg) - 1); |
369 IGNORE_RET(sys_close(ufd)); | 418 IGNORE_RET(sys_close(ufd)); |
370 return; | 419 return; |
371 } | 420 } |
372 } else { | 421 } else { |
373 temp_file_fd = sys_open(info.filename, O_WRONLY, 0600); | 422 temp_file_fd = sys_open(info.filename, O_WRONLY, 0600); |
374 if (temp_file_fd < 0) { | 423 if (temp_file_fd < 0) { |
375 static const char msg[] = "Failed to save crash dump: failed to open\n"; | 424 static const char msg[] = "Failed to save crash dump: failed to open\n"; |
376 sys_write(2, msg, sizeof(msg) - 1); | 425 log(msg, sizeof(msg) - 1); |
377 IGNORE_RET(sys_close(ufd)); | 426 IGNORE_RET(sys_close(ufd)); |
378 return; | 427 return; |
379 } | 428 } |
380 } | 429 } |
381 | 430 |
382 // The MIME boundary is 28 hyphens, followed by a 64-bit nonce and a NUL. | 431 // The MIME boundary is 28 hyphens, followed by a 64-bit nonce and a NUL. |
383 char mime_boundary[28 + 16 + 1]; | 432 char mime_boundary[28 + 16 + 1]; |
384 my_memset(mime_boundary, '-', 28); | 433 my_memset(mime_boundary, '-', 28); |
385 uint64_t boundary_rand; | 434 uint64_t boundary_rand; |
386 sys_read(ufd, &boundary_rand, sizeof(boundary_rand)); | 435 sys_read(ufd, &boundary_rand, sizeof(boundary_rand)); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // --foo \r\n | 504 // --foo \r\n |
456 // BOUNDARY \r\n | 505 // BOUNDARY \r\n |
457 // | 506 // |
458 // Content-Disposition: form-data; name="dump"; filename="dump" \r\n | 507 // Content-Disposition: form-data; name="dump"; filename="dump" \r\n |
459 // Content-Type: application/octet-stream \r\n \r\n | 508 // Content-Type: application/octet-stream \r\n \r\n |
460 // <dump contents> | 509 // <dump contents> |
461 // \r\n BOUNDARY -- \r\n | 510 // \r\n BOUNDARY -- \r\n |
462 | 511 |
463 MimeWriter writer(temp_file_fd, mime_boundary); | 512 MimeWriter writer(temp_file_fd, mime_boundary); |
464 { | 513 { |
465 #if defined(OS_CHROMEOS) | 514 #if defined(OS_ANDROID) |
| 515 static const char chrome_product_msg[] = "Chrome_Android"; |
| 516 #elif defined(OS_CHROMEOS) |
466 static const char chrome_product_msg[] = "Chrome_ChromeOS"; | 517 static const char chrome_product_msg[] = "Chrome_ChromeOS"; |
467 #else // OS_LINUX | 518 #else // OS_LINUX |
468 static const char chrome_product_msg[] = "Chrome_Linux"; | 519 static const char chrome_product_msg[] = "Chrome_Linux"; |
469 #endif | 520 #endif |
| 521 |
| 522 #if defined (OS_ANDROID) |
| 523 base::android::BuildInfo* android_build_info = |
| 524 base::android::BuildInfo::GetInstance(); |
| 525 static const char* version_msg = |
| 526 android_build_info->package_version_code(); |
| 527 static const char android_build_id[] = "android_build_id"; |
| 528 static const char android_build_fp[] = "android_build_fp"; |
| 529 static const char device[] = "device"; |
| 530 static const char model[] = "model"; |
| 531 static const char brand[] = "brand"; |
| 532 #else |
470 static const char version_msg[] = PRODUCT_VERSION; | 533 static const char version_msg[] = PRODUCT_VERSION; |
| 534 #endif |
471 | 535 |
472 writer.AddBoundary(); | 536 writer.AddBoundary(); |
473 writer.AddPairString("prod", chrome_product_msg); | 537 writer.AddPairString("prod", chrome_product_msg); |
474 writer.AddBoundary(); | 538 writer.AddBoundary(); |
475 writer.AddPairString("ver", version_msg); | 539 writer.AddPairString("ver", version_msg); |
476 writer.AddBoundary(); | 540 writer.AddBoundary(); |
477 writer.AddPairString("guid", info.guid); | 541 writer.AddPairString("guid", info.guid); |
478 writer.AddBoundary(); | 542 writer.AddBoundary(); |
| 543 if (info.pid > 0) { |
| 544 uint64_t pid_str_len = my_uint64_len(info.pid); |
| 545 char* pid_buf = reinterpret_cast<char*>(allocator.Alloc(pid_str_len)); |
| 546 my_uint64tos(pid_buf, info.pid, pid_str_len); |
| 547 writer.AddPairString("pid", pid_buf); |
| 548 writer.AddBoundary(); |
| 549 } |
| 550 #if defined(OS_ANDROID) |
| 551 // Addtional MIME blocks are added for logging on Android devices. |
| 552 writer.AddPairString( |
| 553 android_build_id, android_build_info->android_build_id()); |
| 554 writer.AddBoundary(); |
| 555 writer.AddPairString( |
| 556 android_build_fp, android_build_info->android_build_fp()); |
| 557 writer.AddBoundary(); |
| 558 writer.AddPairString(device, android_build_info->device()); |
| 559 writer.AddBoundary(); |
| 560 writer.AddPairString(model, android_build_info->model()); |
| 561 writer.AddBoundary(); |
| 562 writer.AddPairString(brand, android_build_info->brand()); |
| 563 writer.AddBoundary(); |
| 564 #endif |
479 writer.Flush(); | 565 writer.Flush(); |
480 } | 566 } |
481 | 567 |
482 if (info.process_start_time > 0) { | 568 if (info.process_start_time > 0) { |
483 struct kernel_timeval tv; | 569 struct kernel_timeval tv; |
484 if (!sys_gettimeofday(&tv, NULL)) { | 570 if (!sys_gettimeofday(&tv, NULL)) { |
485 uint64_t time = kernel_timeval_to_ms(&tv); | 571 uint64_t time = kernel_timeval_to_ms(&tv); |
486 if (time > info.process_start_time) { | 572 if (time > info.process_start_time) { |
487 time -= info.process_start_time; | 573 time -= info.process_start_time; |
488 char time_str[21]; | 574 char time_str[21]; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 std::min(switches_len, kMaxSwitchLen), | 691 std::min(switches_len, kMaxSwitchLen), |
606 child_process_logging::kSwitchLen, | 692 child_process_logging::kSwitchLen, |
607 true /* Strip whitespace since switches are padded to kSwitchLen. */); | 693 true /* Strip whitespace since switches are padded to kSwitchLen. */); |
608 } | 694 } |
609 | 695 |
610 writer.AddFileDump(dump_data, st.st_size); | 696 writer.AddFileDump(dump_data, st.st_size); |
611 writer.AddEnd(); | 697 writer.AddEnd(); |
612 writer.Flush(); | 698 writer.Flush(); |
613 | 699 |
614 IGNORE_RET(sys_close(temp_file_fd)); | 700 IGNORE_RET(sys_close(temp_file_fd)); |
| 701 #if defined(OS_ANDROID) |
| 702 uint64_t pid_str_len = my_uint64_len(info.pid); |
| 703 char* pid_buf = reinterpret_cast<char*>(allocator.Alloc(pid_str_len)); |
| 704 my_uint64tos(pid_buf, info.pid, pid_str_len); |
| 705 |
| 706 static const char* output_msg = "Output crash dump file:"; |
| 707 log(output_msg, my_strlen(output_msg)); |
| 708 log(info.filename, info.filename_length); |
| 709 // -1 because we won't need the null terminator on the original filename. |
| 710 size_t done_filename_len = info.filename_length -1 + pid_str_len; |
| 711 char* done_filename = reinterpret_cast<char*>( |
| 712 allocator.Alloc(done_filename_len)); |
| 713 // Rename the file such that the pid is the suffix in order signal to other |
| 714 // processes that the minidump is complete. The advantage of using the pid as |
| 715 // the suffix is that it is trivial to associate the minidump with the |
| 716 // crashed process. |
| 717 // Finally, note strncpy prevents null terminators from |
| 718 // being copied. Pad the rest with 0's. |
| 719 my_strncpy(done_filename, info.filename, done_filename_len); |
| 720 // Append the suffix a null terminator should be added. |
| 721 my_strncat(done_filename, pid_buf, pid_str_len); |
| 722 // Rename the minidump file to signal that it is complete. |
| 723 if (rename(info.filename, done_filename)) { |
| 724 __android_log_write(ANDROID_LOG_WARN, "chromium", "Failed to rename:"); |
| 725 __android_log_write(ANDROID_LOG_WARN, "chromium", info.filename); |
| 726 __android_log_write(ANDROID_LOG_WARN, "chromium", "to"); |
| 727 __android_log_write(ANDROID_LOG_WARN, "chromium", done_filename); |
| 728 } |
| 729 #endif |
615 | 730 |
616 if (!info.upload) | 731 if (!info.upload) |
617 return; | 732 return; |
618 | 733 |
619 // The --header argument to wget looks like: | 734 // The --header argument to wget looks like: |
620 // --header=Content-Type: multipart/form-data; boundary=XYZ | 735 // --header=Content-Type: multipart/form-data; boundary=XYZ |
621 // where the boundary has two fewer leading '-' chars | 736 // where the boundary has two fewer leading '-' chars |
622 static const char header_msg[] = | 737 static const char header_msg[] = |
623 "--header=Content-Type: multipart/form-data; boundary="; | 738 "--header=Content-Type: multipart/form-data; boundary="; |
624 char* const header = reinterpret_cast<char*>(allocator.Alloc( | 739 char* const header = reinterpret_cast<char*>(allocator.Alloc( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 "--timeout=10", // Set a timeout so we don't hang forever. | 801 "--timeout=10", // Set a timeout so we don't hang forever. |
687 "--tries=1", // Don't retry if the upload fails. | 802 "--tries=1", // Don't retry if the upload fails. |
688 "-O", // output reply to fd 3 | 803 "-O", // output reply to fd 3 |
689 "/dev/fd/3", | 804 "/dev/fd/3", |
690 NULL, | 805 NULL, |
691 }; | 806 }; |
692 | 807 |
693 execve(kWgetBinary, const_cast<char**>(args), environ); | 808 execve(kWgetBinary, const_cast<char**>(args), environ); |
694 static const char msg[] = "Cannot upload crash dump: cannot exec " | 809 static const char msg[] = "Cannot upload crash dump: cannot exec " |
695 "/usr/bin/wget\n"; | 810 "/usr/bin/wget\n"; |
696 sys_write(2, msg, sizeof(msg) - 1); | 811 log(msg, sizeof(msg) - 1); |
697 sys__exit(1); | 812 sys__exit(1); |
698 } | 813 } |
699 | 814 |
700 // Helper process. | 815 // Helper process. |
701 if (wget_child > 0) { | 816 if (wget_child > 0) { |
702 IGNORE_RET(sys_close(fds[1])); | 817 IGNORE_RET(sys_close(fds[1])); |
703 char id_buf[17]; // Crash report IDs are expected to be 16 chars. | 818 char id_buf[17]; // Crash report IDs are expected to be 16 chars. |
704 ssize_t len = -1; | 819 ssize_t len = -1; |
705 // Wget should finish in about 10 seconds. Add a few more 500 ms | 820 // Wget should finish in about 10 seconds. Add a few more 500 ms |
706 // internals to account for process startup time. | 821 // internals to account for process startup time. |
707 for (size_t wait_count = 0; wait_count < 24; ++wait_count) { | 822 for (size_t wait_count = 0; wait_count < 24; ++wait_count) { |
708 struct kernel_pollfd poll_fd; | 823 struct kernel_pollfd poll_fd; |
709 poll_fd.fd = fds[0]; | 824 poll_fd.fd = fds[0]; |
710 poll_fd.events = POLLIN | POLLPRI | POLLERR; | 825 poll_fd.events = POLLIN | POLLPRI | POLLERR; |
711 int ret = sys_poll(&poll_fd, 1, 500); | 826 int ret = sys_poll(&poll_fd, 1, 500); |
712 if (ret < 0) { | 827 if (ret < 0) { |
713 // Error | 828 // Error |
714 break; | 829 break; |
715 } else if (ret > 0) { | 830 } else if (ret > 0) { |
716 // There is data to read. | 831 // There is data to read. |
717 len = HANDLE_EINTR(sys_read(fds[0], id_buf, sizeof(id_buf) - 1)); | 832 len = HANDLE_EINTR(sys_read(fds[0], id_buf, sizeof(id_buf) - 1)); |
718 break; | 833 break; |
719 } | 834 } |
720 // ret == 0 -> timed out, continue waiting. | 835 // ret == 0 -> timed out, continue waiting. |
721 } | 836 } |
722 if (len > 0) { | 837 if (len > 0) { |
723 // Write crash dump id to stderr. | 838 // Write crash dump id to stderr. |
724 id_buf[len] = 0; | 839 id_buf[len] = 0; |
725 static const char msg[] = "\nCrash dump id: "; | 840 static const char msg[] = "\nCrash dump id: "; |
726 sys_write(2, msg, sizeof(msg) - 1); | 841 log(msg, sizeof(msg) - 1); |
727 sys_write(2, id_buf, my_strlen(id_buf)); | 842 log(id_buf, my_strlen(id_buf)); |
728 sys_write(2, "\n", 1); | 843 log("\n", 1); |
729 | 844 |
730 // Write crash dump id to crash log as: seconds_since_epoch,crash_id | 845 // Write crash dump id to crash log as: seconds_since_epoch,crash_id |
731 struct kernel_timeval tv; | 846 struct kernel_timeval tv; |
732 if (g_crash_log_path && !sys_gettimeofday(&tv, NULL)) { | 847 if (g_crash_log_path && !sys_gettimeofday(&tv, NULL)) { |
733 uint64_t time = kernel_timeval_to_ms(&tv) / 1000; | 848 uint64_t time = kernel_timeval_to_ms(&tv) / 1000; |
734 char time_str[21]; | 849 char time_str[21]; |
735 const unsigned time_len = my_uint64_len(time); | 850 const unsigned time_len = my_uint64_len(time); |
736 my_uint64tos(time_str, time, time_len); | 851 my_uint64tos(time_str, time, time_len); |
737 | 852 |
738 int log_fd = sys_open(g_crash_log_path, | 853 int log_fd = sys_open(g_crash_log_path, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 info.process_type = "browser"; | 907 info.process_type = "browser"; |
793 info.process_type_length = 7; | 908 info.process_type_length = 7; |
794 info.crash_url = NULL; | 909 info.crash_url = NULL; |
795 info.crash_url_length = 0; | 910 info.crash_url_length = 0; |
796 info.guid = child_process_logging::g_client_id; | 911 info.guid = child_process_logging::g_client_id; |
797 info.guid_length = my_strlen(child_process_logging::g_client_id); | 912 info.guid_length = my_strlen(child_process_logging::g_client_id); |
798 info.distro = base::g_linux_distro; | 913 info.distro = base::g_linux_distro; |
799 info.distro_length = my_strlen(base::g_linux_distro); | 914 info.distro_length = my_strlen(base::g_linux_distro); |
800 info.upload = upload; | 915 info.upload = upload; |
801 info.process_start_time = g_process_start_time; | 916 info.process_start_time = g_process_start_time; |
| 917 info.pid = 0; |
802 HandleCrashDump(info); | 918 HandleCrashDump(info); |
803 return true; | 919 return true; |
804 } | 920 } |
805 | 921 |
806 // Wrapper function, do not add more code here. | 922 // Wrapper function, do not add more code here. |
807 static bool CrashDoneNoUpload(const char* dump_path, | 923 static bool CrashDoneNoUpload(const char* dump_path, |
808 const char* minidump_id, | 924 const char* minidump_id, |
809 void* context, | 925 void* context, |
810 bool succeeded) { | 926 bool succeeded) { |
811 return CrashDone(dump_path, minidump_id, false, succeeded); | 927 return CrashDone(dump_path, minidump_id, false, succeeded); |
812 } | 928 } |
813 | 929 |
| 930 #if !defined(OS_ANDROID) |
814 // Wrapper function, do not add more code here. | 931 // Wrapper function, do not add more code here. |
815 static bool CrashDoneUpload(const char* dump_path, | 932 static bool CrashDoneUpload(const char* dump_path, |
816 const char* minidump_id, | 933 const char* minidump_id, |
817 void* context, | 934 void* context, |
818 bool succeeded) { | 935 bool succeeded) { |
819 return CrashDone(dump_path, minidump_id, true, succeeded); | 936 return CrashDone(dump_path, minidump_id, true, succeeded); |
820 } | 937 } |
| 938 #endif |
821 | 939 |
822 void EnableCrashDumping(const bool unattended) { | 940 void EnableCrashDumping(const bool unattended) { |
823 g_is_crash_reporter_enabled = true; | 941 g_is_crash_reporter_enabled = true; |
824 | 942 |
825 FilePath tmp_path("/tmp"); | 943 FilePath tmp_path("/tmp"); |
826 PathService::Get(base::DIR_TEMP, &tmp_path); | 944 PathService::Get(base::DIR_TEMP, &tmp_path); |
827 | 945 |
828 FilePath dumps_path(tmp_path); | 946 FilePath dumps_path(tmp_path); |
829 if (PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) { | 947 if (PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) { |
830 FilePath logfile = | 948 FilePath logfile = |
831 dumps_path.AppendASCII(CrashUploadList::kReporterLogFilename); | 949 dumps_path.AppendASCII(CrashUploadList::kReporterLogFilename); |
832 std::string logfile_str = logfile.value(); | 950 std::string logfile_str = logfile.value(); |
833 const size_t crash_log_path_len = logfile_str.size() + 1; | 951 const size_t crash_log_path_len = logfile_str.size() + 1; |
834 g_crash_log_path = new char[crash_log_path_len]; | 952 g_crash_log_path = new char[crash_log_path_len]; |
835 strncpy(g_crash_log_path, logfile_str.c_str(), crash_log_path_len); | 953 strncpy(g_crash_log_path, logfile_str.c_str(), crash_log_path_len); |
836 } | 954 } |
837 | |
838 DCHECK(!g_breakpad); | 955 DCHECK(!g_breakpad); |
| 956 #if defined(OS_ANDROID) |
| 957 // In Android we never upload from native code. |
| 958 g_breakpad = new google_breakpad::ExceptionHandler( |
| 959 dumps_path.value().c_str(), |
| 960 NULL, |
| 961 CrashDoneNoUpload, |
| 962 NULL, |
| 963 true /* install handlers */); |
| 964 #else |
839 if (unattended) { | 965 if (unattended) { |
840 g_breakpad = new google_breakpad::ExceptionHandler( | 966 g_breakpad = new google_breakpad::ExceptionHandler( |
841 dumps_path.value().c_str(), | 967 dumps_path.value().c_str(), |
842 NULL, | 968 NULL, |
843 CrashDoneNoUpload, | 969 CrashDoneNoUpload, |
844 NULL, | 970 NULL, |
845 true /* install handlers */); | 971 true /* install handlers */); |
846 } else { | 972 } else { |
847 g_breakpad = new google_breakpad::ExceptionHandler( | 973 g_breakpad = new google_breakpad::ExceptionHandler( |
848 tmp_path.value().c_str(), | 974 tmp_path.value().c_str(), |
849 NULL, | 975 NULL, |
850 CrashDoneUpload, | 976 CrashDoneUpload, |
851 NULL, | 977 NULL, |
852 true /* install handlers */); | 978 true /* install handlers */); |
853 } | 979 } |
| 980 #endif |
854 } | 981 } |
855 | 982 |
856 // Non-Browser = Extension, Gpu, Plugins, Ppapi and Renderer | 983 // Non-Browser = Extension, Gpu, Plugins, Ppapi and Renderer |
857 static bool NonBrowserCrashHandler(const void* crash_context, | 984 static bool NonBrowserCrashHandler(const void* crash_context, |
858 size_t crash_context_size, | 985 size_t crash_context_size, |
859 void* context) { | 986 void* context) { |
860 const int fd = reinterpret_cast<intptr_t>(context); | 987 const int fd = reinterpret_cast<intptr_t>(context); |
861 int fds[2] = { -1, -1 }; | 988 int fds[2] = { -1, -1 }; |
862 if (sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { | 989 if (sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { |
863 static const char msg[] = "Failed to create socket for crash dumping.\n"; | 990 static const char msg[] = "Failed to create socket for crash dumping.\n"; |
864 sys_write(2, msg, sizeof(msg)-1); | 991 log(msg, sizeof(msg)-1); |
865 return false; | 992 return false; |
866 } | 993 } |
867 | 994 |
868 // On kernels with ptrace protection, e.g. Ubuntu 10.10+, the browser cannot | 995 // On kernels with ptrace protection, e.g. Ubuntu 10.10+, the browser cannot |
869 // ptrace this crashing process and crash dumping will fail. When using the | 996 // ptrace this crashing process and crash dumping will fail. When using the |
870 // SUID sandbox, this crashing process is likely to be in its own PID | 997 // SUID sandbox, this crashing process is likely to be in its own PID |
871 // namespace, and thus there is no way to permit only the browser process to | 998 // namespace, and thus there is no way to permit only the browser process to |
872 // ptrace it. | 999 // ptrace it. |
873 // The workaround is to allow all processes to ptrace this process if we | 1000 // The workaround is to allow all processes to ptrace this process if we |
874 // reach this point, by passing -1 as the allowed PID. However, support for | 1001 // reach this point, by passing -1 as the allowed PID. However, support for |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 | 1056 |
930 struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); | 1057 struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); |
931 hdr->cmsg_level = SOL_SOCKET; | 1058 hdr->cmsg_level = SOL_SOCKET; |
932 hdr->cmsg_type = SCM_RIGHTS; | 1059 hdr->cmsg_type = SCM_RIGHTS; |
933 hdr->cmsg_len = kControlMsgLenSize; | 1060 hdr->cmsg_len = kControlMsgLenSize; |
934 ((int*) CMSG_DATA(hdr))[0] = fds[0]; | 1061 ((int*) CMSG_DATA(hdr))[0] = fds[0]; |
935 ((int*) CMSG_DATA(hdr))[1] = fds[1]; | 1062 ((int*) CMSG_DATA(hdr))[1] = fds[1]; |
936 | 1063 |
937 if (HANDLE_EINTR(sys_sendmsg(fd, &msg, 0)) < 0) { | 1064 if (HANDLE_EINTR(sys_sendmsg(fd, &msg, 0)) < 0) { |
938 static const char errmsg[] = "Failed to tell parent about crash.\n"; | 1065 static const char errmsg[] = "Failed to tell parent about crash.\n"; |
939 sys_write(2, errmsg, sizeof(errmsg)-1); | 1066 log(errmsg, sizeof(errmsg)-1); |
940 IGNORE_RET(sys_close(fds[1])); | 1067 IGNORE_RET(sys_close(fds[1])); |
941 return false; | 1068 return false; |
942 } | 1069 } |
943 IGNORE_RET(sys_close(fds[1])); | 1070 IGNORE_RET(sys_close(fds[1])); |
944 | 1071 |
945 if (HANDLE_EINTR(sys_read(fds[0], &b, 1)) != 1) { | 1072 if (HANDLE_EINTR(sys_read(fds[0], &b, 1)) != 1) { |
946 static const char errmsg[] = "Parent failed to complete crash dump.\n"; | 1073 static const char errmsg[] = "Parent failed to complete crash dump.\n"; |
947 sys_write(2, errmsg, sizeof(errmsg)-1); | 1074 log(errmsg, sizeof(errmsg)-1); |
948 } | 1075 } |
949 | 1076 |
950 return true; | 1077 return true; |
951 } | 1078 } |
952 | 1079 |
953 void EnableNonBrowserCrashDumping() { | 1080 void EnableNonBrowserCrashDumping() { |
954 const int fd = base::GlobalDescriptors::GetInstance()->Get(kCrashDumpSignal); | 1081 const int fd = base::GlobalDescriptors::GetInstance()->Get(kCrashDumpSignal); |
955 g_is_crash_reporter_enabled = true; | 1082 g_is_crash_reporter_enabled = true; |
956 // We deliberately leak this object. | 1083 // We deliberately leak this object. |
957 DCHECK(!g_breakpad); | 1084 DCHECK(!g_breakpad); |
958 g_breakpad = new google_breakpad::ExceptionHandler( | 1085 g_breakpad = new google_breakpad::ExceptionHandler( |
959 "" /* unused */, NULL, NULL, reinterpret_cast<void*>(fd), true); | 1086 "" /* unused */, NULL, NULL, reinterpret_cast<void*>(fd), true); |
960 g_breakpad->set_crash_handler(NonBrowserCrashHandler); | 1087 g_breakpad->set_crash_handler(NonBrowserCrashHandler); |
961 } | 1088 } |
962 | 1089 |
963 void InitCrashReporter() { | 1090 void InitCrashReporter() { |
| 1091 #if defined(OS_ANDROID) |
| 1092 // This will guarantee that the BuildInfo has been initialized and subsequent |
| 1093 // calls will not require memory allocation. |
| 1094 base::android::BuildInfo::GetInstance(); |
| 1095 #endif |
964 // Determine the process type and take appropriate action. | 1096 // Determine the process type and take appropriate action. |
965 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 1097 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
966 if (parsed_command_line.HasSwitch(switches::kDisableBreakpad)) | 1098 if (parsed_command_line.HasSwitch(switches::kDisableBreakpad)) |
967 return; | 1099 return; |
968 | 1100 |
969 const std::string process_type = | 1101 const std::string process_type = |
970 parsed_command_line.GetSwitchValueASCII(switches::kProcessType); | 1102 parsed_command_line.GetSwitchValueASCII(switches::kProcessType); |
971 if (process_type.empty()) { | 1103 if (process_type.empty()) { |
972 EnableCrashDumping(getenv(env_vars::kHeadless) != NULL); | 1104 EnableCrashDumping(getenv(env_vars::kHeadless) != NULL); |
973 } else if (process_type == switches::kRendererProcess || | 1105 } else if (process_type == switches::kRendererProcess || |
974 process_type == switches::kPluginProcess || | 1106 process_type == switches::kPluginProcess || |
975 process_type == switches::kPpapiPluginProcess || | 1107 process_type == switches::kPpapiPluginProcess || |
976 process_type == switches::kZygoteProcess || | 1108 process_type == switches::kZygoteProcess || |
977 process_type == switches::kGpuProcess) { | 1109 process_type == switches::kGpuProcess) { |
| 1110 #if defined(OS_ANDROID) |
| 1111 child_process_logging::SetClientId("Android"); |
| 1112 #endif |
978 // We might be chrooted in a zygote or renderer process so we cannot call | 1113 // We might be chrooted in a zygote or renderer process so we cannot call |
979 // GetCollectStatsConsent because that needs access the the user's home | 1114 // GetCollectStatsConsent because that needs access the the user's home |
980 // dir. Instead, we set a command line flag for these processes. | 1115 // dir. Instead, we set a command line flag for these processes. |
981 // Even though plugins are not chrooted, we share the same code path for | 1116 // Even though plugins are not chrooted, we share the same code path for |
982 // simplicity. | 1117 // simplicity. |
983 if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter)) | 1118 if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter)) |
984 return; | 1119 return; |
985 // Get the guid and linux distro from the command line switch. | 1120 // Get the guid and linux distro from the command line switch. |
986 std::string switch_value = | 1121 std::string switch_value = |
987 parsed_command_line.GetSwitchValueASCII(switches::kEnableCrashReporter); | 1122 parsed_command_line.GetSwitchValueASCII(switches::kEnableCrashReporter); |
(...skipping 13 matching lines...) Expand all Loading... |
1001 g_process_start_time = timeval_to_ms(&tv); | 1136 g_process_start_time = timeval_to_ms(&tv); |
1002 else | 1137 else |
1003 g_process_start_time = 0; | 1138 g_process_start_time = 0; |
1004 | 1139 |
1005 logging::SetDumpWithoutCrashingFunction(&DumpProcess); | 1140 logging::SetDumpWithoutCrashingFunction(&DumpProcess); |
1006 } | 1141 } |
1007 | 1142 |
1008 bool IsCrashReporterEnabled() { | 1143 bool IsCrashReporterEnabled() { |
1009 return g_is_crash_reporter_enabled; | 1144 return g_is_crash_reporter_enabled; |
1010 } | 1145 } |
OLD | NEW |