blob: 9298ebb2496db9a8c6364f81f081b8465b2d3dca [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]1602cde2012-06-26 15:09:125#include "chrome/browser/crash_handler_host_linux.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]57999812013-02-24 05:40:5215#include "base/files/file_path.h"
[email protected]c725d7922009-06-30 00:05:0816#include "base/format_macros.h"
[email protected]85ebe8f2009-10-29 04:02:5517#include "base/linux_util.h"
[email protected]9a5d2a52009-05-22 03:37:4518#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1519#include "base/memory/singleton.h"
[email protected]9a5d2a52009-05-22 03:37:4520#include "base/message_loop.h"
[email protected]cbd5fd52009-08-26 00:14:2721#include "base/path_service.h"
[email protected]2025d002012-11-14 20:54:3522#include "base/posix/eintr_wrapper.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]1602cde2012-06-26 15:09:1230#include "chrome/app/breakpad_linux.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]a83291d62012-08-23 14:39:45131#if !defined(ADDRESS_SANITIZER)
[email protected]6a033592012-03-23 00:08:54132 const size_t kIovSize = 8;
[email protected]a83291d62012-08-23 14:39:45133#else
134 const size_t kIovSize = 9;
135#endif
136
[email protected]9a5d2a52009-05-22 03:37:45137 struct msghdr msg = {0};
[email protected]c7b1d2f2010-12-03 03:33:13138 struct iovec iov[kIovSize];
[email protected]c468f9492011-04-15 20:56:37139
140 // Freed in WriteDumpFile();
141 char* crash_context = new char[kCrashContextSize];
142 // Freed in CrashDumpTask();
[email protected]b064f0eb2010-09-02 23:53:26143 char* guid = new char[kGuidSize + 1];
144 char* crash_url = new char[kMaxActiveURLSize + 1];
145 char* distro = new char[kDistroSize + 1];
[email protected]a83291d62012-08-23 14:39:45146#if defined(ADDRESS_SANITIZER)
147 asan_report_str_ = new char[kMaxAsanReportSize + 1];
148#endif
[email protected]c468f9492011-04-15 20:56:37149
[email protected]662183142010-07-16 19:28:17150 char* tid_buf_addr = NULL;
151 int tid_fd = -1;
[email protected]c7b1d2f2010-12-03 03:33:13152 uint64_t uptime;
[email protected]6a033592012-03-23 00:08:54153 size_t oom_size;
[email protected]9a5d2a52009-05-22 03:37:45154 char control[kControlMsgSize];
[email protected]c468f9492011-04-15 20:56:37155 const ssize_t expected_msg_size =
156 kCrashContextSize +
[email protected]b064f0eb2010-09-02 23:53:26157 kGuidSize + 1 +
158 kMaxActiveURLSize + 1 +
159 kDistroSize + 1 +
[email protected]c7b1d2f2010-12-03 03:33:13160 sizeof(tid_buf_addr) + sizeof(tid_fd) +
[email protected]6a033592012-03-23 00:08:54161 sizeof(uptime) +
[email protected]a83291d62012-08-23 14:39:45162#if defined(ADDRESS_SANITIZER)
163 kMaxAsanReportSize + 1 +
164#endif
[email protected]6a033592012-03-23 00:08:54165 sizeof(oom_size);
[email protected]2eb41e72009-07-15 23:07:34166 iov[0].iov_base = crash_context;
[email protected]c468f9492011-04-15 20:56:37167 iov[0].iov_len = kCrashContextSize;
[email protected]2eb41e72009-07-15 23:07:34168 iov[1].iov_base = guid;
[email protected]b064f0eb2010-09-02 23:53:26169 iov[1].iov_len = kGuidSize + 1;
[email protected]2eb41e72009-07-15 23:07:34170 iov[2].iov_base = crash_url;
[email protected]b064f0eb2010-09-02 23:53:26171 iov[2].iov_len = kMaxActiveURLSize + 1;
[email protected]912c6452009-07-17 05:55:51172 iov[3].iov_base = distro;
[email protected]b064f0eb2010-09-02 23:53:26173 iov[3].iov_len = kDistroSize + 1;
[email protected]662183142010-07-16 19:28:17174 iov[4].iov_base = &tid_buf_addr;
175 iov[4].iov_len = sizeof(tid_buf_addr);
176 iov[5].iov_base = &tid_fd;
177 iov[5].iov_len = sizeof(tid_fd);
[email protected]c7b1d2f2010-12-03 03:33:13178 iov[6].iov_base = &uptime;
179 iov[6].iov_len = sizeof(uptime);
[email protected]6a033592012-03-23 00:08:54180 iov[7].iov_base = &oom_size;
181 iov[7].iov_len = sizeof(oom_size);
[email protected]a83291d62012-08-23 14:39:45182#if defined(ADDRESS_SANITIZER)
183 iov[8].iov_base = asan_report_str_;
184 iov[8].iov_len = kMaxAsanReportSize + 1;
185#endif
[email protected]2eb41e72009-07-15 23:07:34186 msg.msg_iov = iov;
[email protected]c7b1d2f2010-12-03 03:33:13187 msg.msg_iovlen = kIovSize;
[email protected]9a5d2a52009-05-22 03:37:45188 msg.msg_control = control;
189 msg.msg_controllen = kControlMsgSize;
190
[email protected]2eb41e72009-07-15 23:07:34191 const ssize_t msg_size = HANDLE_EINTR(recvmsg(browser_socket_, &msg, 0));
192 if (msg_size != expected_msg_size) {
[email protected]9a5d2a52009-05-22 03:37:45193 LOG(ERROR) << "Error reading from death signal socket. Crash dumping"
194 << " is disabled."
[email protected]2eb41e72009-07-15 23:07:34195 << " msg_size:" << msg_size
[email protected]9a5d2a52009-05-22 03:37:45196 << " errno:" << errno;
197 file_descriptor_watcher_.StopWatchingFileDescriptor();
198 return;
199 }
200
[email protected]2eb41e72009-07-15 23:07:34201 if (msg.msg_controllen != kControlMsgSize ||
[email protected]9a5d2a52009-05-22 03:37:45202 msg.msg_flags & ~MSG_TRUNC) {
203 LOG(ERROR) << "Received death signal message with the wrong size;"
[email protected]9a5d2a52009-05-22 03:37:45204 << " msg.msg_controllen:" << msg.msg_controllen
205 << " msg.msg_flags:" << msg.msg_flags
206 << " kCrashContextSize:" << kCrashContextSize
207 << " kControlMsgSize:" << kControlMsgSize;
208 return;
209 }
210
[email protected]9a5d2a52009-05-22 03:37:45211 // Walk the control payload an extract the file descriptor and validated pid.
212 pid_t crashing_pid = -1;
[email protected]15e85772010-08-09 20:44:03213 int partner_fd = -1;
[email protected]9a5d2a52009-05-22 03:37:45214 int signal_fd = -1;
215 for (struct cmsghdr *hdr = CMSG_FIRSTHDR(&msg); hdr;
216 hdr = CMSG_NXTHDR(&msg, hdr)) {
217 if (hdr->cmsg_level != SOL_SOCKET)
218 continue;
219 if (hdr->cmsg_type == SCM_RIGHTS) {
220 const unsigned len = hdr->cmsg_len -
221 (((uint8_t*)CMSG_DATA(hdr)) - (uint8_t*)hdr);
[email protected]912c6452009-07-17 05:55:51222 DCHECK_EQ(len % sizeof(int), 0u);
[email protected]9a5d2a52009-05-22 03:37:45223 const unsigned num_fds = len / sizeof(int);
[email protected]15e85772010-08-09 20:44:03224 if (num_fds != 2) {
[email protected]2456c572009-11-09 04:21:51225 // A nasty process could try and send us too many descriptors and
[email protected]9a5d2a52009-05-22 03:37:45226 // force a leak.
[email protected]15e85772010-08-09 20:44:03227 LOG(ERROR) << "Death signal contained wrong number of descriptors;"
[email protected]9a5d2a52009-05-22 03:37:45228 << " num_fds:" << num_fds;
229 for (unsigned i = 0; i < num_fds; ++i)
[email protected]d997c442012-05-07 22:11:19230 (void) HANDLE_EINTR(close(reinterpret_cast<int*>(CMSG_DATA(hdr))[i]));
[email protected]9a5d2a52009-05-22 03:37:45231 return;
232 } else {
[email protected]15e85772010-08-09 20:44:03233 partner_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[0];
234 signal_fd = reinterpret_cast<int*>(CMSG_DATA(hdr))[1];
[email protected]9a5d2a52009-05-22 03:37:45235 }
236 } else if (hdr->cmsg_type == SCM_CREDENTIALS) {
237 const struct ucred *cred =
238 reinterpret_cast<struct ucred*>(CMSG_DATA(hdr));
239 crashing_pid = cred->pid;
240 }
241 }
242
[email protected]15e85772010-08-09 20:44:03243 if (crashing_pid == -1 || partner_fd == -1 || signal_fd == -1) {
[email protected]9a5d2a52009-05-22 03:37:45244 LOG(ERROR) << "Death signal message didn't contain all expected control"
245 << " messages";
[email protected]15e85772010-08-09 20:44:03246 if (partner_fd >= 0)
[email protected]d997c442012-05-07 22:11:19247 (void) HANDLE_EINTR(close(partner_fd));
[email protected]15e85772010-08-09 20:44:03248 if (signal_fd >= 0)
[email protected]d997c442012-05-07 22:11:19249 (void) HANDLE_EINTR(close(signal_fd));
[email protected]9a5d2a52009-05-22 03:37:45250 return;
251 }
252
[email protected]cb7d53e2011-06-21 04:21:06253 // Kernel bug workaround (broken in 2.6.30 and 2.6.32, working in 2.6.38).
[email protected]4378a822009-07-08 01:15:14254 // The kernel doesn't translate PIDs in SCM_CREDENTIALS across PID
255 // namespaces. Thus |crashing_pid| might be garbage from our point of view.
256 // In the future we can remove this workaround, but we have to wait a couple
257 // of years to be sure that it's worked its way out into the world.
[email protected]cb7d53e2011-06-21 04:21:06258 // TODO(thestig) Remove the workaround when Ubuntu Lucid is deprecated.
[email protected]4378a822009-07-08 01:15:14259
[email protected]15e85772010-08-09 20:44:03260 // The crashing process closes its copy of the signal_fd immediately after
261 // calling sendmsg(). We can thus not reliably look for with with
262 // FindProcessHoldingSocket(). But by necessity, it has to keep the
263 // partner_fd open until the crashdump is complete.
[email protected]8053b61b2012-09-04 20:02:57264 ino_t inode_number;
[email protected]15e85772010-08-09 20:44:03265 if (!base::FileDescriptorGetInode(&inode_number, partner_fd)) {
[email protected]4378a822009-07-08 01:15:14266 LOG(WARNING) << "Failed to get inode number for passed socket";
[email protected]d997c442012-05-07 22:11:19267 (void) HANDLE_EINTR(close(partner_fd));
268 (void) HANDLE_EINTR(close(signal_fd));
[email protected]4378a822009-07-08 01:15:14269 return;
270 }
[email protected]d997c442012-05-07 22:11:19271 (void) HANDLE_EINTR(close(partner_fd));
[email protected]4378a822009-07-08 01:15:14272
[email protected]662183142010-07-16 19:28:17273 pid_t actual_crashing_pid = -1;
[email protected]15e85772010-08-09 20:44:03274 if (!base::FindProcessHoldingSocket(&actual_crashing_pid, inode_number)) {
[email protected]4378a822009-07-08 01:15:14275 LOG(WARNING) << "Failed to find process holding other end of crash reply "
276 "socket";
[email protected]d997c442012-05-07 22:11:19277 (void) HANDLE_EINTR(close(signal_fd));
[email protected]4378a822009-07-08 01:15:14278 return;
279 }
[email protected]15e85772010-08-09 20:44:03280
[email protected]cb7d53e2011-06-21 04:21:06281 crashing_pid = actual_crashing_pid;
[email protected]662183142010-07-16 19:28:17282
[email protected]cb7d53e2011-06-21 04:21:06283 // The crashing TID set inside the compromised context via
284 // sys_gettid() in ExceptionHandler::HandleSignal might be wrong (if
285 // the kernel supports PID namespacing) and may need to be
286 // translated.
287 //
288 // We expect the crashing thread to be in sys_read(), waiting for us to
289 // write to |signal_fd|. Most newer kernels where we have the different pid
290 // namespaces also have /proc/[pid]/syscall, so we can look through
291 // |actual_crashing_pid|'s thread group and find the thread that's in the
292 // read syscall with the right arguments.
[email protected]662183142010-07-16 19:28:17293
[email protected]cb7d53e2011-06-21 04:21:06294 std::string expected_syscall_data;
295 // /proc/[pid]/syscall is formatted as follows:
296 // syscall_number arg1 ... arg6 sp pc
297 // but we just check syscall_number through arg3.
298 base::StringAppendF(&expected_syscall_data, "%d 0x%x %p 0x1 ",
299 SYS_read, tid_fd, tid_buf_addr);
300 bool syscall_supported = false;
301 pid_t crashing_tid =
302 base::FindThreadIDWithSyscall(crashing_pid,
303 expected_syscall_data,
304 &syscall_supported);
[email protected]e02f1372011-10-06 21:24:37305 if (crashing_tid == -1) {
[email protected]cb7d53e2011-06-21 04:21:06306 // We didn't find the thread we want. Maybe it didn't reach
307 // sys_read() yet or the thread went away. We'll just take a
308 // guess here and assume the crashing thread is the thread group
309 // leader. If procfs syscall is not supported by the kernel, then
310 // we assume the kernel also does not support TID namespacing and
311 // trust the TID passed by the crashing process.
[email protected]e02f1372011-10-06 21:24:37312 LOG(WARNING) << "Could not translate tid - assuming crashing thread is "
313 "thread group leader; syscall_supported=" << syscall_supported;
[email protected]cb7d53e2011-06-21 04:21:06314 crashing_tid = crashing_pid;
[email protected]662183142010-07-16 19:28:17315 }
[email protected]4378a822009-07-08 01:15:14316
[email protected]cb7d53e2011-06-21 04:21:06317 ExceptionHandler::CrashContext* bad_context =
318 reinterpret_cast<ExceptionHandler::CrashContext*>(crash_context);
319 bad_context->tid = crashing_tid;
320
[email protected]9ddbcd92009-09-23 21:27:43321 // Sanitize the string data a bit more
322 guid[kGuidSize] = crash_url[kMaxActiveURLSize] = distro[kDistroSize] = 0;
323
[email protected]c468f9492011-04-15 20:56:37324 // Freed in CrashDumpTask();
[email protected]b064f0eb2010-09-02 23:53:26325 BreakpadInfo* info = new BreakpadInfo;
326
[email protected]40da3e0c2012-10-24 22:03:38327 info->fd = -1;
[email protected]b064f0eb2010-09-02 23:53:26328 info->process_type_length = process_type_.length();
329 char* process_type_str = new char[info->process_type_length + 1];
330 process_type_.copy(process_type_str, info->process_type_length);
331 process_type_str[info->process_type_length] = '\0';
332 info->process_type = process_type_str;
333
334 info->crash_url_length = strlen(crash_url);
335 info->crash_url = crash_url;
336
337 info->guid_length = strlen(guid);
338 info->guid = guid;
339
340 info->distro_length = strlen(distro);
341 info->distro = distro;
[email protected]6653c192012-04-10 22:52:44342#if defined(OS_ANDROID)
343 // Nothing gets uploaded in android.
344 info->upload = false;
345#else
[email protected]154cbabd2011-02-17 23:01:57346 info->upload = (getenv(env_vars::kHeadless) == NULL);
[email protected]6653c192012-04-10 22:52:44347#endif
[email protected]a83291d62012-08-23 14:39:45348
349#if defined(ADDRESS_SANITIZER)
350 info->asan_report_str = asan_report_str_;
351 info->asan_report_length = strlen(asan_report_str_);
352#endif
[email protected]c7b1d2f2010-12-03 03:33:13353 info->process_start_time = uptime;
[email protected]6a033592012-03-23 00:08:54354 info->oom_size = oom_size;
[email protected]b064f0eb2010-09-02 23:53:26355
[email protected]154cbabd2011-02-17 23:01:57356 BrowserThread::PostTask(
357 BrowserThread::FILE, FROM_HERE,
[email protected]69eb91122011-11-22 21:44:22358 base::Bind(&CrashHandlerHostLinux::WriteDumpFile,
359 base::Unretained(this),
360 info,
361 crashing_pid,
362 crash_context,
363 signal_fd));
[email protected]154cbabd2011-02-17 23:01:57364}
365
366void CrashHandlerHostLinux::WriteDumpFile(BreakpadInfo* info,
367 pid_t crashing_pid,
368 char* crash_context,
369 int signal_fd) {
370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
371
[email protected]650b2d52013-02-10 03:41:45372 base::FilePath dumps_path("/tmp");
[email protected]154cbabd2011-02-17 23:01:57373 PathService::Get(base::DIR_TEMP, &dumps_path);
374 if (!info->upload)
375 PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path);
376 const uint64 rand = base::RandUint64();
377 const std::string minidump_filename =
[email protected]51ef8c12011-08-17 00:51:21378 base::StringPrintf("%s/chromium-%s-minidump-%016" PRIx64 ".dmp",
379 dumps_path.value().c_str(),
380 process_type_.c_str(),
381 rand);
[email protected]a83291d62012-08-23 14:39:45382
[email protected]154cbabd2011-02-17 23:01:57383 if (!google_breakpad::WriteMinidump(minidump_filename.c_str(),
[email protected]892996332012-11-22 04:54:41384 kMaxMinidumpFileSize,
[email protected]154cbabd2011-02-17 23:01:57385 crashing_pid, crash_context,
[email protected]892996332012-11-22 04:54:41386 kCrashContextSize,
387 google_breakpad::MappingList(),
388 google_breakpad::AppMemoryList())) {
[email protected]154cbabd2011-02-17 23:01:57389 LOG(ERROR) << "Failed to write crash dump for pid " << crashing_pid;
390 }
[email protected]a83291d62012-08-23 14:39:45391#if defined(ADDRESS_SANITIZER)
392 // Create a temporary file holding the AddressSanitizer report.
393 const std::string log_filename =
394 base::StringPrintf("%s/chromium-%s-minidump-%016" PRIx64 ".log",
395 dumps_path.value().c_str(),
396 process_type_.c_str(),
397 rand);
398 FILE* logfile = fopen(log_filename.c_str(), "w");
399 CHECK(logfile);
400 fprintf(logfile, "%s", asan_report_str_);
401 fclose(logfile);
402#endif
403
[email protected]c468f9492011-04-15 20:56:37404 delete[] crash_context;
[email protected]154cbabd2011-02-17 23:01:57405
[email protected]c468f9492011-04-15 20:56:37406 // Freed in CrashDumpTask();
[email protected]9cdd080d2012-04-09 20:10:17407 char* minidump_filename_str = new char[minidump_filename.length() + 1];
[email protected]154cbabd2011-02-17 23:01:57408 minidump_filename.copy(minidump_filename_str, minidump_filename.length());
409 minidump_filename_str[minidump_filename.length()] = '\0';
410 info->filename = minidump_filename_str;
[email protected]a83291d62012-08-23 14:39:45411#if defined(ADDRESS_SANITIZER)
412 char* minidump_log_filename_str = new char[minidump_filename.length() + 1];
413 minidump_filename.copy(minidump_log_filename_str, minidump_filename.length());
414 memcpy(minidump_log_filename_str + minidump_filename.length() - 3, "log", 3);
415 minidump_log_filename_str[minidump_filename.length()] = '\0';
416 info->log_filename = minidump_log_filename_str;
417#endif
[email protected]6653c192012-04-10 22:52:44418 info->pid = crashing_pid;
[email protected]154cbabd2011-02-17 23:01:57419
420 BrowserThread::PostTask(
421 BrowserThread::IO, FROM_HERE,
[email protected]69eb91122011-11-22 21:44:22422 base::Bind(&CrashHandlerHostLinux::QueueCrashDumpTask,
423 base::Unretained(this),
424 info,
425 signal_fd));
[email protected]154cbabd2011-02-17 23:01:57426}
427
428void CrashHandlerHostLinux::QueueCrashDumpTask(BreakpadInfo* info,
429 int signal_fd) {
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
431
432 // Send the done signal to the process: it can exit now.
433 struct msghdr msg = {0};
434 struct iovec done_iov;
435 done_iov.iov_base = const_cast<char*>("\x42");
436 done_iov.iov_len = 1;
437 msg.msg_iov = &done_iov;
438 msg.msg_iovlen = 1;
439
[email protected]d997c442012-05-07 22:11:19440 (void) HANDLE_EINTR(sendmsg(signal_fd, &msg, MSG_DONTWAIT | MSG_NOSIGNAL));
441 (void) HANDLE_EINTR(close(signal_fd));
[email protected]154cbabd2011-02-17 23:01:57442
[email protected]b064f0eb2010-09-02 23:53:26443 uploader_thread_->message_loop()->PostTask(
444 FROM_HERE,
[email protected]69eb91122011-11-22 21:44:22445 base::Bind(&CrashDumpTask, base::Unretained(this), info));
[email protected]9a5d2a52009-05-22 03:37:45446}
447
[email protected]2456c572009-11-09 04:21:51448void CrashHandlerHostLinux::WillDestroyCurrentMessageLoop() {
[email protected]9a5d2a52009-05-22 03:37:45449 file_descriptor_watcher_.StopWatchingFileDescriptor();
[email protected]ca779662010-11-11 23:28:43450
451 // If we are quitting and there are crash dumps in the queue, turn them into
452 // no-ops.
453 shutting_down_ = true;
454 uploader_thread_->Stop();
455}
456
457bool CrashHandlerHostLinux::IsShuttingDown() const {
458 return shutting_down_;
[email protected]9a5d2a52009-05-22 03:37:45459}
[email protected]b064f0eb2010-09-02 23:53:26460
[email protected]9dbfff12011-07-01 19:37:07461ExtensionCrashHandlerHostLinux::ExtensionCrashHandlerHostLinux() {
462 InitCrashUploaderThread();
463}
464
465ExtensionCrashHandlerHostLinux::~ExtensionCrashHandlerHostLinux() {
466}
467
468void ExtensionCrashHandlerHostLinux::SetProcessType() {
469 process_type_ = "extension";
470}
471
472// static
473ExtensionCrashHandlerHostLinux* ExtensionCrashHandlerHostLinux::GetInstance() {
474 return Singleton<ExtensionCrashHandlerHostLinux>::get();
475}
476
[email protected]9289af822011-02-03 18:21:20477GpuCrashHandlerHostLinux::GpuCrashHandlerHostLinux() {
478 InitCrashUploaderThread();
479}
480
481GpuCrashHandlerHostLinux::~GpuCrashHandlerHostLinux() {
482}
483
484void GpuCrashHandlerHostLinux::SetProcessType() {
485 process_type_ = "gpu-process";
486}
487
488// static
489GpuCrashHandlerHostLinux* GpuCrashHandlerHostLinux::GetInstance() {
490 return Singleton<GpuCrashHandlerHostLinux>::get();
491}
492
[email protected]b064f0eb2010-09-02 23:53:26493PluginCrashHandlerHostLinux::PluginCrashHandlerHostLinux() {
[email protected]19eef062010-09-16 19:44:09494 InitCrashUploaderThread();
[email protected]b064f0eb2010-09-02 23:53:26495}
496
497PluginCrashHandlerHostLinux::~PluginCrashHandlerHostLinux() {
498}
499
500void PluginCrashHandlerHostLinux::SetProcessType() {
501 process_type_ = "plugin";
502}
503
[email protected]d3c6c0d72010-12-09 08:15:04504// static
505PluginCrashHandlerHostLinux* PluginCrashHandlerHostLinux::GetInstance() {
506 return Singleton<PluginCrashHandlerHostLinux>::get();
507}
508
[email protected]54457f32011-04-15 22:05:29509PpapiCrashHandlerHostLinux::PpapiCrashHandlerHostLinux() {
510 InitCrashUploaderThread();
511}
512
513PpapiCrashHandlerHostLinux::~PpapiCrashHandlerHostLinux() {
514}
515
516void PpapiCrashHandlerHostLinux::SetProcessType() {
517 process_type_ = "ppapi";
518}
519
520// static
521PpapiCrashHandlerHostLinux* PpapiCrashHandlerHostLinux::GetInstance() {
522 return Singleton<PpapiCrashHandlerHostLinux>::get();
523}
[email protected]9dbfff12011-07-01 19:37:07524
525RendererCrashHandlerHostLinux::RendererCrashHandlerHostLinux() {
526 InitCrashUploaderThread();
527}
528
529RendererCrashHandlerHostLinux::~RendererCrashHandlerHostLinux() {
530}
531
532void RendererCrashHandlerHostLinux::SetProcessType() {
533 process_type_ = "renderer";
534}
535
536// static
537RendererCrashHandlerHostLinux* RendererCrashHandlerHostLinux::GetInstance() {
538 return Singleton<RendererCrashHandlerHostLinux>::get();
539}