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

Side by Side Diff: chrome/app/breakpad_linuxish.cc

Issue 9838033: Upstream native crash handling changes for Android. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Revert of Revert with fixes. Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/app/breakpad_linuxish.h ('k') | chrome/app/chrome_main_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
35 #include "breakpad/src/common/linux/linux_libc_support.h" 35 #include "breakpad/src/common/linux/linux_libc_support.h"
36 #include "breakpad/src/common/memory.h" 36 #include "breakpad/src/common/memory.h"
37 #include "chrome/browser/crash_upload_list.h" 37 #include "chrome/browser/crash_upload_list.h"
38 #include "chrome/common/child_process_logging.h" 38 #include "chrome/common/child_process_logging.h"
39 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
40 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
41 #include "chrome/common/chrome_version_info_posix.h" 41 #include "chrome/common/chrome_version_info_posix.h"
42 #include "chrome/common/env_vars.h" 42 #include "chrome/common/env_vars.h"
43 #include "chrome/common/logging_chrome.h" 43 #include "chrome/common/logging_chrome.h"
44 #include "content/common/chrome_descriptors.h" 44 #include "content/common/chrome_descriptors.h"
45
46 #if defined(OS_ANDROID)
47 #include <android/log.h>
48 #include <sys/stat.h>
49 #include "base/android/path_utils.h"
50 #include "base/android/build_info.h"
51 #include "third_party/lss/linux_syscall_support.h"
52 #else
45 #include "seccompsandbox/linux_syscall_support.h" 53 #include "seccompsandbox/linux_syscall_support.h"
54 #endif
46 55
47 #ifndef PR_SET_PTRACER 56 #ifndef PR_SET_PTRACER
48 #define PR_SET_PTRACER 0x59616d61 57 #define PR_SET_PTRACER 0x59616d61
49 #endif 58 #endif
50 59
51 // Some versions of gcc are prone to warn about unused return values. In cases 60 // Some versions of gcc are prone to warn about unused return values. In cases
52 // where we either a) know the call cannot fail, or b) there is nothing we 61 // where we either a) know the call cannot fail, or b) there is nothing we
53 // can do when a call fails, we mark the return code as ignored. This avoids 62 // can do when a call fails, we mark the return code as ignored. This avoids
54 // spurious compiler warnings. 63 // spurious compiler warnings.
55 #define IGNORE_RET(x) do { if (x); } while (0) 64 #define IGNORE_RET(x) do { if (x); } while (0)
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 120 }
112 121
113 // uint64_t version of my_itos() from 122 // uint64_t version of my_itos() from
114 // breakpad/src/common/linux/linux_libc_support.h. Convert a non-negative 123 // breakpad/src/common/linux/linux_libc_support.h. Convert a non-negative
115 // integer to a string (not null-terminated). 124 // integer to a string (not null-terminated).
116 static void my_uint64tos(char* output, uint64_t i, unsigned i_len) { 125 static void my_uint64tos(char* output, uint64_t i, unsigned i_len) {
117 for (unsigned index = i_len; index; --index, i /= 10) 126 for (unsigned index = i_len; index; --index, i /= 10)
118 output[index - 1] = '0' + (i % 10); 127 output[index - 1] = '0' + (i % 10);
119 } 128 }
120 129
130 #if defind(OS_ANDROID)
131 static char* my_strncpy(char* dst, const char* src, size_t len) {
132 int i = len;
133 char* p = dst;
134 if (!dst || !src)
135 return dst;
136 while (i != 0 && *src != '\0') {
137 *p++ = *src++;
138 i--;
139 }
140 while (i != 0) {
141 *p++ = '\0';
142 i--;
143 }
144 return dst;
145 }
146
147 static char* my_strncat(char *dest, const char *src, size_t len) {
148 char *ret = dest;
149 while (*dest)
150 dest++;
151 while (len--)
152 if (!(*dest++ = *src++))
153 return ret;
154 *dest = 0;
155 return ret;
156 }
157 #endif
158
121 namespace { 159 namespace {
122 160
123 // MIME substrings. 161 // MIME substrings.
124 static const char g_rn[] = "\r\n"; 162 static const char g_rn[] = "\r\n";
125 static const char g_form_data_msg[] = "Content-Disposition: form-data; name=\""; 163 static const char g_form_data_msg[] = "Content-Disposition: form-data; name=\"";
126 static const char g_quote_msg[] = "\""; 164 static const char g_quote_msg[] = "\"";
127 static const char g_dashdash_msg[] = "--"; 165 static const char g_dashdash_msg[] = "--";
128 static const char g_dump_msg[] = "upload_file_minidump\"; filename=\"dump\""; 166 static const char g_dump_msg[] = "upload_file_minidump\"; filename=\"dump\"";
129 static const char g_content_type_msg[] = 167 static const char g_content_type_msg[] =
130 "Content-Type: application/octet-stream"; 168 "Content-Type: application/octet-stream";
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 size--; 336 size--;
299 } 337 }
300 AddItem(base, size); 338 AddItem(base, size);
301 } 339 }
302 340
303 void DumpProcess() { 341 void DumpProcess() {
304 if (g_breakpad) 342 if (g_breakpad)
305 g_breakpad->WriteMinidump(); 343 g_breakpad->WriteMinidump();
306 } 344 }
307 345
346 size_t log(const char* buf, size_t nbytes) {
347 #if defined(OS_ANDROID)
348 return __android_log_write(ANDROID_LOG_WARN, "google-breakpad", buf);
349 #else
350 return sys_write(2, buf, nbytes)
351 #endif
352 }
353
308 } // namespace 354 } // namespace
309 355
310 void HandleCrashDump(const BreakpadInfo& info) { 356 void HandleCrashDump(const BreakpadInfo& info) {
311 // WARNING: this code runs in a compromised context. It may not call into 357 // WARNING: this code runs in a compromised context. It may not call into
312 // libc nor allocate memory normally. 358 // libc nor allocate memory normally.
313 359
314 const int dumpfd = sys_open(info.filename, O_RDONLY, 0); 360 const int dumpfd = sys_open(info.filename, O_RDONLY, 0);
315 if (dumpfd < 0) { 361 if (dumpfd < 0) {
316 static const char msg[] = "Cannot upload crash dump: failed to open\n"; 362 static const char msg[] = "Cannot upload crash dump: failed to open\n";
317 sys_write(2, msg, sizeof(msg)); 363 log(msg, sizeof(msg));
318 return; 364 return;
319 } 365 }
366 #if defined(OS_ANDROID)
367 struct stat st;
368 if (fstat(dumpfd, &st) != 0) {
369 #else
320 struct kernel_stat st; 370 struct kernel_stat st;
321 if (sys_fstat(dumpfd, &st) != 0) { 371 if (sys_fstat(dumpfd, &st) != 0) {
372 #endif
322 static const char msg[] = "Cannot upload crash dump: stat failed\n"; 373 static const char msg[] = "Cannot upload crash dump: stat failed\n";
323 sys_write(2, msg, sizeof(msg)); 374 log(msg, sizeof(msg));
324 IGNORE_RET(sys_close(dumpfd)); 375 IGNORE_RET(sys_close(dumpfd));
325 return; 376 return;
326 } 377 }
327 378
328 google_breakpad::PageAllocator allocator; 379 google_breakpad::PageAllocator allocator;
329 380
330 uint8_t* dump_data = reinterpret_cast<uint8_t*>(allocator.Alloc(st.st_size)); 381 uint8_t* dump_data = reinterpret_cast<uint8_t*>(allocator.Alloc(st.st_size));
331 if (!dump_data) { 382 if (!dump_data) {
332 static const char msg[] = "Cannot upload crash dump: cannot alloc\n"; 383 static const char msg[] = "Cannot upload crash dump: cannot alloc\n";
333 sys_write(2, msg, sizeof(msg)); 384 log(msg, sizeof(msg));
334 IGNORE_RET(sys_close(dumpfd)); 385 IGNORE_RET(sys_close(dumpfd));
335 return; 386 return;
336 } 387 }
337 388
338 sys_read(dumpfd, dump_data, st.st_size); 389 sys_read(dumpfd, dump_data, st.st_size);
339 IGNORE_RET(sys_close(dumpfd)); 390 IGNORE_RET(sys_close(dumpfd));
340 391
341 // We need to build a MIME block for uploading to the server. Since we are 392 // We need to build a MIME block for uploading to the server. Since we are
342 // going to fork and run wget, it needs to be written to a temp file. 393 // going to fork and run wget, it needs to be written to a temp file.
343 394
344 const int ufd = sys_open("/dev/urandom", O_RDONLY, 0); 395 const int ufd = sys_open("/dev/urandom", O_RDONLY, 0);
345 if (ufd < 0) { 396 if (ufd < 0) {
346 static const char msg[] = "Cannot upload crash dump because /dev/urandom" 397 static const char msg[] = "Cannot upload crash dump because /dev/urandom"
347 " is missing\n"; 398 " is missing\n";
348 sys_write(2, msg, sizeof(msg) - 1); 399 log(msg, sizeof(msg) - 1);
349 return; 400 return;
350 } 401 }
351 402
352 static const char temp_file_template[] = 403 static const char temp_file_template[] =
353 "/tmp/chromium-upload-XXXXXXXXXXXXXXXX"; 404 "/tmp/chromium-upload-XXXXXXXXXXXXXXXX";
354 char temp_file[sizeof(temp_file_template)]; 405 char temp_file[sizeof(temp_file_template)];
355 int temp_file_fd = -1; 406 int temp_file_fd = -1;
356 if (info.upload) { 407 if (info.upload) {
357 memcpy(temp_file, temp_file_template, sizeof(temp_file_template)); 408 memcpy(temp_file, temp_file_template, sizeof(temp_file_template));
358 409
359 for (unsigned i = 0; i < 10; ++i) { 410 for (unsigned i = 0; i < 10; ++i) {
360 uint64_t t; 411 uint64_t t;
361 sys_read(ufd, &t, sizeof(t)); 412 sys_read(ufd, &t, sizeof(t));
362 write_uint64_hex(temp_file + sizeof(temp_file) - (16 + 1), t); 413 write_uint64_hex(temp_file + sizeof(temp_file) - (16 + 1), t);
363 414
364 temp_file_fd = sys_open(temp_file, O_WRONLY | O_CREAT | O_EXCL, 0600); 415 temp_file_fd = sys_open(temp_file, O_WRONLY | O_CREAT | O_EXCL, 0600);
365 if (temp_file_fd >= 0) 416 if (temp_file_fd >= 0)
366 break; 417 break;
367 } 418 }
368 419
369 if (temp_file_fd < 0) { 420 if (temp_file_fd < 0) {
370 static const char msg[] = "Failed to create temporary file in /tmp: " 421 static const char msg[] = "Failed to create temporary file in /tmp: "
371 "cannot upload crash dump\n"; 422 "cannot upload crash dump\n";
372 sys_write(2, msg, sizeof(msg) - 1); 423 log(msg, sizeof(msg) - 1);
373 IGNORE_RET(sys_close(ufd)); 424 IGNORE_RET(sys_close(ufd));
374 return; 425 return;
375 } 426 }
376 } else { 427 } else {
377 temp_file_fd = sys_open(info.filename, O_WRONLY, 0600); 428 temp_file_fd = sys_open(info.filename, O_WRONLY, 0600);
378 if (temp_file_fd < 0) { 429 if (temp_file_fd < 0) {
379 static const char msg[] = "Failed to save crash dump: failed to open\n"; 430 static const char msg[] = "Failed to save crash dump: failed to open\n";
380 sys_write(2, msg, sizeof(msg) - 1); 431 log(msg, sizeof(msg) - 1);
381 IGNORE_RET(sys_close(ufd)); 432 IGNORE_RET(sys_close(ufd));
382 return; 433 return;
383 } 434 }
384 } 435 }
385 436
386 // The MIME boundary is 28 hyphens, followed by a 64-bit nonce and a NUL. 437 // The MIME boundary is 28 hyphens, followed by a 64-bit nonce and a NUL.
387 char mime_boundary[28 + 16 + 1]; 438 char mime_boundary[28 + 16 + 1];
388 my_memset(mime_boundary, '-', 28); 439 my_memset(mime_boundary, '-', 28);
389 uint64_t boundary_rand; 440 uint64_t boundary_rand;
390 sys_read(ufd, &boundary_rand, sizeof(boundary_rand)); 441 sys_read(ufd, &boundary_rand, sizeof(boundary_rand));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 // 1234567890 \r\n 520 // 1234567890 \r\n
470 // BOUNDARY \r\n 521 // BOUNDARY \r\n
471 // 522 //
472 // Content-Disposition: form-data; name="dump"; filename="dump" \r\n 523 // Content-Disposition: form-data; name="dump"; filename="dump" \r\n
473 // Content-Type: application/octet-stream \r\n \r\n 524 // Content-Type: application/octet-stream \r\n \r\n
474 // <dump contents> 525 // <dump contents>
475 // \r\n BOUNDARY -- \r\n 526 // \r\n BOUNDARY -- \r\n
476 527
477 MimeWriter writer(temp_file_fd, mime_boundary); 528 MimeWriter writer(temp_file_fd, mime_boundary);
478 { 529 {
479 #if defined(OS_CHROMEOS) 530 #if defined(OS_ANDROID)
531 static const char chrome_product_msg[] = "Chrome_Android";
532 #elif defined(OS_CHROMEOS)
480 static const char chrome_product_msg[] = "Chrome_ChromeOS"; 533 static const char chrome_product_msg[] = "Chrome_ChromeOS";
481 #else // OS_LINUX 534 #else // OS_LINUX
482 static const char chrome_product_msg[] = "Chrome_Linux"; 535 static const char chrome_product_msg[] = "Chrome_Linux";
483 #endif 536 #endif
537
538 #if defined (OS_ANDROID)
539 base::android::BuildInfo* android_build_info =
540 base::android::BuildInfo::GetInstance();
541 static const char* version_msg =
542 android_build_info->package_version_code();
543 static const char android_build_id[] = "android_build_id";
544 static const char android_build_fp[] = "android_build_fp";
545 static const char device[] = "device";
546 static const char model[] = "model";
547 static const char brand[] = "brand";
548 #else
484 static const char version_msg[] = PRODUCT_VERSION; 549 static const char version_msg[] = PRODUCT_VERSION;
550 #endif
485 551
486 writer.AddBoundary(); 552 writer.AddBoundary();
487 writer.AddPairString("prod", chrome_product_msg); 553 writer.AddPairString("prod", chrome_product_msg);
488 writer.AddBoundary(); 554 writer.AddBoundary();
489 writer.AddPairString("ver", version_msg); 555 writer.AddPairString("ver", version_msg);
490 writer.AddBoundary(); 556 writer.AddBoundary();
491 writer.AddPairString("guid", info.guid); 557 writer.AddPairString("guid", info.guid);
492 writer.AddBoundary(); 558 writer.AddBoundary();
559 if (info.pid > 0) {
560 uint64_t pid_str_len = my_uint64_len(info.pid);
561 char* pid_buf = reinterpret_cast<char*>(allocator.Alloc(pid_str_len));
562 my_uint64tos(pid_buf, info.pid, pid_str_len);
563 writer.AddPairString("pid", pid_buf);
564 writer.AddBoundary();
565 }
566 #if defined(OS_ANDROID)
567 // Addtional MIME blocks are added for logging on Android devices.
568 writer.AddPairString(
569 android_build_id, android_build_info->android_build_id());
570 writer.AddBoundary();
571 writer.AddPairString(
572 android_build_fp, android_build_info->android_build_fp());
573 writer.AddBoundary();
574 writer.AddPairString(device, android_build_info->device());
575 writer.AddBoundary();
576 writer.AddPairString(model, android_build_info->model());
577 writer.AddBoundary();
578 writer.AddPairString(brand, android_build_info->brand());
579 writer.AddBoundary();
580 #endif
493 writer.Flush(); 581 writer.Flush();
494 } 582 }
495 583
496 if (info.process_start_time > 0) { 584 if (info.process_start_time > 0) {
497 struct kernel_timeval tv; 585 struct kernel_timeval tv;
498 if (!sys_gettimeofday(&tv, NULL)) { 586 if (!sys_gettimeofday(&tv, NULL)) {
499 uint64_t time = kernel_timeval_to_ms(&tv); 587 uint64_t time = kernel_timeval_to_ms(&tv);
500 if (time > info.process_start_time) { 588 if (time > info.process_start_time) {
501 time -= info.process_start_time; 589 time -= info.process_start_time;
502 char time_str[kUint64StringSize]; 590 char time_str[kUint64StringSize];
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 oom_size_str, oom_size_len); 718 oom_size_str, oom_size_len);
631 writer.AddBoundary(); 719 writer.AddBoundary();
632 writer.Flush(); 720 writer.Flush();
633 } 721 }
634 722
635 writer.AddFileDump(dump_data, st.st_size); 723 writer.AddFileDump(dump_data, st.st_size);
636 writer.AddEnd(); 724 writer.AddEnd();
637 writer.Flush(); 725 writer.Flush();
638 726
639 IGNORE_RET(sys_close(temp_file_fd)); 727 IGNORE_RET(sys_close(temp_file_fd));
728 #if defined(OS_ANDROID)
729 uint64_t pid_str_len = my_uint64_len(info.pid);
730 char* pid_buf = reinterpret_cast<char*>(allocator.Alloc(pid_str_len));
731 my_uint64tos(pid_buf, info.pid, pid_str_len);
732
733 static const char* output_msg = "Output crash dump file:";
734 log(output_msg, my_strlen(output_msg));
735 int initial_filename_len = my_strln(info.filename);
736 log(info.filename, info.filename);
737 // -1 because we won't need the null terminator on the original filename.
738 size_t done_filename_len = initial_filename_len -1 + pid_str_len;
739 char* done_filename = reinterpret_cast<char*>(
740 allocator.Alloc(done_filename_len));
741 // Rename the file such that the pid is the suffix in order signal to other
742 // processes that the minidump is complete. The advantage of using the pid as
743 // the suffix is that it is trivial to associate the minidump with the
744 // crashed process.
745 // Finally, note strncpy prevents null terminators from
746 // being copied. Pad the rest with 0's.
747 my_strncpy(done_filename, info.filename, done_filename_len);
748 // Append the suffix a null terminator should be added.
749 my_strncat(done_filename, pid_buf, pid_str_len);
750 // Rename the minidump file to signal that it is complete.
751 if (rename(info.filename, done_filename)) {
752 __android_log_write(ANDROID_LOG_WARN, "chromium", "Failed to rename:");
753 __android_log_write(ANDROID_LOG_WARN, "chromium", info.filename);
754 __android_log_write(ANDROID_LOG_WARN, "chromium", "to");
755 __android_log_write(ANDROID_LOG_WARN, "chromium", done_filename);
756 }
757 #endif
640 758
641 if (!info.upload) 759 if (!info.upload)
642 return; 760 return;
643 761
644 // The --header argument to wget looks like: 762 // The --header argument to wget looks like:
645 // --header=Content-Type: multipart/form-data; boundary=XYZ 763 // --header=Content-Type: multipart/form-data; boundary=XYZ
646 // where the boundary has two fewer leading '-' chars 764 // where the boundary has two fewer leading '-' chars
647 static const char header_msg[] = 765 static const char header_msg[] =
648 "--header=Content-Type: multipart/form-data; boundary="; 766 "--header=Content-Type: multipart/form-data; boundary=";
649 char* const header = reinterpret_cast<char*>(allocator.Alloc( 767 char* const header = reinterpret_cast<char*>(allocator.Alloc(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 "--timeout=10", // Set a timeout so we don't hang forever. 829 "--timeout=10", // Set a timeout so we don't hang forever.
712 "--tries=1", // Don't retry if the upload fails. 830 "--tries=1", // Don't retry if the upload fails.
713 "-O", // output reply to fd 3 831 "-O", // output reply to fd 3
714 "/dev/fd/3", 832 "/dev/fd/3",
715 NULL, 833 NULL,
716 }; 834 };
717 835
718 execve(kWgetBinary, const_cast<char**>(args), environ); 836 execve(kWgetBinary, const_cast<char**>(args), environ);
719 static const char msg[] = "Cannot upload crash dump: cannot exec " 837 static const char msg[] = "Cannot upload crash dump: cannot exec "
720 "/usr/bin/wget\n"; 838 "/usr/bin/wget\n";
721 sys_write(2, msg, sizeof(msg) - 1); 839 log(msg, sizeof(msg) - 1);
722 sys__exit(1); 840 sys__exit(1);
723 } 841 }
724 842
725 // Helper process. 843 // Helper process.
726 if (wget_child > 0) { 844 if (wget_child > 0) {
727 IGNORE_RET(sys_close(fds[1])); 845 IGNORE_RET(sys_close(fds[1]));
728 char id_buf[17]; // Crash report IDs are expected to be 16 chars. 846 char id_buf[17]; // Crash report IDs are expected to be 16 chars.
729 ssize_t len = -1; 847 ssize_t len = -1;
730 // Wget should finish in about 10 seconds. Add a few more 500 ms 848 // Wget should finish in about 10 seconds. Add a few more 500 ms
731 // internals to account for process startup time. 849 // internals to account for process startup time.
732 for (size_t wait_count = 0; wait_count < 24; ++wait_count) { 850 for (size_t wait_count = 0; wait_count < 24; ++wait_count) {
733 struct kernel_pollfd poll_fd; 851 struct kernel_pollfd poll_fd;
734 poll_fd.fd = fds[0]; 852 poll_fd.fd = fds[0];
735 poll_fd.events = POLLIN | POLLPRI | POLLERR; 853 poll_fd.events = POLLIN | POLLPRI | POLLERR;
736 int ret = sys_poll(&poll_fd, 1, 500); 854 int ret = sys_poll(&poll_fd, 1, 500);
737 if (ret < 0) { 855 if (ret < 0) {
738 // Error 856 // Error
739 break; 857 break;
740 } else if (ret > 0) { 858 } else if (ret > 0) {
741 // There is data to read. 859 // There is data to read.
742 len = HANDLE_EINTR(sys_read(fds[0], id_buf, sizeof(id_buf) - 1)); 860 len = HANDLE_EINTR(sys_read(fds[0], id_buf, sizeof(id_buf) - 1));
743 break; 861 break;
744 } 862 }
745 // ret == 0 -> timed out, continue waiting. 863 // ret == 0 -> timed out, continue waiting.
746 } 864 }
747 if (len > 0) { 865 if (len > 0) {
748 // Write crash dump id to stderr. 866 // Write crash dump id to stderr.
749 id_buf[len] = 0; 867 id_buf[len] = 0;
750 static const char msg[] = "\nCrash dump id: "; 868 static const char msg[] = "\nCrash dump id: ";
751 sys_write(2, msg, sizeof(msg) - 1); 869 log(msg, sizeof(msg) - 1);
752 sys_write(2, id_buf, my_strlen(id_buf)); 870 log(id_buf, my_strlen(id_buf));
753 sys_write(2, "\n", 1); 871 log("\n", 1);
754 872
755 // Write crash dump id to crash log as: seconds_since_epoch,crash_id 873 // Write crash dump id to crash log as: seconds_since_epoch,crash_id
756 struct kernel_timeval tv; 874 struct kernel_timeval tv;
757 if (g_crash_log_path && !sys_gettimeofday(&tv, NULL)) { 875 if (g_crash_log_path && !sys_gettimeofday(&tv, NULL)) {
758 uint64_t time = kernel_timeval_to_ms(&tv) / 1000; 876 uint64_t time = kernel_timeval_to_ms(&tv) / 1000;
759 char time_str[kUint64StringSize]; 877 char time_str[kUint64StringSize];
760 const unsigned time_len = my_uint64_len(time); 878 const unsigned time_len = my_uint64_len(time);
761 my_uint64tos(time_str, time, time_len); 879 my_uint64tos(time_str, time, time_len);
762 880
763 int log_fd = sys_open(g_crash_log_path, 881 int log_fd = sys_open(g_crash_log_path,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 info.process_type_length = 7; 936 info.process_type_length = 7;
819 info.crash_url = NULL; 937 info.crash_url = NULL;
820 info.crash_url_length = 0; 938 info.crash_url_length = 0;
821 info.guid = child_process_logging::g_client_id; 939 info.guid = child_process_logging::g_client_id;
822 info.guid_length = my_strlen(child_process_logging::g_client_id); 940 info.guid_length = my_strlen(child_process_logging::g_client_id);
823 info.distro = base::g_linux_distro; 941 info.distro = base::g_linux_distro;
824 info.distro_length = my_strlen(base::g_linux_distro); 942 info.distro_length = my_strlen(base::g_linux_distro);
825 info.upload = upload; 943 info.upload = upload;
826 info.process_start_time = g_process_start_time; 944 info.process_start_time = g_process_start_time;
827 info.oom_size = base::g_oom_size; 945 info.oom_size = base::g_oom_size;
946 info.pid = 0;
828 HandleCrashDump(info); 947 HandleCrashDump(info);
829 return true; 948 return true;
830 } 949 }
831 950
832 // Wrapper function, do not add more code here. 951 // Wrapper function, do not add more code here.
833 static bool CrashDoneNoUpload(const char* dump_path, 952 static bool CrashDoneNoUpload(const char* dump_path,
834 const char* minidump_id, 953 const char* minidump_id,
835 void* context, 954 void* context,
836 bool succeeded) { 955 bool succeeded) {
837 return CrashDone(dump_path, minidump_id, false, succeeded); 956 return CrashDone(dump_path, minidump_id, false, succeeded);
838 } 957 }
839 958
959 #if !defined(OS_ANDROID)
840 // Wrapper function, do not add more code here. 960 // Wrapper function, do not add more code here.
841 static bool CrashDoneUpload(const char* dump_path, 961 static bool CrashDoneUpload(const char* dump_path,
842 const char* minidump_id, 962 const char* minidump_id,
843 void* context, 963 void* context,
844 bool succeeded) { 964 bool succeeded) {
845 return CrashDone(dump_path, minidump_id, true, succeeded); 965 return CrashDone(dump_path, minidump_id, true, succeeded);
846 } 966 }
967 #endif
847 968
848 void EnableCrashDumping(const bool unattended) { 969 void EnableCrashDumping(const bool unattended) {
849 g_is_crash_reporter_enabled = true; 970 g_is_crash_reporter_enabled = true;
850 971
851 FilePath tmp_path("/tmp"); 972 FilePath tmp_path("/tmp");
852 PathService::Get(base::DIR_TEMP, &tmp_path); 973 PathService::Get(base::DIR_TEMP, &tmp_path);
853 974
854 FilePath dumps_path(tmp_path); 975 FilePath dumps_path(tmp_path);
855 if (PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) { 976 if (PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) {
856 FilePath logfile = 977 FilePath logfile =
857 dumps_path.AppendASCII(CrashUploadList::kReporterLogFilename); 978 dumps_path.AppendASCII(CrashUploadList::kReporterLogFilename);
858 std::string logfile_str = logfile.value(); 979 std::string logfile_str = logfile.value();
859 const size_t crash_log_path_len = logfile_str.size() + 1; 980 const size_t crash_log_path_len = logfile_str.size() + 1;
860 g_crash_log_path = new char[crash_log_path_len]; 981 g_crash_log_path = new char[crash_log_path_len];
861 strncpy(g_crash_log_path, logfile_str.c_str(), crash_log_path_len); 982 strncpy(g_crash_log_path, logfile_str.c_str(), crash_log_path_len);
862 } 983 }
863
864 DCHECK(!g_breakpad); 984 DCHECK(!g_breakpad);
985 #if defined(OS_ANDROID)
986 // In Android we never upload from native code.
987 g_breakpad = new google_breakpad::ExceptionHandler(
988 dumps_path.value().c_str(),
989 NULL,
990 CrashDoneNoUpload,
991 NULL,
992 true /* install handlers */);
993 #else
865 if (unattended) { 994 if (unattended) {
866 g_breakpad = new google_breakpad::ExceptionHandler( 995 g_breakpad = new google_breakpad::ExceptionHandler(
867 dumps_path.value().c_str(), 996 dumps_path.value().c_str(),
868 NULL, 997 NULL,
869 CrashDoneNoUpload, 998 CrashDoneNoUpload,
870 NULL, 999 NULL,
871 true /* install handlers */); 1000 true /* install handlers */);
872 } else { 1001 } else {
873 g_breakpad = new google_breakpad::ExceptionHandler( 1002 g_breakpad = new google_breakpad::ExceptionHandler(
874 tmp_path.value().c_str(), 1003 tmp_path.value().c_str(),
875 NULL, 1004 NULL,
876 CrashDoneUpload, 1005 CrashDoneUpload,
877 NULL, 1006 NULL,
878 true /* install handlers */); 1007 true /* install handlers */);
879 } 1008 }
1009 #endif
880 } 1010 }
881 1011
882 // Non-Browser = Extension, Gpu, Plugins, Ppapi and Renderer 1012 // Non-Browser = Extension, Gpu, Plugins, Ppapi and Renderer
883 static bool NonBrowserCrashHandler(const void* crash_context, 1013 static bool NonBrowserCrashHandler(const void* crash_context,
884 size_t crash_context_size, 1014 size_t crash_context_size,
885 void* context) { 1015 void* context) {
886 const int fd = reinterpret_cast<intptr_t>(context); 1016 const int fd = reinterpret_cast<intptr_t>(context);
887 int fds[2] = { -1, -1 }; 1017 int fds[2] = { -1, -1 };
888 if (sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { 1018 if (sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) {
889 static const char msg[] = "Failed to create socket for crash dumping.\n"; 1019 static const char msg[] = "Failed to create socket for crash dumping.\n";
890 sys_write(2, msg, sizeof(msg)-1); 1020 log(msg, sizeof(msg)-1);
891 return false; 1021 return false;
892 } 1022 }
893 1023
894 // On kernels with ptrace protection, e.g. Ubuntu 10.10+, the browser cannot 1024 // On kernels with ptrace protection, e.g. Ubuntu 10.10+, the browser cannot
895 // ptrace this crashing process and crash dumping will fail. When using the 1025 // ptrace this crashing process and crash dumping will fail. When using the
896 // SUID sandbox, this crashing process is likely to be in its own PID 1026 // SUID sandbox, this crashing process is likely to be in its own PID
897 // namespace, and thus there is no way to permit only the browser process to 1027 // namespace, and thus there is no way to permit only the browser process to
898 // ptrace it. 1028 // ptrace it.
899 // The workaround is to allow all processes to ptrace this process if we 1029 // The workaround is to allow all processes to ptrace this process if we
900 // reach this point, by passing -1 as the allowed PID. However, support for 1030 // reach this point, by passing -1 as the allowed PID. However, support for
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 1087
958 struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); 1088 struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg);
959 hdr->cmsg_level = SOL_SOCKET; 1089 hdr->cmsg_level = SOL_SOCKET;
960 hdr->cmsg_type = SCM_RIGHTS; 1090 hdr->cmsg_type = SCM_RIGHTS;
961 hdr->cmsg_len = kControlMsgLenSize; 1091 hdr->cmsg_len = kControlMsgLenSize;
962 ((int*) CMSG_DATA(hdr))[0] = fds[0]; 1092 ((int*) CMSG_DATA(hdr))[0] = fds[0];
963 ((int*) CMSG_DATA(hdr))[1] = fds[1]; 1093 ((int*) CMSG_DATA(hdr))[1] = fds[1];
964 1094
965 if (HANDLE_EINTR(sys_sendmsg(fd, &msg, 0)) < 0) { 1095 if (HANDLE_EINTR(sys_sendmsg(fd, &msg, 0)) < 0) {
966 static const char errmsg[] = "Failed to tell parent about crash.\n"; 1096 static const char errmsg[] = "Failed to tell parent about crash.\n";
967 sys_write(2, errmsg, sizeof(errmsg)-1); 1097 log(errmsg, sizeof(errmsg)-1);
968 IGNORE_RET(sys_close(fds[1])); 1098 IGNORE_RET(sys_close(fds[1]));
969 return false; 1099 return false;
970 } 1100 }
971 IGNORE_RET(sys_close(fds[1])); 1101 IGNORE_RET(sys_close(fds[1]));
972 1102
973 if (HANDLE_EINTR(sys_read(fds[0], &b, 1)) != 1) { 1103 if (HANDLE_EINTR(sys_read(fds[0], &b, 1)) != 1) {
974 static const char errmsg[] = "Parent failed to complete crash dump.\n"; 1104 static const char errmsg[] = "Parent failed to complete crash dump.\n";
975 sys_write(2, errmsg, sizeof(errmsg)-1); 1105 log(errmsg, sizeof(errmsg)-1);
976 } 1106 }
977 1107
978 return true; 1108 return true;
979 } 1109 }
980 1110
981 void EnableNonBrowserCrashDumping() { 1111 void EnableNonBrowserCrashDumping() {
982 const int fd = base::GlobalDescriptors::GetInstance()->Get(kCrashDumpSignal); 1112 const int fd = base::GlobalDescriptors::GetInstance()->Get(kCrashDumpSignal);
983 g_is_crash_reporter_enabled = true; 1113 g_is_crash_reporter_enabled = true;
984 // We deliberately leak this object. 1114 // We deliberately leak this object.
985 DCHECK(!g_breakpad); 1115 DCHECK(!g_breakpad);
986 g_breakpad = new google_breakpad::ExceptionHandler( 1116 g_breakpad = new google_breakpad::ExceptionHandler(
987 "" /* unused */, NULL, NULL, reinterpret_cast<void*>(fd), true); 1117 "" /* unused */, NULL, NULL, reinterpret_cast<void*>(fd), true);
988 g_breakpad->set_crash_handler(NonBrowserCrashHandler); 1118 g_breakpad->set_crash_handler(NonBrowserCrashHandler);
989 } 1119 }
990 1120
991 void InitCrashReporter() { 1121 void InitCrashReporter() {
1122 #if defined(OS_ANDROID)
1123 // This will guarantee that the BuildInfo has been initialized and subsequent
1124 // calls will not require memory allocation.
1125 base::android::BuildInfo::GetInstance();
1126 #endif
992 // Determine the process type and take appropriate action. 1127 // Determine the process type and take appropriate action.
993 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 1128 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
994 if (parsed_command_line.HasSwitch(switches::kDisableBreakpad)) 1129 if (parsed_command_line.HasSwitch(switches::kDisableBreakpad))
995 return; 1130 return;
996 1131
997 const std::string process_type = 1132 const std::string process_type =
998 parsed_command_line.GetSwitchValueASCII(switches::kProcessType); 1133 parsed_command_line.GetSwitchValueASCII(switches::kProcessType);
999 if (process_type.empty()) { 1134 if (process_type.empty()) {
1000 EnableCrashDumping(getenv(env_vars::kHeadless) != NULL); 1135 EnableCrashDumping(getenv(env_vars::kHeadless) != NULL);
1001 } else if (process_type == switches::kRendererProcess || 1136 } else if (process_type == switches::kRendererProcess ||
1002 process_type == switches::kPluginProcess || 1137 process_type == switches::kPluginProcess ||
1003 process_type == switches::kPpapiPluginProcess || 1138 process_type == switches::kPpapiPluginProcess ||
1004 process_type == switches::kZygoteProcess || 1139 process_type == switches::kZygoteProcess ||
1005 process_type == switches::kGpuProcess) { 1140 process_type == switches::kGpuProcess) {
1141 #if defined(OS_ANDROID)
1142 child_process_logging::SetClientId("Android");
1143 #endif
1006 // We might be chrooted in a zygote or renderer process so we cannot call 1144 // We might be chrooted in a zygote or renderer process so we cannot call
1007 // GetCollectStatsConsent because that needs access the the user's home 1145 // GetCollectStatsConsent because that needs access the the user's home
1008 // dir. Instead, we set a command line flag for these processes. 1146 // dir. Instead, we set a command line flag for these processes.
1009 // Even though plugins are not chrooted, we share the same code path for 1147 // Even though plugins are not chrooted, we share the same code path for
1010 // simplicity. 1148 // simplicity.
1011 if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter)) 1149 if (!parsed_command_line.HasSwitch(switches::kEnableCrashReporter))
1012 return; 1150 return;
1013 // Get the guid and linux distro from the command line switch. 1151 // Get the guid and linux distro from the command line switch.
1014 std::string switch_value = 1152 std::string switch_value =
1015 parsed_command_line.GetSwitchValueASCII(switches::kEnableCrashReporter); 1153 parsed_command_line.GetSwitchValueASCII(switches::kEnableCrashReporter);
(...skipping 13 matching lines...) Expand all
1029 g_process_start_time = timeval_to_ms(&tv); 1167 g_process_start_time = timeval_to_ms(&tv);
1030 else 1168 else
1031 g_process_start_time = 0; 1169 g_process_start_time = 0;
1032 1170
1033 logging::SetDumpWithoutCrashingFunction(&DumpProcess); 1171 logging::SetDumpWithoutCrashingFunction(&DumpProcess);
1034 } 1172 }
1035 1173
1036 bool IsCrashReporterEnabled() { 1174 bool IsCrashReporterEnabled() {
1037 return g_is_crash_reporter_enabled; 1175 return g_is_crash_reporter_enabled;
1038 } 1176 }
OLDNEW
« no previous file with comments | « chrome/app/breakpad_linuxish.h ('k') | chrome/app/chrome_main_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698