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_linux.h" |
10 | 10 |
(...skipping 23 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 const base::android::BuildInfo* android_build_info = |
| 524 base::android::BuildInfo::GetInstance(); |
| 525 static const char* version_msg = android_build_info->package_version_code; |
| 526 static const char android_build_id[] = "android_build_id"; |
| 527 static const char android_build_fp[] = "android_build_fp"; |
| 528 static const char device[] = "device"; |
| 529 static const char model[] = "model"; |
| 530 static const char brand[] = "brand"; |
| 531 #else |
470 static const char version_msg[] = PRODUCT_VERSION; | 532 static const char version_msg[] = PRODUCT_VERSION; |
| 533 #endif |
471 | 534 |
472 writer.AddBoundary(); | 535 writer.AddBoundary(); |
473 writer.AddPairString("prod", chrome_product_msg); | 536 writer.AddPairString("prod", chrome_product_msg); |
474 writer.AddBoundary(); | 537 writer.AddBoundary(); |
475 writer.AddPairString("ver", version_msg); | 538 writer.AddPairString("ver", version_msg); |
476 writer.AddBoundary(); | 539 writer.AddBoundary(); |
477 writer.AddPairString("guid", info.guid); | 540 writer.AddPairString("guid", info.guid); |
478 writer.AddBoundary(); | 541 writer.AddBoundary(); |
| 542 if (info.pid > 0) { |
| 543 uint64_t pid_str_len = my_uint64_len(info.pid); |
| 544 char* pid_buf = reinterpret_cast<char*>(allocator.Alloc(pid_str_len)); |
| 545 my_uint64tos(pid_buf, info.pid, pid_str_len); |
| 546 writer.AddPairString("pid", pid_buf); |
| 547 writer.AddBoundary(); |
| 548 } |
| 549 #if defined(OS_ANDROID) |
| 550 // Addtional MIME blocks are added for logging on Android devices. |
| 551 writer.AddPairString( |
| 552 android_build_id, android_build_info->android_build_id); |
| 553 writer.AddBoundary(); |
| 554 writer.AddPairString( |
| 555 android_build_fp, android_build_info->android_build_fp); |
| 556 writer.AddBoundary(); |
| 557 writer.AddPairString(device, android_build_info->device); |
| 558 writer.AddBoundary(); |
| 559 writer.AddPairString(model, android_build_info->model); |
| 560 writer.AddBoundary(); |
| 561 writer.AddPairString(brand, android_build_info->brand); |
| 562 writer.AddBoundary(); |
| 563 #endif |
479 writer.Flush(); | 564 writer.Flush(); |
480 } | 565 } |
481 | 566 |
482 if (info.process_start_time > 0) { | 567 if (info.process_start_time > 0) { |
483 struct kernel_timeval tv; | 568 struct kernel_timeval tv; |
484 if (!sys_gettimeofday(&tv, NULL)) { | 569 if (!sys_gettimeofday(&tv, NULL)) { |
485 uint64_t time = kernel_timeval_to_ms(&tv); | 570 uint64_t time = kernel_timeval_to_ms(&tv); |
486 if (time > info.process_start_time) { | 571 if (time > info.process_start_time) { |
487 time -= info.process_start_time; | 572 time -= info.process_start_time; |
488 char time_str[21]; | 573 char time_str[21]; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 std::min(switches_len, kMaxSwitchLen), | 690 std::min(switches_len, kMaxSwitchLen), |
606 child_process_logging::kSwitchLen, | 691 child_process_logging::kSwitchLen, |
607 true /* Strip whitespace since switches are padded to kSwitchLen. */); | 692 true /* Strip whitespace since switches are padded to kSwitchLen. */); |
608 } | 693 } |
609 | 694 |
610 writer.AddFileDump(dump_data, st.st_size); | 695 writer.AddFileDump(dump_data, st.st_size); |
611 writer.AddEnd(); | 696 writer.AddEnd(); |
612 writer.Flush(); | 697 writer.Flush(); |
613 | 698 |
614 IGNORE_RET(sys_close(temp_file_fd)); | 699 IGNORE_RET(sys_close(temp_file_fd)); |
| 700 #if defined(OS_ANDROID) |
| 701 uint64_t pid_str_len = my_uint64_len(info.pid); |
| 702 char* pid_buf = reinterpret_cast<char*>(allocator.Alloc(pid_str_len)); |
| 703 my_uint64tos(pid_buf, info.pid, pid_str_len); |
| 704 |
| 705 static const char* output_msg = "Output crash dump file:"; |
| 706 log(output_msg, my_strlen(output_msg)); |
| 707 log(info.filename, info.filename_length); |
| 708 // -1 because we won't need the null terminator on the original filename. |
| 709 size_t done_filename_len = info.filename_length -1 + pid_str_len; |
| 710 char* done_filename = reinterpret_cast<char*>( |
| 711 allocator.Alloc(done_filename_len)); |
| 712 // Rename the file such that the pid is the suffix in order signal to other |
| 713 // processes that the minidump is complete. The advantage of using the pid as |
| 714 // the suffix is that it is trivial to associate the minidump with the |
| 715 // crashed process. |
| 716 // Finally, note strncpy prevents null terminators from |
| 717 // being copied. Pad the rest with 0's. |
| 718 my_strncpy(done_filename, info.filename, done_filename_len); |
| 719 // Append the suffix a null terminator should be added. |
| 720 my_strncat(done_filename, pid_buf, pid_str_len); |
| 721 // Rename the minidump file to signal that it is complete. |
| 722 if (rename(info.filename, done_filename)) { |
| 723 __android_log_write(ANDROID_LOG_WARN, "chromium", "Failed to rename:"); |
| 724 __android_log_write(ANDROID_LOG_WARN, "chromium", info.filename); |
| 725 __android_log_write(ANDROID_LOG_WARN, "chromium", "to"); |
| 726 __android_log_write(ANDROID_LOG_WARN, "chromium", done_filename); |
| 727 } |
| 728 #endif |
615 | 729 |
616 if (!info.upload) | 730 if (!info.upload) |
617 return; | 731 return; |
618 | 732 |
619 // The --header argument to wget looks like: | 733 // The --header argument to wget looks like: |
620 // --header=Content-Type: multipart/form-data; boundary=XYZ | 734 // --header=Content-Type: multipart/form-data; boundary=XYZ |
621 // where the boundary has two fewer leading '-' chars | 735 // where the boundary has two fewer leading '-' chars |
622 static const char header_msg[] = | 736 static const char header_msg[] = |
623 "--header=Content-Type: multipart/form-data; boundary="; | 737 "--header=Content-Type: multipart/form-data; boundary="; |
624 char* const header = reinterpret_cast<char*>(allocator.Alloc( | 738 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. | 800 "--timeout=10", // Set a timeout so we don't hang forever. |
687 "--tries=1", // Don't retry if the upload fails. | 801 "--tries=1", // Don't retry if the upload fails. |
688 "-O", // output reply to fd 3 | 802 "-O", // output reply to fd 3 |
689 "/dev/fd/3", | 803 "/dev/fd/3", |
690 NULL, | 804 NULL, |
691 }; | 805 }; |
692 | 806 |
693 execve(kWgetBinary, const_cast<char**>(args), environ); | 807 execve(kWgetBinary, const_cast<char**>(args), environ); |
694 static const char msg[] = "Cannot upload crash dump: cannot exec " | 808 static const char msg[] = "Cannot upload crash dump: cannot exec " |
695 "/usr/bin/wget\n"; | 809 "/usr/bin/wget\n"; |
696 sys_write(2, msg, sizeof(msg) - 1); | 810 log(msg, sizeof(msg) - 1); |
697 sys__exit(1); | 811 sys__exit(1); |
698 } | 812 } |
699 | 813 |
700 // Helper process. | 814 // Helper process. |
701 if (wget_child > 0) { | 815 if (wget_child > 0) { |
702 IGNORE_RET(sys_close(fds[1])); | 816 IGNORE_RET(sys_close(fds[1])); |
703 char id_buf[17]; // Crash report IDs are expected to be 16 chars. | 817 char id_buf[17]; // Crash report IDs are expected to be 16 chars. |
704 ssize_t len = -1; | 818 ssize_t len = -1; |
705 // Wget should finish in about 10 seconds. Add a few more 500 ms | 819 // Wget should finish in about 10 seconds. Add a few more 500 ms |
706 // internals to account for process startup time. | 820 // internals to account for process startup time. |
707 for (size_t wait_count = 0; wait_count < 24; ++wait_count) { | 821 for (size_t wait_count = 0; wait_count < 24; ++wait_count) { |
708 struct kernel_pollfd poll_fd; | 822 struct kernel_pollfd poll_fd; |
709 poll_fd.fd = fds[0]; | 823 poll_fd.fd = fds[0]; |
710 poll_fd.events = POLLIN | POLLPRI | POLLERR; | 824 poll_fd.events = POLLIN | POLLPRI | POLLERR; |
711 int ret = sys_poll(&poll_fd, 1, 500); | 825 int ret = sys_poll(&poll_fd, 1, 500); |
712 if (ret < 0) { | 826 if (ret < 0) { |
713 // Error | 827 // Error |
714 break; | 828 break; |
715 } else if (ret > 0) { | 829 } else if (ret > 0) { |
716 // There is data to read. | 830 // There is data to read. |
717 len = HANDLE_EINTR(sys_read(fds[0], id_buf, sizeof(id_buf) - 1)); | 831 len = HANDLE_EINTR(sys_read(fds[0], id_buf, sizeof(id_buf) - 1)); |
718 break; | 832 break; |
719 } | 833 } |
720 // ret == 0 -> timed out, continue waiting. | 834 // ret == 0 -> timed out, continue waiting. |
721 } | 835 } |
722 if (len > 0) { | 836 if (len > 0) { |
723 // Write crash dump id to stderr. | 837 // Write crash dump id to stderr. |
724 id_buf[len] = 0; | 838 id_buf[len] = 0; |
725 static const char msg[] = "\nCrash dump id: "; | 839 static const char msg[] = "\nCrash dump id: "; |
726 sys_write(2, msg, sizeof(msg) - 1); | 840 log(msg, sizeof(msg) - 1); |
727 sys_write(2, id_buf, my_strlen(id_buf)); | 841 log(id_buf, my_strlen(id_buf)); |
728 sys_write(2, "\n", 1); | 842 log("\n", 1); |
729 | 843 |
730 // Write crash dump id to crash log as: seconds_since_epoch,crash_id | 844 // Write crash dump id to crash log as: seconds_since_epoch,crash_id |
731 struct kernel_timeval tv; | 845 struct kernel_timeval tv; |
732 if (g_crash_log_path && !sys_gettimeofday(&tv, NULL)) { | 846 if (g_crash_log_path && !sys_gettimeofday(&tv, NULL)) { |
733 uint64_t time = kernel_timeval_to_ms(&tv) / 1000; | 847 uint64_t time = kernel_timeval_to_ms(&tv) / 1000; |
734 char time_str[21]; | 848 char time_str[21]; |
735 const unsigned time_len = my_uint64_len(time); | 849 const unsigned time_len = my_uint64_len(time); |
736 my_uint64tos(time_str, time, time_len); | 850 my_uint64tos(time_str, time, time_len); |
737 | 851 |
738 int log_fd = sys_open(g_crash_log_path, | 852 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"; | 906 info.process_type = "browser"; |
793 info.process_type_length = 7; | 907 info.process_type_length = 7; |
794 info.crash_url = NULL; | 908 info.crash_url = NULL; |
795 info.crash_url_length = 0; | 909 info.crash_url_length = 0; |
796 info.guid = child_process_logging::g_client_id; | 910 info.guid = child_process_logging::g_client_id; |
797 info.guid_length = my_strlen(child_process_logging::g_client_id); | 911 info.guid_length = my_strlen(child_process_logging::g_client_id); |
798 info.distro = base::g_linux_distro; | 912 info.distro = base::g_linux_distro; |
799 info.distro_length = my_strlen(base::g_linux_distro); | 913 info.distro_length = my_strlen(base::g_linux_distro); |
800 info.upload = upload; | 914 info.upload = upload; |
801 info.process_start_time = g_process_start_time; | 915 info.process_start_time = g_process_start_time; |
| 916 info.pid = 0; |
802 HandleCrashDump(info); | 917 HandleCrashDump(info); |
803 return true; | 918 return true; |
804 } | 919 } |
805 | 920 |
806 // Wrapper function, do not add more code here. | 921 // Wrapper function, do not add more code here. |
807 static bool CrashDoneNoUpload(const char* dump_path, | 922 static bool CrashDoneNoUpload(const char* dump_path, |
808 const char* minidump_id, | 923 const char* minidump_id, |
809 void* context, | 924 void* context, |
810 bool succeeded) { | 925 bool succeeded) { |
811 return CrashDone(dump_path, minidump_id, false, succeeded); | 926 return CrashDone(dump_path, minidump_id, false, succeeded); |
812 } | 927 } |
813 | 928 |
| 929 #if !defined(OS_ANDROID) |
814 // Wrapper function, do not add more code here. | 930 // Wrapper function, do not add more code here. |
815 static bool CrashDoneUpload(const char* dump_path, | 931 static bool CrashDoneUpload(const char* dump_path, |
816 const char* minidump_id, | 932 const char* minidump_id, |
817 void* context, | 933 void* context, |
818 bool succeeded) { | 934 bool succeeded) { |
819 return CrashDone(dump_path, minidump_id, true, succeeded); | 935 return CrashDone(dump_path, minidump_id, true, succeeded); |
820 } | 936 } |
| 937 #endif |
821 | 938 |
822 void EnableCrashDumping(const bool unattended) { | 939 void EnableCrashDumping(const bool unattended) { |
823 g_is_crash_reporter_enabled = true; | 940 g_is_crash_reporter_enabled = true; |
824 | 941 |
825 FilePath tmp_path("/tmp"); | 942 FilePath tmp_path("/tmp"); |
826 PathService::Get(base::DIR_TEMP, &tmp_path); | 943 PathService::Get(base::DIR_TEMP, &tmp_path); |
827 | 944 |
828 FilePath dumps_path(tmp_path); | 945 FilePath dumps_path(tmp_path); |
829 if (PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) { | 946 if (PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) { |
830 FilePath logfile = | 947 FilePath logfile = |
831 dumps_path.AppendASCII(CrashUploadList::kReporterLogFilename); | 948 dumps_path.AppendASCII(CrashUploadList::kReporterLogFilename); |
832 std::string logfile_str = logfile.value(); | 949 std::string logfile_str = logfile.value(); |
833 const size_t crash_log_path_len = logfile_str.size() + 1; | 950 const size_t crash_log_path_len = logfile_str.size() + 1; |
834 g_crash_log_path = new char[crash_log_path_len]; | 951 g_crash_log_path = new char[crash_log_path_len]; |
835 strncpy(g_crash_log_path, logfile_str.c_str(), crash_log_path_len); | 952 strncpy(g_crash_log_path, logfile_str.c_str(), crash_log_path_len); |
836 } | 953 } |
837 | |
838 DCHECK(!g_breakpad); | 954 DCHECK(!g_breakpad); |
| 955 #if defined(OS_ANDROID) |
| 956 // In Android we never upload from native code. |
| 957 g_breakpad = new google_breakpad::ExceptionHandler( |
| 958 dumps_path.value().c_str(), |
| 959 NULL, |
| 960 CrashDoneNoUpload, |
| 961 NULL, |
| 962 true /* install handlers */); |
| 963 #else |
839 if (unattended) { | 964 if (unattended) { |
840 g_breakpad = new google_breakpad::ExceptionHandler( | 965 g_breakpad = new google_breakpad::ExceptionHandler( |
841 dumps_path.value().c_str(), | 966 dumps_path.value().c_str(), |
842 NULL, | 967 NULL, |
843 CrashDoneNoUpload, | 968 CrashDoneNoUpload, |
844 NULL, | 969 NULL, |
845 true /* install handlers */); | 970 true /* install handlers */); |
846 } else { | 971 } else { |
847 g_breakpad = new google_breakpad::ExceptionHandler( | 972 g_breakpad = new google_breakpad::ExceptionHandler( |
848 tmp_path.value().c_str(), | 973 tmp_path.value().c_str(), |
849 NULL, | 974 NULL, |
850 CrashDoneUpload, | 975 CrashDoneUpload, |
851 NULL, | 976 NULL, |
852 true /* install handlers */); | 977 true /* install handlers */); |
853 } | 978 } |
| 979 #endif |
854 } | 980 } |
855 | 981 |
856 // Non-Browser = Extension, Gpu, Plugins, Ppapi and Renderer | 982 // Non-Browser = Extension, Gpu, Plugins, Ppapi and Renderer |
857 static bool NonBrowserCrashHandler(const void* crash_context, | 983 static bool NonBrowserCrashHandler(const void* crash_context, |
858 size_t crash_context_size, | 984 size_t crash_context_size, |
859 void* context) { | 985 void* context) { |
860 const int fd = reinterpret_cast<intptr_t>(context); | 986 const int fd = reinterpret_cast<intptr_t>(context); |
861 int fds[2] = { -1, -1 }; | 987 int fds[2] = { -1, -1 }; |
862 if (sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { | 988 if (sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { |
863 static const char msg[] = "Failed to create socket for crash dumping.\n"; | 989 static const char msg[] = "Failed to create socket for crash dumping.\n"; |
864 sys_write(2, msg, sizeof(msg)-1); | 990 log(msg, sizeof(msg)-1); |
865 return false; | 991 return false; |
866 } | 992 } |
867 | 993 |
868 // On kernels with ptrace protection, e.g. Ubuntu 10.10+, the browser cannot | 994 // 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 | 995 // 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 | 996 // 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 | 997 // namespace, and thus there is no way to permit only the browser process to |
872 // ptrace it. | 998 // ptrace it. |
873 // The workaround is to allow all processes to ptrace this process if we | 999 // 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 | 1000 // 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 | 1055 |
930 struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); | 1056 struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); |
931 hdr->cmsg_level = SOL_SOCKET; | 1057 hdr->cmsg_level = SOL_SOCKET; |
932 hdr->cmsg_type = SCM_RIGHTS; | 1058 hdr->cmsg_type = SCM_RIGHTS; |
933 hdr->cmsg_len = kControlMsgLenSize; | 1059 hdr->cmsg_len = kControlMsgLenSize; |
934 ((int*) CMSG_DATA(hdr))[0] = fds[0]; | 1060 ((int*) CMSG_DATA(hdr))[0] = fds[0]; |
935 ((int*) CMSG_DATA(hdr))[1] = fds[1]; | 1061 ((int*) CMSG_DATA(hdr))[1] = fds[1]; |
936 | 1062 |
937 if (HANDLE_EINTR(sys_sendmsg(fd, &msg, 0)) < 0) { | 1063 if (HANDLE_EINTR(sys_sendmsg(fd, &msg, 0)) < 0) { |
938 static const char errmsg[] = "Failed to tell parent about crash.\n"; | 1064 static const char errmsg[] = "Failed to tell parent about crash.\n"; |
939 sys_write(2, errmsg, sizeof(errmsg)-1); | 1065 log(errmsg, sizeof(errmsg)-1); |
940 IGNORE_RET(sys_close(fds[1])); | 1066 IGNORE_RET(sys_close(fds[1])); |
941 return false; | 1067 return false; |
942 } | 1068 } |
943 IGNORE_RET(sys_close(fds[1])); | 1069 IGNORE_RET(sys_close(fds[1])); |
944 | 1070 |
945 if (HANDLE_EINTR(sys_read(fds[0], &b, 1)) != 1) { | 1071 if (HANDLE_EINTR(sys_read(fds[0], &b, 1)) != 1) { |
946 static const char errmsg[] = "Parent failed to complete crash dump.\n"; | 1072 static const char errmsg[] = "Parent failed to complete crash dump.\n"; |
947 sys_write(2, errmsg, sizeof(errmsg)-1); | 1073 log(errmsg, sizeof(errmsg)-1); |
948 } | 1074 } |
949 | 1075 |
950 return true; | 1076 return true; |
951 } | 1077 } |
952 | 1078 |
953 void EnableNonBrowserCrashDumping() { | 1079 void EnableNonBrowserCrashDumping() { |
954 const int fd = base::GlobalDescriptors::GetInstance()->Get(kCrashDumpSignal); | 1080 const int fd = base::GlobalDescriptors::GetInstance()->Get(kCrashDumpSignal); |
955 g_is_crash_reporter_enabled = true; | 1081 g_is_crash_reporter_enabled = true; |
956 // We deliberately leak this object. | 1082 // We deliberately leak this object. |
957 DCHECK(!g_breakpad); | 1083 DCHECK(!g_breakpad); |
958 g_breakpad = new google_breakpad::ExceptionHandler( | 1084 g_breakpad = new google_breakpad::ExceptionHandler( |
959 "" /* unused */, NULL, NULL, reinterpret_cast<void*>(fd), true); | 1085 "" /* unused */, NULL, NULL, reinterpret_cast<void*>(fd), true); |
960 g_breakpad->set_crash_handler(NonBrowserCrashHandler); | 1086 g_breakpad->set_crash_handler(NonBrowserCrashHandler); |
961 } | 1087 } |
962 | 1088 |
963 void InitCrashReporter() { | 1089 void InitCrashReporter() { |
| 1090 #if defined(OS_ANDROID) |
| 1091 // This will guarantee that the BuildInfo has been initialized and subsequent |
| 1092 // calls will not require memory allocation. |
| 1093 base::android::BuildInfo::GetInstance(); |
| 1094 #endif |
964 // Determine the process type and take appropriate action. | 1095 // Determine the process type and take appropriate action. |
965 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 1096 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
966 if (parsed_command_line.HasSwitch(switches::kDisableBreakpad)) | 1097 if (parsed_command_line.HasSwitch(switches::kDisableBreakpad)) |
967 return; | 1098 return; |
968 | 1099 |
969 const std::string process_type = | 1100 const std::string process_type = |
970 parsed_command_line.GetSwitchValueASCII(switches::kProcessType); | 1101 parsed_command_line.GetSwitchValueASCII(switches::kProcessType); |
971 if (process_type.empty()) { | 1102 if (process_type.empty()) { |
972 EnableCrashDumping(getenv(env_vars::kHeadless) != NULL); | 1103 EnableCrashDumping(getenv(env_vars::kHeadless) != NULL); |
973 } else if (process_type == switches::kRendererProcess || | 1104 } else if (process_type == switches::kRendererProcess || |
974 process_type == switches::kPluginProcess || | 1105 process_type == switches::kPluginProcess || |
975 process_type == switches::kPpapiPluginProcess || | 1106 process_type == switches::kPpapiPluginProcess || |
976 process_type == switches::kZygoteProcess || | 1107 process_type == switches::kZygoteProcess || |
977 process_type == switches::kGpuProcess) { | 1108 process_type == switches::kGpuProcess) { |
| 1109 #if defined(OS_ANDROID) |
| 1110 child_process_logging::SetClientId("Android"); |
| 1111 #endif |
978 // We might be chrooted in a zygote or renderer process so we cannot call | 1112 // 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 | 1113 // GetCollectStatsConsent because that needs access the the user's home |
980 // dir. Instead, we set a command line flag for these processes. | 1114 // 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 | 1115 // Even though plugins are not chrooted, we share the same code path for |
982 // simplicity. | 1116 // simplicity. |
983 if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter)) | 1117 if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter)) |
984 return; | 1118 return; |
985 // Get the guid and linux distro from the command line switch. | 1119 // Get the guid and linux distro from the command line switch. |
986 std::string switch_value = | 1120 std::string switch_value = |
987 parsed_command_line.GetSwitchValueASCII(switches::kEnableCrashReporter); | 1121 parsed_command_line.GetSwitchValueASCII(switches::kEnableCrashReporter); |
(...skipping 13 matching lines...) Expand all Loading... |
1001 g_process_start_time = timeval_to_ms(&tv); | 1135 g_process_start_time = timeval_to_ms(&tv); |
1002 else | 1136 else |
1003 g_process_start_time = 0; | 1137 g_process_start_time = 0; |
1004 | 1138 |
1005 logging::SetDumpWithoutCrashingFunction(&DumpProcess); | 1139 logging::SetDumpWithoutCrashingFunction(&DumpProcess); |
1006 } | 1140 } |
1007 | 1141 |
1008 bool IsCrashReporterEnabled() { | 1142 bool IsCrashReporterEnabled() { |
1009 return g_is_crash_reporter_enabled; | 1143 return g_is_crash_reporter_enabled; |
1010 } | 1144 } |
OLD | NEW |