| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 | 7 |
| 8 #include "components/breakpad/app/breakpad_linux.h" | 8 #include "components/breakpad/app/breakpad_linux.h" |
| 9 | 9 |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 #endif | 197 #endif |
| 198 | 198 |
| 199 size_t LengthWithoutTrailingSpaces(const char* str, size_t len) { | 199 size_t LengthWithoutTrailingSpaces(const char* str, size_t len) { |
| 200 while (len > 0 && str[len - 1] == ' ') { | 200 while (len > 0 && str[len - 1] == ' ') { |
| 201 len--; | 201 len--; |
| 202 } | 202 } |
| 203 return len; | 203 return len; |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Populates the passed in allocated string and its size with the distro of | |
| 207 // the crashing process. | |
| 208 // The passed string is expected to be at least kDistroSize bytes long. | |
| 209 void PopulateDistro(char* distro, size_t* distro_len_param) { | |
| 210 size_t distro_len = std::min(my_strlen(base::g_linux_distro), kDistroSize); | |
| 211 memcpy(distro, base::g_linux_distro, distro_len); | |
| 212 if (distro_len_param) | |
| 213 *distro_len_param = distro_len; | |
| 214 } | |
| 215 | |
| 216 void SetClientIdFromCommandLine(const CommandLine& command_line) { | 206 void SetClientIdFromCommandLine(const CommandLine& command_line) { |
| 217 // Get the guid and linux distro from the command line switch. | 207 // Get the guid and linux distro from the command line switch. |
| 218 std::string switch_value = | 208 std::string switch_value = |
| 219 command_line.GetSwitchValueASCII(switches::kEnableCrashReporter); | 209 command_line.GetSwitchValueASCII(switches::kEnableCrashReporter); |
| 220 size_t separator = switch_value.find(","); | 210 size_t separator = switch_value.find(","); |
| 221 if (separator != std::string::npos) { | 211 if (separator != std::string::npos) { |
| 222 GetBreakpadClient()->SetClientID(switch_value.substr(0, separator)); | 212 GetBreakpadClient()->SetClientID(switch_value.substr(0, separator)); |
| 223 base::SetLinuxDistro(switch_value.substr(separator + 1)); | 213 base::SetLinuxDistro(switch_value.substr(separator + 1)); |
| 224 } else { | 214 } else { |
| 225 GetBreakpadClient()->SetClientID(switch_value); | 215 GetBreakpadClient()->SetClientID(switch_value); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 const bool succeeded) { | 681 const bool succeeded) { |
| 692 // WARNING: this code runs in a compromised context. It may not call into | 682 // WARNING: this code runs in a compromised context. It may not call into |
| 693 // libc nor allocate memory normally. | 683 // libc nor allocate memory normally. |
| 694 if (!succeeded) { | 684 if (!succeeded) { |
| 695 static const char msg[] = "Crash dump generation failed.\n"; | 685 static const char msg[] = "Crash dump generation failed.\n"; |
| 696 WriteLog(msg, sizeof(msg) - 1); | 686 WriteLog(msg, sizeof(msg) - 1); |
| 697 return false; | 687 return false; |
| 698 } | 688 } |
| 699 | 689 |
| 700 // Start constructing the message to send to the browser. | 690 // Start constructing the message to send to the browser. |
| 701 char distro[kDistroSize + 1] = {0}; | |
| 702 size_t distro_length = 0; | |
| 703 PopulateDistro(distro, &distro_length); | |
| 704 BreakpadInfo info = {0}; | 691 BreakpadInfo info = {0}; |
| 705 info.filename = NULL; | 692 info.filename = NULL; |
| 706 info.fd = descriptor.fd(); | 693 info.fd = descriptor.fd(); |
| 707 info.process_type = g_process_type; | 694 info.process_type = g_process_type; |
| 708 info.process_type_length = my_strlen(g_process_type); | 695 info.process_type_length = my_strlen(g_process_type); |
| 709 info.distro = distro; | 696 info.distro = NULL; |
| 710 info.distro_length = distro_length; | 697 info.distro_length = 0; |
| 711 info.upload = false; | 698 info.upload = false; |
| 712 info.process_start_time = g_process_start_time; | 699 info.process_start_time = g_process_start_time; |
| 713 info.pid = g_pid; | 700 info.pid = g_pid; |
| 714 info.crash_keys = g_crash_keys; | 701 info.crash_keys = g_crash_keys; |
| 715 HandleCrashDump(info); | 702 HandleCrashDump(info); |
| 716 bool finalize_result = FinalizeCrashDoneAndroid(); | 703 bool finalize_result = FinalizeCrashDoneAndroid(); |
| 717 base::android::BuildInfo* android_build_info = | 704 base::android::BuildInfo* android_build_info = |
| 718 base::android::BuildInfo::GetInstance(); | 705 base::android::BuildInfo::GetInstance(); |
| 719 if (android_build_info->sdk_int() >= 18 && | 706 if (android_build_info->sdk_int() >= 18 && |
| 720 my_strcmp(android_build_info->build_type(), "eng") != 0 && | 707 my_strcmp(android_build_info->build_type(), "eng") != 0 && |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 virtual bool RequestDump(const void* crash_context, | 768 virtual bool RequestDump(const void* crash_context, |
| 782 size_t crash_context_size) OVERRIDE { | 769 size_t crash_context_size) OVERRIDE { |
| 783 int fds[2] = { -1, -1 }; | 770 int fds[2] = { -1, -1 }; |
| 784 if (sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { | 771 if (sys_socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0) { |
| 785 static const char msg[] = "Failed to create socket for crash dumping.\n"; | 772 static const char msg[] = "Failed to create socket for crash dumping.\n"; |
| 786 WriteLog(msg, sizeof(msg) - 1); | 773 WriteLog(msg, sizeof(msg) - 1); |
| 787 return false; | 774 return false; |
| 788 } | 775 } |
| 789 | 776 |
| 790 // Start constructing the message to send to the browser. | 777 // Start constructing the message to send to the browser. |
| 791 char distro[kDistroSize + 1] = {0}; | |
| 792 PopulateDistro(distro, NULL); | |
| 793 | |
| 794 char b; // Dummy variable for sys_read below. | 778 char b; // Dummy variable for sys_read below. |
| 795 const char* b_addr = &b; // Get the address of |b| so we can create the | 779 const char* b_addr = &b; // Get the address of |b| so we can create the |
| 796 // expected /proc/[pid]/syscall content in the | 780 // expected /proc/[pid]/syscall content in the |
| 797 // browser to convert namespace tids. | 781 // browser to convert namespace tids. |
| 798 | 782 |
| 799 // The length of the control message: | 783 // The length of the control message: |
| 800 static const unsigned kControlMsgSize = sizeof(int); | 784 static const unsigned kControlMsgSize = sizeof(int); |
| 801 static const unsigned kControlMsgSpaceSize = CMSG_SPACE(kControlMsgSize); | 785 static const unsigned kControlMsgSpaceSize = CMSG_SPACE(kControlMsgSize); |
| 802 static const unsigned kControlMsgLenSize = CMSG_LEN(kControlMsgSize); | 786 static const unsigned kControlMsgLenSize = CMSG_LEN(kControlMsgSize); |
| 803 | 787 |
| 804 struct kernel_msghdr msg; | 788 struct kernel_msghdr msg; |
| 805 my_memset(&msg, 0, sizeof(struct kernel_msghdr)); | 789 my_memset(&msg, 0, sizeof(struct kernel_msghdr)); |
| 806 struct kernel_iovec iov[kCrashIovSize]; | 790 struct kernel_iovec iov[kCrashIovSize]; |
| 807 iov[0].iov_base = const_cast<void*>(crash_context); | 791 iov[0].iov_base = const_cast<void*>(crash_context); |
| 808 iov[0].iov_len = crash_context_size; | 792 iov[0].iov_len = crash_context_size; |
| 809 iov[1].iov_base = distro; | 793 iov[1].iov_base = &b_addr; |
| 810 iov[1].iov_len = kDistroSize + 1; | 794 iov[1].iov_len = sizeof(b_addr); |
| 811 iov[2].iov_base = &b_addr; | 795 iov[2].iov_base = &fds[0]; |
| 812 iov[2].iov_len = sizeof(b_addr); | 796 iov[2].iov_len = sizeof(fds[0]); |
| 813 iov[3].iov_base = &fds[0]; | 797 iov[3].iov_base = &g_process_start_time; |
| 814 iov[3].iov_len = sizeof(fds[0]); | 798 iov[3].iov_len = sizeof(g_process_start_time); |
| 815 iov[4].iov_base = &g_process_start_time; | 799 iov[4].iov_base = &base::g_oom_size; |
| 816 iov[4].iov_len = sizeof(g_process_start_time); | 800 iov[4].iov_len = sizeof(base::g_oom_size); |
| 817 iov[5].iov_base = &base::g_oom_size; | |
| 818 iov[5].iov_len = sizeof(base::g_oom_size); | |
| 819 google_breakpad::SerializedNonAllocatingMap* serialized_map; | 801 google_breakpad::SerializedNonAllocatingMap* serialized_map; |
| 820 iov[6].iov_len = g_crash_keys->Serialize( | 802 iov[5].iov_len = g_crash_keys->Serialize( |
| 821 const_cast<const google_breakpad::SerializedNonAllocatingMap**>( | 803 const_cast<const google_breakpad::SerializedNonAllocatingMap**>( |
| 822 &serialized_map)); | 804 &serialized_map)); |
| 823 iov[6].iov_base = serialized_map; | 805 iov[5].iov_base = serialized_map; |
| 824 #if defined(ADDRESS_SANITIZER) | 806 #if !defined(ADDRESS_SANITIZER) |
| 825 iov[7].iov_base = const_cast<char*>(g_asan_report_str); | 807 COMPILE_ASSERT(5 == kCrashIovSize - 1, Incorrect_Number_Of_Iovec_Members); |
| 826 iov[7].iov_len = kMaxAsanReportSize + 1; | 808 #else |
| 809 iov[6].iov_base = const_cast<char*>(g_asan_report_str); |
| 810 iov[6].iov_len = kMaxAsanReportSize + 1; |
| 811 COMPILE_ASSERT(6 == kCrashIovSize - 1, Incorrect_Number_Of_Iovec_Members); |
| 827 #endif | 812 #endif |
| 828 | 813 |
| 829 msg.msg_iov = iov; | 814 msg.msg_iov = iov; |
| 830 msg.msg_iovlen = kCrashIovSize; | 815 msg.msg_iovlen = kCrashIovSize; |
| 831 char cmsg[kControlMsgSpaceSize]; | 816 char cmsg[kControlMsgSpaceSize]; |
| 832 my_memset(cmsg, 0, kControlMsgSpaceSize); | 817 my_memset(cmsg, 0, kControlMsgSpaceSize); |
| 833 msg.msg_control = cmsg; | 818 msg.msg_control = cmsg; |
| 834 msg.msg_controllen = sizeof(cmsg); | 819 msg.msg_controllen = sizeof(cmsg); |
| 835 | 820 |
| 836 struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); | 821 struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1628 } | 1613 } |
| 1629 } | 1614 } |
| 1630 } | 1615 } |
| 1631 #endif // OS_ANDROID | 1616 #endif // OS_ANDROID |
| 1632 | 1617 |
| 1633 bool IsCrashReporterEnabled() { | 1618 bool IsCrashReporterEnabled() { |
| 1634 return g_is_crash_reporter_enabled; | 1619 return g_is_crash_reporter_enabled; |
| 1635 } | 1620 } |
| 1636 | 1621 |
| 1637 } // namespace breakpad | 1622 } // namespace breakpad |
| OLD | NEW |