[email protected] | c83dd91 | 2010-04-06 18:50:51 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 5 | #include "chrome/browser/crash_handler_host_linux.h" |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 6 | |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 7 | #include <stdint.h> |
[email protected] | 85ebe8f | 2009-10-29 04:02:55 | [diff] [blame] | 8 | #include <stdlib.h> |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 9 | #include <sys/socket.h> |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 10 | #include <sys/syscall.h> |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 11 | #include <sys/types.h> |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 12 | #include <unistd.h> |
| 13 | |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 14 | #include "base/eintr_wrapper.h" |
[email protected] | cbd5fd5 | 2009-08-26 00:14:27 | [diff] [blame] | 15 | #include "base/file_path.h" |
[email protected] | c725d792 | 2009-06-30 00:05:08 | [diff] [blame] | 16 | #include "base/format_macros.h" |
[email protected] | 85ebe8f | 2009-10-29 04:02:55 | [diff] [blame] | 17 | #include "base/linux_util.h" |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 18 | #include "base/logging.h" |
| 19 | #include "base/message_loop.h" |
[email protected] | cbd5fd5 | 2009-08-26 00:14:27 | [diff] [blame] | 20 | #include "base/path_service.h" |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 21 | #include "base/rand_util.h" |
| 22 | #include "base/string_util.h" |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 23 | #include "base/task.h" |
| 24 | #include "base/thread.h" |
[email protected] | b07fc511 | 2009-12-02 01:55:06 | [diff] [blame] | 25 | #include "breakpad/src/client/linux/handler/exception_handler.h" |
| 26 | #include "breakpad/src/client/linux/minidump_writer/linux_dumper.h" |
| 27 | #include "breakpad/src/client/linux/minidump_writer/minidump_writer.h" |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 28 | #include "chrome/app/breakpad_linux.h" |
[email protected] | ed7e6dd | 2010-10-12 02:02:45 | [diff] [blame] | 29 | #include "chrome/browser/browser_thread.h" |
[email protected] | cbd5fd5 | 2009-08-26 00:14:27 | [diff] [blame] | 30 | #include "chrome/common/chrome_paths.h" |
[email protected] | 99ca9a1 | 2010-03-12 18:32:10 | [diff] [blame] | 31 | #include "chrome/common/env_vars.h" |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 32 | |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 33 | using google_breakpad::ExceptionHandler; |
| 34 | |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 35 | namespace { |
| 36 | |
| 37 | // Handles the crash dump and frees the allocated BreakpadInfo struct. |
[email protected] | ca77966 | 2010-11-11 23:28:43 | [diff] [blame] | 38 | void CrashDumpTask(CrashHandlerHostLinux* handler, BreakpadInfo* info) { |
| 39 | if (handler->IsShuttingDown()) |
| 40 | return; |
| 41 | |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 42 | HandleCrashDump(*info); |
| 43 | delete[] info->filename; |
| 44 | delete[] info->process_type; |
| 45 | delete[] info->crash_url; |
| 46 | delete[] info->guid; |
| 47 | delete[] info->distro; |
| 48 | delete info; |
| 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 53 | // Since classes derived from CrashHandlerHostLinux are singletons, it's only |
| 54 | // destroyed at the end of the processes lifetime, which is greater in span than |
| 55 | // the lifetime of the IO message loop. |
[email protected] | c56428f2 | 2010-06-16 02:17:23 | [diff] [blame] | 56 | DISABLE_RUNNABLE_METHOD_REFCOUNT(CrashHandlerHostLinux); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 57 | |
[email protected] | ca77966 | 2010-11-11 23:28:43 | [diff] [blame] | 58 | CrashHandlerHostLinux::CrashHandlerHostLinux() |
| 59 | : shutting_down_(false) { |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 60 | int fds[2]; |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 61 | // We use SOCK_SEQPACKET rather than SOCK_DGRAM to prevent the process from |
[email protected] | 54730a1 | 2009-10-07 22:55:48 | [diff] [blame] | 62 | // sending datagrams to other sockets on the system. The sandbox may prevent |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 63 | // the process from calling socket() to create new sockets, but it'll still |
[email protected] | 54730a1 | 2009-10-07 22:55:48 | [diff] [blame] | 64 | // inherit some sockets. With PF_UNIX+SOCK_DGRAM, it can call sendmsg to send |
| 65 | // a datagram to any (abstract) socket on the same system. With |
| 66 | // SOCK_SEQPACKET, this is prevented. |
[email protected] | c83dd91 | 2010-04-06 18:50:51 | [diff] [blame] | 67 | CHECK_EQ(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds), 0); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 68 | static const int on = 1; |
| 69 | |
| 70 | // Enable passcred on the server end of the socket |
[email protected] | c83dd91 | 2010-04-06 18:50:51 | [diff] [blame] | 71 | CHECK_EQ(setsockopt(fds[1], SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)), 0); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 72 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 73 | process_socket_ = fds[0]; |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 74 | browser_socket_ = fds[1]; |
| 75 | |
[email protected] | d04e766 | 2010-10-10 22:24:48 | [diff] [blame] | 76 | BrowserThread::PostTask( |
| 77 | BrowserThread::IO, FROM_HERE, |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 78 | NewRunnableMethod(this, &CrashHandlerHostLinux::Init)); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 79 | } |
| 80 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 81 | CrashHandlerHostLinux::~CrashHandlerHostLinux() { |
| 82 | HANDLE_EINTR(close(process_socket_)); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 83 | HANDLE_EINTR(close(browser_socket_)); |
| 84 | } |
| 85 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 86 | void CrashHandlerHostLinux::Init() { |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 87 | MessageLoopForIO* ml = MessageLoopForIO::current(); |
| 88 | CHECK(ml->WatchFileDescriptor( |
| 89 | browser_socket_, true /* persistent */, |
| 90 | MessageLoopForIO::WATCH_READ, |
| 91 | &file_descriptor_watcher_, this)); |
| 92 | ml->AddDestructionObserver(this); |
| 93 | } |
| 94 | |
[email protected] | 19eef06 | 2010-09-16 19:44:09 | [diff] [blame] | 95 | void CrashHandlerHostLinux::InitCrashUploaderThread() { |
| 96 | SetProcessType(); |
| 97 | uploader_thread_.reset( |
| 98 | new base::Thread(std::string(process_type_ + "_crash_uploader").c_str())); |
| 99 | uploader_thread_->Start(); |
| 100 | } |
| 101 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 102 | void CrashHandlerHostLinux::OnFileCanWriteWithoutBlocking(int fd) { |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 103 | DCHECK(false); |
| 104 | } |
| 105 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 106 | void CrashHandlerHostLinux::OnFileCanReadWithoutBlocking(int fd) { |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 107 | DCHECK_EQ(fd, browser_socket_); |
| 108 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 109 | // A process has crashed and has signaled us by writing a datagram |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 110 | // to the death signal socket. The datagram contains the crash context needed |
| 111 | // for writing the minidump as well as a file descriptor and a credentials |
| 112 | // block so that they can't lie about their pid. |
| 113 | |
| 114 | // The length of the control message: |
| 115 | static const unsigned kControlMsgSize = |
[email protected] | 603e195 | 2010-08-11 06:44:30 | [diff] [blame] | 116 | CMSG_SPACE(2*sizeof(int)) + CMSG_SPACE(sizeof(struct ucred)); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 117 | // The length of the regular payload: |
| 118 | static const unsigned kCrashContextSize = |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 119 | sizeof(ExceptionHandler::CrashContext); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 120 | |
[email protected] | c7b1d2f | 2010-12-03 03:33:13 | [diff] [blame^] | 121 | const size_t kIovSize = 7; |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 122 | struct msghdr msg = {0}; |
[email protected] | c7b1d2f | 2010-12-03 03:33:13 | [diff] [blame^] | 123 | struct iovec iov[kIovSize]; |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 124 | char crash_context[kCrashContextSize]; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 125 | char* guid = new char[kGuidSize + 1]; |
| 126 | char* crash_url = new char[kMaxActiveURLSize + 1]; |
| 127 | char* distro = new char[kDistroSize + 1]; |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 128 | char* tid_buf_addr = NULL; |
| 129 | int tid_fd = -1; |
[email protected] | c7b1d2f | 2010-12-03 03:33:13 | [diff] [blame^] | 130 | uint64_t uptime; |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 131 | char control[kControlMsgSize]; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 132 | const ssize_t expected_msg_size = sizeof(crash_context) + |
| 133 | kGuidSize + 1 + |
| 134 | kMaxActiveURLSize + 1 + |
| 135 | kDistroSize + 1 + |
[email protected] | c7b1d2f | 2010-12-03 03:33:13 | [diff] [blame^] | 136 | sizeof(tid_buf_addr) + sizeof(tid_fd) + |
| 137 | sizeof(uptime); |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 138 | |
| 139 | iov[0].iov_base = crash_context; |
| 140 | iov[0].iov_len = sizeof(crash_context); |
| 141 | iov[1].iov_base = guid; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 142 | iov[1].iov_len = kGuidSize + 1; |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 143 | iov[2].iov_base = crash_url; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 144 | iov[2].iov_len = kMaxActiveURLSize + 1; |
[email protected] | 912c645 | 2009-07-17 05:55:51 | [diff] [blame] | 145 | iov[3].iov_base = distro; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 146 | iov[3].iov_len = kDistroSize + 1; |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 147 | iov[4].iov_base = &tid_buf_addr; |
| 148 | iov[4].iov_len = sizeof(tid_buf_addr); |
| 149 | iov[5].iov_base = &tid_fd; |
| 150 | iov[5].iov_len = sizeof(tid_fd); |
[email protected] | c7b1d2f | 2010-12-03 03:33:13 | [diff] [blame^] | 151 | iov[6].iov_base = &uptime; |
| 152 | iov[6].iov_len = sizeof(uptime); |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 153 | msg.msg_iov = iov; |
[email protected] | c7b1d2f | 2010-12-03 03:33:13 | [diff] [blame^] | 154 | msg.msg_iovlen = kIovSize; |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 155 | msg.msg_control = control; |
| 156 | msg.msg_controllen = kControlMsgSize; |
| 157 | |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 158 | const ssize_t msg_size = HANDLE_EINTR(recvmsg(browser_socket_, &msg, 0)); |
| 159 | if (msg_size != expected_msg_size) { |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 160 | LOG(ERROR) << "Error reading from death signal socket. Crash dumping" |
| 161 | << " is disabled." |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 162 | << " msg_size:" << msg_size |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 163 | << " errno:" << errno; |
| 164 | file_descriptor_watcher_.StopWatchingFileDescriptor(); |
| 165 | return; |
| 166 | } |
| 167 | |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 168 | if (msg.msg_controllen != kControlMsgSize || |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 169 | msg.msg_flags & ~MSG_TRUNC) { |
| 170 | LOG(ERROR) << "Received death signal message with the wrong size;" |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 171 | << " msg.msg_controllen:" << msg.msg_controllen |
| 172 | << " msg.msg_flags:" << msg.msg_flags |
| 173 | << " kCrashContextSize:" << kCrashContextSize |
| 174 | << " kControlMsgSize:" << kControlMsgSize; |
| 175 | return; |
| 176 | } |
| 177 | |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 178 | // Walk the control payload an extract the file descriptor and validated pid. |
| 179 | pid_t crashing_pid = -1; |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 180 | int partner_fd = -1; |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 181 | int signal_fd = -1; |
| 182 | for (struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); hdr; |
| 183 | hdr = CMSG_NXTHDR(&msg, hdr)) { |
| 184 | if (hdr->cmsg_level != SOL_SOCKET) |
| 185 | continue; |
| 186 | if (hdr->cmsg_type == SCM_RIGHTS) { |
| 187 | const unsigned len = hdr->cmsg_len - |
| 188 | (((uint8_t*)CMSG_DATA(hdr)) - (uint8_t*)hdr); |
[email protected] | 912c645 | 2009-07-17 05:55:51 | [diff] [blame] | 189 | DCHECK_EQ(len % sizeof(int), 0u); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 190 | const unsigned num_fds = len / sizeof(int); |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 191 | if (num_fds != 2) { |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 192 | // A nasty process could try and send us too many descriptors and |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 193 | // force a leak. |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 194 | LOG(ERROR) << "Death signal contained wrong number of descriptors;" |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 195 | << " num_fds:" << num_fds; |
| 196 | for (unsigned i = 0; i < num_fds; ++i) |
| 197 | HANDLE_EINTR(close(reinterpret_cast<int*>(CMSG_DATA(hdr))[i])); |
| 198 | return; |
| 199 | } else { |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 200 | partner_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[0]; |
| 201 | signal_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[1]; |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 202 | } |
| 203 | } else if (hdr->cmsg_type == SCM_CREDENTIALS) { |
| 204 | const struct ucred *cred = |
| 205 | reinterpret_cast<struct ucred*>(CMSG_DATA(hdr)); |
| 206 | crashing_pid = cred->pid; |
| 207 | } |
| 208 | } |
| 209 | |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 210 | if (crashing_pid == -1 || partner_fd == -1 || signal_fd == -1) { |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 211 | LOG(ERROR) << "Death signal message didn't contain all expected control" |
| 212 | << " messages"; |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 213 | if (partner_fd >= 0) |
| 214 | HANDLE_EINTR(close(partner_fd)); |
| 215 | if (signal_fd >= 0) |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 216 | HANDLE_EINTR(close(signal_fd)); |
| 217 | return; |
| 218 | } |
| 219 | |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 220 | // Kernel bug workaround (broken in 2.6.30 at least): |
| 221 | // The kernel doesn't translate PIDs in SCM_CREDENTIALS across PID |
| 222 | // namespaces. Thus |crashing_pid| might be garbage from our point of view. |
| 223 | // In the future we can remove this workaround, but we have to wait a couple |
| 224 | // of years to be sure that it's worked its way out into the world. |
| 225 | |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 226 | // The crashing process closes its copy of the signal_fd immediately after |
| 227 | // calling sendmsg(). We can thus not reliably look for with with |
| 228 | // FindProcessHoldingSocket(). But by necessity, it has to keep the |
| 229 | // partner_fd open until the crashdump is complete. |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 230 | uint64_t inode_number; |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 231 | if (!base::FileDescriptorGetInode(&inode_number, partner_fd)) { |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 232 | LOG(WARNING) << "Failed to get inode number for passed socket"; |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 233 | HANDLE_EINTR(close(partner_fd)); |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 234 | HANDLE_EINTR(close(signal_fd)); |
| 235 | return; |
| 236 | } |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 237 | HANDLE_EINTR(close(partner_fd)); |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 238 | |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 239 | pid_t actual_crashing_pid = -1; |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 240 | if (!base::FindProcessHoldingSocket(&actual_crashing_pid, inode_number)) { |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 241 | LOG(WARNING) << "Failed to find process holding other end of crash reply " |
| 242 | "socket"; |
| 243 | HANDLE_EINTR(close(signal_fd)); |
| 244 | return; |
| 245 | } |
[email protected] | 15e8577 | 2010-08-09 20:44:03 | [diff] [blame] | 246 | |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 247 | if (actual_crashing_pid != crashing_pid) { |
| 248 | crashing_pid = actual_crashing_pid; |
| 249 | |
| 250 | // The crashing TID set inside the compromised context via sys_gettid() |
| 251 | // in ExceptionHandler::HandleSignal is also wrong and needs to be |
| 252 | // translated. |
| 253 | // |
| 254 | // We expect the crashing thread to be in sys_read(), waiting for use to |
| 255 | // write to |signal_fd|. Most newer kernels where we have the different pid |
| 256 | // namespaces also have /proc/[pid]/syscall, so we can look through |
| 257 | // |actual_crashing_pid|'s thread group and find the thread that's in the |
| 258 | // read syscall with the right arguments. |
| 259 | |
| 260 | std::string expected_syscall_data; |
| 261 | // /proc/[pid]/syscall is formatted as follows: |
| 262 | // syscall_number arg1 ... arg6 sp pc |
| 263 | // but we just check syscall_number through arg3. |
[email protected] | a77fa2dc | 2010-11-15 12:11:11 | [diff] [blame] | 264 | base::StringAppendF(&expected_syscall_data, "%d 0x%x %p 0x1 ", |
| 265 | SYS_read, tid_fd, tid_buf_addr); |
[email protected] | 66218314 | 2010-07-16 19:28:17 | [diff] [blame] | 266 | pid_t crashing_tid = |
| 267 | base::FindThreadIDWithSyscall(crashing_pid, expected_syscall_data); |
| 268 | if (crashing_tid == -1) { |
| 269 | // We didn't find the thread we want. Maybe it didn't reach sys_read() |
| 270 | // yet, or the kernel doesn't support /proc/[pid]/syscall or the thread |
| 271 | // went away. We'll just take a guess here and assume the crashing |
| 272 | // thread is the thread group leader. |
| 273 | crashing_tid = crashing_pid; |
| 274 | } |
| 275 | |
| 276 | ExceptionHandler::CrashContext* bad_context = |
| 277 | reinterpret_cast<ExceptionHandler::CrashContext*>(crash_context); |
| 278 | bad_context->tid = crashing_tid; |
| 279 | } |
[email protected] | 4378a82 | 2009-07-08 01:15:14 | [diff] [blame] | 280 | |
[email protected] | cbd5fd5 | 2009-08-26 00:14:27 | [diff] [blame] | 281 | bool upload = true; |
| 282 | FilePath dumps_path("/tmp"); |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 283 | PathService::Get(base::DIR_TEMP, &dumps_path); |
[email protected] | c83dd91 | 2010-04-06 18:50:51 | [diff] [blame] | 284 | if (getenv(env_vars::kHeadless)) { |
[email protected] | cbd5fd5 | 2009-08-26 00:14:27 | [diff] [blame] | 285 | upload = false; |
| 286 | PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
| 287 | } |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 288 | const uint64 rand = base::RandUint64(); |
| 289 | const std::string minidump_filename = |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 290 | StringPrintf("%s/chromium-%s-minidump-%016" PRIx64 ".dmp", |
| 291 | dumps_path.value().c_str(), process_type_.c_str(), rand); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 292 | if (!google_breakpad::WriteMinidump(minidump_filename.c_str(), |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 293 | crashing_pid, crash_context, |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 294 | kCrashContextSize)) { |
| 295 | LOG(ERROR) << "Failed to write crash dump for pid " << crashing_pid; |
| 296 | HANDLE_EINTR(close(signal_fd)); |
| 297 | } |
| 298 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 299 | // Send the done signal to the process: it can exit now. |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 300 | memset(&msg, 0, sizeof(msg)); |
[email protected] | 2eb41e7 | 2009-07-15 23:07:34 | [diff] [blame] | 301 | struct iovec done_iov; |
| 302 | done_iov.iov_base = const_cast<char*>("\x42"); |
| 303 | done_iov.iov_len = 1; |
| 304 | msg.msg_iov = &done_iov; |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 305 | msg.msg_iovlen = 1; |
| 306 | |
| 307 | HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL)); |
| 308 | HANDLE_EINTR(close(signal_fd)); |
| 309 | |
[email protected] | 9ddbcd9 | 2009-09-23 21:27:43 | [diff] [blame] | 310 | // Sanitize the string data a bit more |
| 311 | guid[kGuidSize] = crash_url[kMaxActiveURLSize] = distro[kDistroSize] = 0; |
| 312 | |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 313 | BreakpadInfo* info = new BreakpadInfo; |
| 314 | |
| 315 | char* minidump_filename_str = new char[minidump_filename.length() + 1]; |
| 316 | minidump_filename.copy(minidump_filename_str, minidump_filename.length()); |
| 317 | minidump_filename_str[minidump_filename.length()] = '\0'; |
| 318 | info->filename = minidump_filename_str; |
| 319 | |
| 320 | info->process_type_length = process_type_.length(); |
| 321 | char* process_type_str = new char[info->process_type_length + 1]; |
| 322 | process_type_.copy(process_type_str, info->process_type_length); |
| 323 | process_type_str[info->process_type_length] = '\0'; |
| 324 | info->process_type = process_type_str; |
| 325 | |
| 326 | info->crash_url_length = strlen(crash_url); |
| 327 | info->crash_url = crash_url; |
| 328 | |
| 329 | info->guid_length = strlen(guid); |
| 330 | info->guid = guid; |
| 331 | |
| 332 | info->distro_length = strlen(distro); |
| 333 | info->distro = distro; |
| 334 | |
| 335 | info->upload = upload; |
[email protected] | c7b1d2f | 2010-12-03 03:33:13 | [diff] [blame^] | 336 | info->process_start_time = uptime; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 337 | |
| 338 | uploader_thread_->message_loop()->PostTask( |
| 339 | FROM_HERE, |
[email protected] | ca77966 | 2010-11-11 23:28:43 | [diff] [blame] | 340 | NewRunnableFunction(&CrashDumpTask, this, info)); |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 341 | } |
| 342 | |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 343 | void CrashHandlerHostLinux::WillDestroyCurrentMessageLoop() { |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 344 | file_descriptor_watcher_.StopWatchingFileDescriptor(); |
[email protected] | ca77966 | 2010-11-11 23:28:43 | [diff] [blame] | 345 | |
| 346 | // If we are quitting and there are crash dumps in the queue, turn them into |
| 347 | // no-ops. |
| 348 | shutting_down_ = true; |
| 349 | uploader_thread_->Stop(); |
| 350 | } |
| 351 | |
| 352 | bool CrashHandlerHostLinux::IsShuttingDown() const { |
| 353 | return shutting_down_; |
[email protected] | 9a5d2a5 | 2009-05-22 03:37:45 | [diff] [blame] | 354 | } |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 355 | |
| 356 | PluginCrashHandlerHostLinux::PluginCrashHandlerHostLinux() { |
[email protected] | 19eef06 | 2010-09-16 19:44:09 | [diff] [blame] | 357 | InitCrashUploaderThread(); |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | PluginCrashHandlerHostLinux::~PluginCrashHandlerHostLinux() { |
| 361 | } |
| 362 | |
| 363 | void PluginCrashHandlerHostLinux::SetProcessType() { |
| 364 | process_type_ = "plugin"; |
| 365 | } |
| 366 | |
| 367 | RendererCrashHandlerHostLinux::RendererCrashHandlerHostLinux() { |
[email protected] | 19eef06 | 2010-09-16 19:44:09 | [diff] [blame] | 368 | InitCrashUploaderThread(); |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | RendererCrashHandlerHostLinux::~RendererCrashHandlerHostLinux() { |
| 372 | } |
| 373 | |
| 374 | void RendererCrashHandlerHostLinux::SetProcessType() { |
| 375 | process_type_ = "renderer"; |
| 376 | } |