blob: 98277749cc9c929829c64abab3a4daa9f18fc7f1 [file] [log] [blame]
[email protected]6a033592012-03-23 00:08:541// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]9a5d2a52009-05-22 03:37:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]6653c192012-04-10 22:52:445#include "chrome/browser/crash_handler_host_linuxish.h"
[email protected]9a5d2a52009-05-22 03:37:456
[email protected]9a5d2a52009-05-22 03:37:457#include <stdint.h>
[email protected]85ebe8f2009-10-29 04:02:558#include <stdlib.h>
[email protected]9a5d2a52009-05-22 03:37:459#include <sys/socket.h>
[email protected]662183142010-07-16 19:28:1710#include <sys/syscall.h>
[email protected]4378a822009-07-08 01:15:1411#include <unistd.h>
12
[email protected]69eb91122011-11-22 21:44:2213#include "base/bind.h"
14#include "base/bind_helpers.h"
[email protected]9a5d2a52009-05-22 03:37:4515#include "base/eintr_wrapper.h"
[email protected]cbd5fd52009-08-26 00:14:2716#include "base/file_path.h"
[email protected]c725d7922009-06-30 00:05:0817#include "base/format_macros.h"
[email protected]85ebe8f2009-10-29 04:02:5518#include "base/linux_util.h"
[email protected]9a5d2a52009-05-22 03:37:4519#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1520#include "base/memory/singleton.h"
[email protected]9a5d2a52009-05-22 03:37:4521#include "base/message_loop.h"
[email protected]cbd5fd52009-08-26 00:14:2722#include "base/path_service.h"
[email protected]9a5d2a52009-05-22 03:37:4523#include "base/rand_util.h"
24#include "base/string_util.h"
[email protected]51ef8c12011-08-17 00:51:2125#include "base/stringprintf.h"
[email protected]34b99632011-01-01 01:01:0626#include "base/threading/thread.h"
[email protected]b07fc5112009-12-02 01:55:0627#include "breakpad/src/client/linux/handler/exception_handler.h"
28#include "breakpad/src/client/linux/minidump_writer/linux_dumper.h"
29#include "breakpad/src/client/linux/minidump_writer/minidump_writer.h"
[email protected]6653c192012-04-10 22:52:4430#include "chrome/app/breakpad_linuxish.h"
[email protected]cbd5fd52009-08-26 00:14:2731#include "chrome/common/chrome_paths.h"
[email protected]99ca9a12010-03-12 18:32:1032#include "chrome/common/env_vars.h"
[email protected]c38831a12011-10-28 12:44:4933#include "content/public/browser/browser_thread.h"
[email protected]9a5d2a52009-05-22 03:37:4534
[email protected]6653c192012-04-10 22:52:4435#if defined(OS_ANDROID)
36#include <sys/linux-syscalls.h>
37
38#define SYS_read __NR_read
39#endif
40
[email protected]631bb742011-11-02 11:29:3941using content::BrowserThread;
[email protected]662183142010-07-16 19:28:1742using google_breakpad::ExceptionHandler;
43
[email protected]b064f0eb2010-09-02 23:53:2644namespace {
45
[email protected]154cbabd2011-02-17 23:01:5746// The length of the control message:
47const unsigned kControlMsgSize =
48 CMSG_SPACE(2*sizeof(int)) + CMSG_SPACE(sizeof(struct ucred));
49// The length of the regular payload:
50const unsigned kCrashContextSize = sizeof(ExceptionHandler::CrashContext);
51
[email protected]b064f0eb2010-09-02 23:53:2652// Handles the crash dump and frees the allocated BreakpadInfo struct.
[email protected]ca779662010-11-11 23:28:4353void CrashDumpTask(CrashHandlerHostLinux* handler, BreakpadInfo* info) {
54 if (handler->IsShuttingDown())
55 return;
56
[email protected]b064f0eb2010-09-02 23:53:2657 HandleCrashDump(*info);
58 delete[] info->filename;
59 delete[] info->process_type;
60 delete[] info->crash_url;
61 delete[] info->guid;
62 delete[] info->distro;
63 delete info;
64}
65
66} // namespace
67
[email protected]2456c572009-11-09 04:21:5168// Since classes derived from CrashHandlerHostLinux are singletons, it's only
69// destroyed at the end of the processes lifetime, which is greater in span than
[email protected]69eb91122011-11-22 21:44:2270// the lifetime of the IO message loop. Thus, all calls to base::Bind() use
71// non-refcounted pointers.
[email protected]9a5d2a52009-05-22 03:37:4572
[email protected]ca779662010-11-11 23:28:4373CrashHandlerHostLinux::CrashHandlerHostLinux()
74 : shutting_down_(false) {
[email protected]9a5d2a52009-05-22 03:37:4575 int fds[2];
[email protected]2456c572009-11-09 04:21:5176 // We use SOCK_SEQPACKET rather than SOCK_DGRAM to prevent the process from
[email protected]54730a12009-10-07 22:55:4877 // sending datagrams to other sockets on the system. The sandbox may prevent
[email protected]2456c572009-11-09 04:21:5178 // the process from calling socket() to create new sockets, but it'll still
[email protected]54730a12009-10-07 22:55:4879 // inherit some sockets. With PF_UNIX+SOCK_DGRAM, it can call sendmsg to send
80 // a datagram to any (abstract) socket on the same system. With
81 // SOCK_SEQPACKET, this is prevented.
[email protected]c83dd912010-04-06 18:50:5182 CHECK_EQ(socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds), 0);
[email protected]9a5d2a52009-05-22 03:37:4583 static const int on = 1;
84
85 // Enable passcred on the server end of the socket
[email protected]c83dd912010-04-06 18:50:5186 CHECK_EQ(setsockopt(fds[1], SOL_SOCKET, SO_PASSCRED, &on, sizeof(on)), 0);
[email protected]9a5d2a52009-05-22 03:37:4587
[email protected]2456c572009-11-09 04:21:5188 process_socket_ = fds[0];
[email protected]9a5d2a52009-05-22 03:37:4589 browser_socket_ = fds[1];
90
[email protected]d04e7662010-10-10 22:24:4891 BrowserThread::PostTask(
92 BrowserThread::IO, FROM_HERE,
[email protected]69eb91122011-11-22 21:44:2293 base::Bind(&CrashHandlerHostLinux::Init, base::Unretained(this)));
[email protected]9a5d2a52009-05-22 03:37:4594}
95
[email protected]2456c572009-11-09 04:21:5196CrashHandlerHostLinux::~CrashHandlerHostLinux() {
[email protected]d997c442012-05-07 22:11:1997 (void) HANDLE_EINTR(close(process_socket_));
98 (void) HANDLE_EINTR(close(browser_socket_));
[email protected]9a5d2a52009-05-22 03:37:4599}
100
[email protected]2456c572009-11-09 04:21:51101void CrashHandlerHostLinux::Init() {
[email protected]9a5d2a52009-05-22 03:37:45102 MessageLoopForIO* ml = MessageLoopForIO::current();
103 CHECK(ml->WatchFileDescriptor(
104 browser_socket_, true /* persistent */,
105 MessageLoopForIO::WATCH_READ,
106 &file_descriptor_watcher_, this));
107 ml->AddDestructionObserver(this);
108}
109
[email protected]19eef062010-09-16 19:44:09110void CrashHandlerHostLinux::InitCrashUploaderThread() {
111 SetProcessType();
112 uploader_thread_.reset(
113 new base::Thread(std::string(process_type_ + "_crash_uploader").c_str()));
114 uploader_thread_->Start();
115}
116
[email protected]2456c572009-11-09 04:21:51117void CrashHandlerHostLinux::OnFileCanWriteWithoutBlocking(int fd) {
[email protected]6a033592012-03-23 00:08:54118 NOTREACHED();
[email protected]9a5d2a52009-05-22 03:37:45119}
120
[email protected]2456c572009-11-09 04:21:51121void CrashHandlerHostLinux::OnFileCanReadWithoutBlocking(int fd) {
[email protected]9a5d2a52009-05-22 03:37:45122 DCHECK_EQ(fd, browser_socket_);
123
[email protected]2456c572009-11-09 04:21:51124 // A process has crashed and has signaled us by writing a datagram
[email protected]9a5d2a52009-05-22 03:37:45125 // to the death signal socket. The datagram contains the crash context needed
126 // for writing the minidump as well as a file descriptor and a credentials
127 // block so that they can't lie about their pid.
[email protected]6a033592012-03-23 00:08:54128 //
129 // The message sender is in chrome/app/breakpad_linux.cc.
[email protected]9a5d2a52009-05-22 03:37:45130
[email protected]6a033592012-03-23 00:08:54131 const size_t kIovSize = 8;
[email protected]9a5d2a52009-05-22 03:37:45132 struct msghdr msg = {0};
[email protected]c7b1d2f2010-12-03 03:33:13133 struct iovec iov[kIovSize];
[email protected]c468f9492011-04-15 20:56:37134
135 // Freed in WriteDumpFile();
136 char* crash_context = new char[kCrashContextSize];
137 // Freed in CrashDumpTask();
[email protected]b064f0eb2010-09-02 23:53:26138 char* guid = new char[kGuidSize + 1];
139 char* crash_url = new char[kMaxActiveURLSize + 1];
140 char* distro = new char[kDistroSize + 1];
[email protected]c468f9492011-04-15 20:56:37141
[email protected]662183142010-07-16 19:28:17142 char* tid_buf_addr = NULL;
143 int tid_fd = -1;
[email protected]c7b1d2f2010-12-03 03:33:13144 uint64_t uptime;
[email protected]6a033592012-03-23 00:08:54145 size_t oom_size;
[email protected]9a5d2a52009-05-22 03:37:45146 char control[kControlMsgSize];
[email protected]c468f9492011-04-15 20:56:37147 const ssize_t expected_msg_size =
148 kCrashContextSize +
[email protected]b064f0eb2010-09-02 23:53:26149 kGuidSize + 1 +
150 kMaxActiveURLSize + 1 +
151 kDistroSize + 1 +
[email protected]c7b1d2f2010-12-03 03:33:13152 sizeof(tid_buf_addr) + sizeof(tid_fd) +
[email protected]6a033592012-03-23 00:08:54153 sizeof(uptime) +
154 sizeof(oom_size);
[email protected]2eb41e72009-07-15 23:07:34155
156 iov[0].iov_base = crash_context;
[email protected]c468f9492011-04-15 20:56:37157 iov[0].iov_len = kCrashContextSize;
[email protected]2eb41e72009-07-15 23:07:34158 iov[1].iov_base = guid;
[email protected]b064f0eb2010-09-02 23:53:26159 iov[1].iov_len = kGuidSize + 1;
[email protected]2eb41e72009-07-15 23:07:34160 iov[2].iov_base = crash_url;
[email protected]b064f0eb2010-09-02 23:53:26161 iov[2].iov_len = kMaxActiveURLSize + 1;
[email protected]912c6452009-07-17 05:55:51162 iov[3].iov_base = distro;
[email protected]b064f0eb2010-09-02 23:53:26163 iov[3].iov_len = kDistroSize + 1;
[email protected]662183142010-07-16 19:28:17164 iov[4].iov_base = &tid_buf_addr;
165 iov[4].iov_len = sizeof(tid_buf_addr);
166 iov[5].iov_base = &tid_fd;
167 iov[5].iov_len = sizeof(tid_fd);
[email protected]c7b1d2f2010-12-03 03:33:13168 iov[6].iov_base = &uptime;
169 iov[6].iov_len = sizeof(uptime);
[email protected]6a033592012-03-23 00:08:54170 iov[7].iov_base = &oom_size;
171 iov[7].iov_len = sizeof(oom_size);
[email protected]2eb41e72009-07-15 23:07:34172 msg.msg_iov = iov;
[email protected]c7b1d2f2010-12-03 03:33:13173 msg.msg_iovlen = kIovSize;
[email protected]9a5d2a52009-05-22 03:37:45174 msg.msg_control = control;
175 msg.msg_controllen = kControlMsgSize;
176
[email protected]2eb41e72009-07-15 23:07:34177 const ssize_t msg_size = HANDLE_EINTR(recvmsg(browser_socket_, &msg, 0));
178 if (msg_size != expected_msg_size) {
[email protected]9a5d2a52009-05-22 03:37:45179 LOG(ERROR) << "Error reading from death signal socket. Crash dumping"
180 << " is disabled."
[email protected]2eb41e72009-07-15 23:07:34181 << " msg_size:" << msg_size
[email protected]9a5d2a52009-05-22 03:37:45182 << " errno:" << errno;
183 file_descriptor_watcher_.StopWatchingFileDescriptor();
184 return;
185 }
186
[email protected]2eb41e72009-07-15 23:07:34187 if (msg.msg_controllen != kControlMsgSize ||
[email protected]9a5d2a52009-05-22 03:37:45188 msg.msg_flags & ~MSG_TRUNC) {
189 LOG(ERROR) << "Received death signal message with the wrong size;"
[email protected]9a5d2a52009-05-22 03:37:45190 << " msg.msg_controllen:" << msg.msg_controllen
191 << " msg.msg_flags:" << msg.msg_flags
192 << " kCrashContextSize:" << kCrashContextSize
193 << " kControlMsgSize:" << kControlMsgSize;
194 return;
195 }
196
[email protected]9a5d2a52009-05-22 03:37:45197 // Walk the control payload an extract the file descriptor and validated pid.
198 pid_t crashing_pid = -1;
[email protected]15e85772010-08-09 20:44:03199 int partner_fd = -1;
[email protected]9a5d2a52009-05-22 03:37:45200 int signal_fd = -1;
201 for (struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); hdr;
202 hdr = CMSG_NXTHDR(&msg, hdr)) {
203 if (hdr->cmsg_level != SOL_SOCKET)
204 continue;
205 if (hdr->cmsg_type == SCM_RIGHTS) {
206 const unsigned len = hdr->cmsg_len -
207 (((uint8_t*)CMSG_DATA(hdr)) - (uint8_t*)hdr);
[email protected]912c6452009-07-17 05:55:51208 DCHECK_EQ(len % sizeof(int), 0u);
[email protected]9a5d2a52009-05-22 03:37:45209 const unsigned num_fds = len / sizeof(int);
[email protected]15e85772010-08-09 20:44:03210 if (num_fds != 2) {
[email protected]2456c572009-11-09 04:21:51211 // A nasty process could try and send us too many descriptors and
[email protected]9a5d2a52009-05-22 03:37:45212 // force a leak.
[email protected]15e85772010-08-09 20:44:03213 LOG(ERROR) << "Death signal contained wrong number of descriptors;"
[email protected]9a5d2a52009-05-22 03:37:45214 << " num_fds:" << num_fds;
215 for (unsigned i = 0; i < num_fds; ++i)
[email protected]d997c442012-05-07 22:11:19216 (void) HANDLE_EINTR(close(reinterpret_cast<int*>(CMSG_DATA(hdr))[i]));
[email protected]9a5d2a52009-05-22 03:37:45217 return;
218 } else {
[email protected]15e85772010-08-09 20:44:03219 partner_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[0];
220 signal_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[1];
[email protected]9a5d2a52009-05-22 03:37:45221 }
222 } else if (hdr->cmsg_type == SCM_CREDENTIALS) {
223 const struct ucred *cred =
224 reinterpret_cast<struct ucred*>(CMSG_DATA(hdr));
225 crashing_pid = cred->pid;
226 }
227 }
228
[email protected]15e85772010-08-09 20:44:03229 if (crashing_pid == -1 || partner_fd == -1 || signal_fd == -1) {
[email protected]9a5d2a52009-05-22 03:37:45230 LOG(ERROR) << "Death signal message didn't contain all expected control"
231 << " messages";
[email protected]15e85772010-08-09 20:44:03232 if (partner_fd >= 0)
[email protected]d997c442012-05-07 22:11:19233 (void) HANDLE_EINTR(close(partner_fd));
[email protected]15e85772010-08-09 20:44:03234 if (signal_fd >= 0)
[email protected]d997c442012-05-07 22:11:19235 (void) HANDLE_EINTR(close(signal_fd));
[email protected]9a5d2a52009-05-22 03:37:45236 return;
237 }
238
[email protected]cb7d53e2011-06-21 04:21:06239 // Kernel bug workaround (broken in 2.6.30 and 2.6.32, working in 2.6.38).
[email protected]4378a822009-07-08 01:15:14240 // The kernel doesn't translate PIDs in SCM_CREDENTIALS across PID
241 // namespaces. Thus |crashing_pid| might be garbage from our point of view.
242 // In the future we can remove this workaround, but we have to wait a couple
243 // of years to be sure that it's worked its way out into the world.
[email protected]cb7d53e2011-06-21 04:21:06244 // TODO(thestig) Remove the workaround when Ubuntu Lucid is deprecated.
[email protected]4378a822009-07-08 01:15:14245
[email protected]15e85772010-08-09 20:44:03246 // The crashing process closes its copy of the signal_fd immediately after
247 // calling sendmsg(). We can thus not reliably look for with with
248 // FindProcessHoldingSocket(). But by necessity, it has to keep the
249 // partner_fd open until the crashdump is complete.
[email protected]4378a822009-07-08 01:15:14250 uint64_t inode_number;
[email protected]15e85772010-08-09 20:44:03251 if (!base::FileDescriptorGetInode(&inode_number, partner_fd)) {
[email protected]4378a822009-07-08 01:15:14252 LOG(WARNING) << "Failed to get inode number for passed socket";
[email protected]d997c442012-05-07 22:11:19253 (void) HANDLE_EINTR(close(partner_fd));
254 (void) HANDLE_EINTR(close(signal_fd));
[email protected]4378a822009-07-08 01:15:14255 return;
256 }
[email protected]d997c442012-05-07 22:11:19257 (void) HANDLE_EINTR(close(partner_fd));
[email protected]4378a822009-07-08 01:15:14258
[email protected]662183142010-07-16 19:28:17259 pid_t actual_crashing_pid = -1;
[email protected]15e85772010-08-09 20:44:03260 if (!base::FindProcessHoldingSocket(&actual_crashing_pid, inode_number)) {
[email protected]4378a822009-07-08 01:15:14261 LOG(WARNING) << "Failed to find process holding other end of crash reply "
262 "socket";
[email protected]d997c442012-05-07 22:11:19263 (void) HANDLE_EINTR(close(signal_fd));
[email protected]4378a822009-07-08 01:15:14264 return;
265 }
[email protected]15e85772010-08-09 20:44:03266
[email protected]cb7d53e2011-06-21 04:21:06267 crashing_pid = actual_crashing_pid;
[email protected]662183142010-07-16 19:28:17268
[email protected]cb7d53e2011-06-21 04:21:06269 // The crashing TID set inside the compromised context via
270 // sys_gettid() in ExceptionHandler::HandleSignal might be wrong (if
271 // the kernel supports PID namespacing) and may need to be
272 // translated.
273 //
274 // We expect the crashing thread to be in sys_read(), waiting for us to
275 // write to |signal_fd|. Most newer kernels where we have the different pid
276 // namespaces also have /proc/[pid]/syscall, so we can look through
277 // |actual_crashing_pid|'s thread group and find the thread that's in the
278 // read syscall with the right arguments.
[email protected]662183142010-07-16 19:28:17279
[email protected]cb7d53e2011-06-21 04:21:06280 std::string expected_syscall_data;
281 // /proc/[pid]/syscall is formatted as follows:
282 // syscall_number arg1 ... arg6 sp pc
283 // but we just check syscall_number through arg3.
284 base::StringAppendF(&expected_syscall_data, "%d 0x%x %p 0x1 ",
285 SYS_read, tid_fd, tid_buf_addr);
286 bool syscall_supported = false;
287 pid_t crashing_tid =
288 base::FindThreadIDWithSyscall(crashing_pid,
289 expected_syscall_data,
290 &syscall_supported);
[email protected]e02f1372011-10-06 21:24:37291 if (crashing_tid == -1) {
[email protected]cb7d53e2011-06-21 04:21:06292 // We didn't find the thread we want. Maybe it didn't reach
293 // sys_read() yet or the thread went away. We'll just take a
294 // guess here and assume the crashing thread is the thread group
295 // leader. If procfs syscall is not supported by the kernel, then
296 // we assume the kernel also does not support TID namespacing and
297 // trust the TID passed by the crashing process.
[email protected]e02f1372011-10-06 21:24:37298 LOG(WARNING) << "Could not translate tid - assuming crashing thread is "
299 "thread group leader; syscall_supported=" << syscall_supported;
[email protected]cb7d53e2011-06-21 04:21:06300 crashing_tid = crashing_pid;
[email protected]662183142010-07-16 19:28:17301 }
[email protected]4378a822009-07-08 01:15:14302
[email protected]cb7d53e2011-06-21 04:21:06303 ExceptionHandler::CrashContext* bad_context =
304 reinterpret_cast<ExceptionHandler::CrashContext*>(crash_context);
305 bad_context->tid = crashing_tid;
306
[email protected]9ddbcd92009-09-23 21:27:43307 // Sanitize the string data a bit more
308 guid[kGuidSize] = crash_url[kMaxActiveURLSize] = distro[kDistroSize] = 0;
309
[email protected]c468f9492011-04-15 20:56:37310 // Freed in CrashDumpTask();
[email protected]b064f0eb2010-09-02 23:53:26311 BreakpadInfo* info = new BreakpadInfo;
312
[email protected]b064f0eb2010-09-02 23:53:26313 info->process_type_length = process_type_.length();
314 char* process_type_str = new char[info->process_type_length + 1];
315 process_type_.copy(process_type_str, info->process_type_length);
316 process_type_str[info->process_type_length] = '\0';
317 info->process_type = process_type_str;
318
319 info->crash_url_length = strlen(crash_url);
320 info->crash_url = crash_url;
321
322 info->guid_length = strlen(guid);
323 info->guid = guid;
324
325 info->distro_length = strlen(distro);
326 info->distro = distro;
[email protected]6653c192012-04-10 22:52:44327#if defined(OS_ANDROID)
328 // Nothing gets uploaded in android.
329 info->upload = false;
330#else
[email protected]154cbabd2011-02-17 23:01:57331 info->upload = (getenv(env_vars::kHeadless) == NULL);
[email protected]6653c192012-04-10 22:52:44332#endif
[email protected]c7b1d2f2010-12-03 03:33:13333 info->process_start_time = uptime;
[email protected]6a033592012-03-23 00:08:54334 info->oom_size = oom_size;
[email protected]b064f0eb2010-09-02 23:53:26335
[email protected]154cbabd2011-02-17 23:01:57336 BrowserThread::PostTask(
337 BrowserThread::FILE, FROM_HERE,
[email protected]69eb91122011-11-22 21:44:22338 base::Bind(&CrashHandlerHostLinux::WriteDumpFile,
339 base::Unretained(this),
340 info,
341 crashing_pid,
342 crash_context,
343 signal_fd));
[email protected]154cbabd2011-02-17 23:01:57344}
345
346void CrashHandlerHostLinux::WriteDumpFile(BreakpadInfo* info,
347 pid_t crashing_pid,
348 char* crash_context,
349 int signal_fd) {
350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
351
352 FilePath dumps_path("/tmp");
353 PathService::Get(base::DIR_TEMP, &dumps_path);
354 if (!info->upload)
355 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
356 const uint64 rand = base::RandUint64();
357 const std::string minidump_filename =
[email protected]51ef8c12011-08-17 00:51:21358 base::StringPrintf("%s/chromium-%s-minidump-%016" PRIx64 ".dmp",
359 dumps_path.value().c_str(),
360 process_type_.c_str(),
361 rand);
[email protected]154cbabd2011-02-17 23:01:57362 if (!google_breakpad::WriteMinidump(minidump_filename.c_str(),
363 crashing_pid, crash_context,
364 kCrashContextSize)) {
365 LOG(ERROR) << "Failed to write crash dump for pid " << crashing_pid;
366 }
[email protected]c468f9492011-04-15 20:56:37367 delete[] crash_context;
[email protected]154cbabd2011-02-17 23:01:57368
[email protected]c468f9492011-04-15 20:56:37369 // Freed in CrashDumpTask();
[email protected]9cdd080d2012-04-09 20:10:17370 char* minidump_filename_str = new char[minidump_filename.length() + 1];
[email protected]154cbabd2011-02-17 23:01:57371 minidump_filename.copy(minidump_filename_str, minidump_filename.length());
372 minidump_filename_str[minidump_filename.length()] = '\0';
373 info->filename = minidump_filename_str;
[email protected]6653c192012-04-10 22:52:44374 info->pid = crashing_pid;
[email protected]154cbabd2011-02-17 23:01:57375
376 BrowserThread::PostTask(
377 BrowserThread::IO, FROM_HERE,
[email protected]69eb91122011-11-22 21:44:22378 base::Bind(&CrashHandlerHostLinux::QueueCrashDumpTask,
379 base::Unretained(this),
380 info,
381 signal_fd));
[email protected]154cbabd2011-02-17 23:01:57382}
383
384void CrashHandlerHostLinux::QueueCrashDumpTask(BreakpadInfo* info,
385 int signal_fd) {
386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
387
388 // Send the done signal to the process: it can exit now.
389 struct msghdr msg = {0};
390 struct iovec done_iov;
391 done_iov.iov_base = const_cast<char*>("\x42");
392 done_iov.iov_len = 1;
393 msg.msg_iov = &done_iov;
394 msg.msg_iovlen = 1;
395
[email protected]d997c442012-05-07 22:11:19396 (void) HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL));
397 (void) HANDLE_EINTR(close(signal_fd));
[email protected]154cbabd2011-02-17 23:01:57398
[email protected]b064f0eb2010-09-02 23:53:26399 uploader_thread_->message_loop()->PostTask(
400 FROM_HERE,
[email protected]69eb91122011-11-22 21:44:22401 base::Bind(&CrashDumpTask, base::Unretained(this), info));
[email protected]9a5d2a52009-05-22 03:37:45402}
403
[email protected]2456c572009-11-09 04:21:51404void CrashHandlerHostLinux::WillDestroyCurrentMessageLoop() {
[email protected]9a5d2a52009-05-22 03:37:45405 file_descriptor_watcher_.StopWatchingFileDescriptor();
[email protected]ca779662010-11-11 23:28:43406
407 // If we are quitting and there are crash dumps in the queue, turn them into
408 // no-ops.
409 shutting_down_ = true;
410 uploader_thread_->Stop();
411}
412
413bool CrashHandlerHostLinux::IsShuttingDown() const {
414 return shutting_down_;
[email protected]9a5d2a52009-05-22 03:37:45415}
[email protected]b064f0eb2010-09-02 23:53:26416
[email protected]9dbfff12011-07-01 19:37:07417ExtensionCrashHandlerHostLinux::ExtensionCrashHandlerHostLinux() {
418 InitCrashUploaderThread();
419}
420
421ExtensionCrashHandlerHostLinux::~ExtensionCrashHandlerHostLinux() {
422}
423
424void ExtensionCrashHandlerHostLinux::SetProcessType() {
425 process_type_ = "extension";
426}
427
428// static
429ExtensionCrashHandlerHostLinux* ExtensionCrashHandlerHostLinux::GetInstance() {
430 return Singleton<ExtensionCrashHandlerHostLinux>::get();
431}
432
[email protected]9289af822011-02-03 18:21:20433GpuCrashHandlerHostLinux::GpuCrashHandlerHostLinux() {
434 InitCrashUploaderThread();
435}
436
437GpuCrashHandlerHostLinux::~GpuCrashHandlerHostLinux() {
438}
439
440void GpuCrashHandlerHostLinux::SetProcessType() {
441 process_type_ = "gpu-process";
442}
443
444// static
445GpuCrashHandlerHostLinux* GpuCrashHandlerHostLinux::GetInstance() {
446 return Singleton<GpuCrashHandlerHostLinux>::get();
447}
448
[email protected]b064f0eb2010-09-02 23:53:26449PluginCrashHandlerHostLinux::PluginCrashHandlerHostLinux() {
[email protected]19eef062010-09-16 19:44:09450 InitCrashUploaderThread();
[email protected]b064f0eb2010-09-02 23:53:26451}
452
453PluginCrashHandlerHostLinux::~PluginCrashHandlerHostLinux() {
454}
455
456void PluginCrashHandlerHostLinux::SetProcessType() {
457 process_type_ = "plugin";
458}
459
[email protected]d3c6c0d72010-12-09 08:15:04460// static
461PluginCrashHandlerHostLinux* PluginCrashHandlerHostLinux::GetInstance() {
462 return Singleton<PluginCrashHandlerHostLinux>::get();
463}
464
[email protected]54457f32011-04-15 22:05:29465PpapiCrashHandlerHostLinux::PpapiCrashHandlerHostLinux() {
466 InitCrashUploaderThread();
467}
468
469PpapiCrashHandlerHostLinux::~PpapiCrashHandlerHostLinux() {
470}
471
472void PpapiCrashHandlerHostLinux::SetProcessType() {
473 process_type_ = "ppapi";
474}
475
476// static
477PpapiCrashHandlerHostLinux* PpapiCrashHandlerHostLinux::GetInstance() {
478 return Singleton<PpapiCrashHandlerHostLinux>::get();
479}
[email protected]9dbfff12011-07-01 19:37:07480
481RendererCrashHandlerHostLinux::RendererCrashHandlerHostLinux() {
482 InitCrashUploaderThread();
483}
484
485RendererCrashHandlerHostLinux::~RendererCrashHandlerHostLinux() {
486}
487
488void RendererCrashHandlerHostLinux::SetProcessType() {
489 process_type_ = "renderer";
490}
491
492// static
493RendererCrashHandlerHostLinux* RendererCrashHandlerHostLinux::GetInstance() {
494 return Singleton<RendererCrashHandlerHostLinux>::get();
495}