blob: f0db83e98dcc84831256f1bb53200ec41b71701a [file] [log] [blame]
[email protected]6653c192012-04-10 22:52:441// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]2456c572009-11-09 04:21:512// 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#ifndef CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
6#define CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
[email protected]2456c572009-11-09 04:21:517
[email protected]dfd50642011-11-28 20:00:448#include "base/compiler_specific.h"
[email protected]154cbabd2011-02-17 23:01:579#include "base/message_loop.h"
10
11#if defined(USE_LINUX_BREAKPAD)
12#include <sys/types.h>
13
[email protected]2456c572009-11-09 04:21:5114#include <string>
15
[email protected]3b63f8f42011-03-28 01:54:1516#include "base/memory/scoped_ptr.h"
[email protected]d3c6c0d72010-12-09 08:15:0417
[email protected]5879d182012-05-10 22:27:4618struct BreakpadInfo;
[email protected]b064f0eb2010-09-02 23:53:2619
20namespace base {
21class Thread;
22}
[email protected]154cbabd2011-02-17 23:01:5723#endif // defined(USE_LINUX_BREAKPAD)
24
25template <typename T> struct DefaultSingletonTraits;
[email protected]2456c572009-11-09 04:21:5126
27// This is the base class for singleton objects which crash dump renderers and
[email protected]6653c192012-04-10 22:52:4428// plugins on Linux or Android. We perform the crash dump from the browser
29// because it allows us to be outside the sandbox.
[email protected]2456c572009-11-09 04:21:5130//
[email protected]6653c192012-04-10 22:52:4431// PluginCrashHandlerHostLinux and RendererCrashHandlerHostLinux are
32// singletons that handle plugin and renderer crashes, respectively.
[email protected]2456c572009-11-09 04:21:5133//
34// Processes signal that they need to be dumped by sending a datagram over a
35// UNIX domain socket. All processes of the same type share the client end of
36// this socket which is installed in their descriptor table before exec.
37class CrashHandlerHostLinux : public MessageLoopForIO::Watcher,
38 public MessageLoop::DestructionObserver {
39 public:
40 // Get the file descriptor which processes should be given in order to signal
41 // crashes to the browser.
42 int GetDeathSignalSocket() const {
43 return process_socket_;
44 }
45
46 // MessagePumbLibevent::Watcher impl:
[email protected]dfd50642011-11-28 20:00:4447 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
48 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
[email protected]2456c572009-11-09 04:21:5149
50 // MessageLoop::DestructionObserver impl:
[email protected]dfd50642011-11-28 20:00:4451 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
[email protected]2456c572009-11-09 04:21:5152
[email protected]ca779662010-11-11 23:28:4353#if defined(USE_LINUX_BREAKPAD)
54 // Whether we are shutting down or not.
55 bool IsShuttingDown() const;
56#endif
57
[email protected]2456c572009-11-09 04:21:5158 protected:
59 CrashHandlerHostLinux();
[email protected]46ebf0642010-07-24 02:47:4060 virtual ~CrashHandlerHostLinux();
[email protected]19eef062010-09-16 19:44:0961
[email protected]b064f0eb2010-09-02 23:53:2662#if defined(USE_LINUX_BREAKPAD)
[email protected]19eef062010-09-16 19:44:0963 // Only called in concrete subclasses.
64 void InitCrashUploaderThread();
[email protected]2456c572009-11-09 04:21:5165
66 std::string process_type_;
[email protected]b064f0eb2010-09-02 23:53:2667#endif
[email protected]2456c572009-11-09 04:21:5168
69 private:
70 void Init();
71
[email protected]19eef062010-09-16 19:44:0972#if defined(USE_LINUX_BREAKPAD)
73 // This is here on purpose to make CrashHandlerHostLinux abstract.
74 virtual void SetProcessType() = 0;
[email protected]154cbabd2011-02-17 23:01:5775
76 // Do work on the FILE thread for OnFileCanReadWithoutBlocking().
77 void WriteDumpFile(BreakpadInfo* info,
78 pid_t crashing_pid,
79 char* crash_context,
80 int signal_fd);
81
82 // Continue OnFileCanReadWithoutBlocking()'s work on the IO thread.
83 void QueueCrashDumpTask(BreakpadInfo* info, int signal_fd);
[email protected]19eef062010-09-16 19:44:0984#endif
85
[email protected]2456c572009-11-09 04:21:5186 int process_socket_;
87 int browser_socket_;
[email protected]19eef062010-09-16 19:44:0988
[email protected]b064f0eb2010-09-02 23:53:2689#if defined(USE_LINUX_BREAKPAD)
[email protected]2456c572009-11-09 04:21:5190 MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_;
[email protected]b064f0eb2010-09-02 23:53:2691 scoped_ptr<base::Thread> uploader_thread_;
[email protected]ca779662010-11-11 23:28:4392 bool shutting_down_;
[email protected]b064f0eb2010-09-02 23:53:2693#endif
[email protected]2456c572009-11-09 04:21:5194
[email protected]a83291d62012-08-23 14:39:4595#if defined(ADDRESS_SANITIZER)
96 char* asan_report_str_;
97#endif
98
[email protected]2456c572009-11-09 04:21:5199 DISALLOW_COPY_AND_ASSIGN(CrashHandlerHostLinux);
100};
101
[email protected]9dbfff12011-07-01 19:37:07102class ExtensionCrashHandlerHostLinux : public CrashHandlerHostLinux {
103 public:
104 // Returns the singleton instance.
105 static ExtensionCrashHandlerHostLinux* GetInstance();
106
107 private:
108 friend struct DefaultSingletonTraits<ExtensionCrashHandlerHostLinux>;
109 ExtensionCrashHandlerHostLinux();
110 virtual ~ExtensionCrashHandlerHostLinux();
111
112#if defined(USE_LINUX_BREAKPAD)
[email protected]dfd50642011-11-28 20:00:44113 virtual void SetProcessType() OVERRIDE;
[email protected]9dbfff12011-07-01 19:37:07114#endif
115
116 DISALLOW_COPY_AND_ASSIGN(ExtensionCrashHandlerHostLinux);
117};
118
[email protected]9289af822011-02-03 18:21:20119class GpuCrashHandlerHostLinux : public CrashHandlerHostLinux {
120 public:
121 // Returns the singleton instance.
122 static GpuCrashHandlerHostLinux* GetInstance();
123
124 private:
125 friend struct DefaultSingletonTraits<GpuCrashHandlerHostLinux>;
126 GpuCrashHandlerHostLinux();
127 virtual ~GpuCrashHandlerHostLinux();
128
129#if defined(USE_LINUX_BREAKPAD)
[email protected]dfd50642011-11-28 20:00:44130 virtual void SetProcessType() OVERRIDE;
[email protected]9289af822011-02-03 18:21:20131#endif
132
133 DISALLOW_COPY_AND_ASSIGN(GpuCrashHandlerHostLinux);
134};
135
[email protected]2456c572009-11-09 04:21:51136class PluginCrashHandlerHostLinux : public CrashHandlerHostLinux {
[email protected]d3c6c0d72010-12-09 08:15:04137 public:
138 // Returns the singleton instance.
139 static PluginCrashHandlerHostLinux* GetInstance();
140
[email protected]2456c572009-11-09 04:21:51141 private:
142 friend struct DefaultSingletonTraits<PluginCrashHandlerHostLinux>;
[email protected]b064f0eb2010-09-02 23:53:26143 PluginCrashHandlerHostLinux();
144 virtual ~PluginCrashHandlerHostLinux();
[email protected]2456c572009-11-09 04:21:51145
[email protected]b064f0eb2010-09-02 23:53:26146#if defined(USE_LINUX_BREAKPAD)
[email protected]dfd50642011-11-28 20:00:44147 virtual void SetProcessType() OVERRIDE;
[email protected]b064f0eb2010-09-02 23:53:26148#endif
[email protected]2456c572009-11-09 04:21:51149
150 DISALLOW_COPY_AND_ASSIGN(PluginCrashHandlerHostLinux);
151};
152
[email protected]54457f32011-04-15 22:05:29153class PpapiCrashHandlerHostLinux : public CrashHandlerHostLinux {
154 public:
155 // Returns the singleton instance.
156 static PpapiCrashHandlerHostLinux* GetInstance();
157
158 private:
159 friend struct DefaultSingletonTraits<PpapiCrashHandlerHostLinux>;
160 PpapiCrashHandlerHostLinux();
161 virtual ~PpapiCrashHandlerHostLinux();
162
163#if defined(USE_LINUX_BREAKPAD)
[email protected]dfd50642011-11-28 20:00:44164 virtual void SetProcessType() OVERRIDE;
[email protected]54457f32011-04-15 22:05:29165#endif
166
167 DISALLOW_COPY_AND_ASSIGN(PpapiCrashHandlerHostLinux);
168};
169
[email protected]9dbfff12011-07-01 19:37:07170class RendererCrashHandlerHostLinux : public CrashHandlerHostLinux {
171 public:
172 // Returns the singleton instance.
173 static RendererCrashHandlerHostLinux* GetInstance();
174
175 private:
176 friend struct DefaultSingletonTraits<RendererCrashHandlerHostLinux>;
177 RendererCrashHandlerHostLinux();
178 virtual ~RendererCrashHandlerHostLinux();
179
180#if defined(USE_LINUX_BREAKPAD)
[email protected]dfd50642011-11-28 20:00:44181 virtual void SetProcessType() OVERRIDE;
[email protected]9dbfff12011-07-01 19:37:07182#endif
183
184 DISALLOW_COPY_AND_ASSIGN(RendererCrashHandlerHostLinux);
185};
186
[email protected]1602cde2012-06-26 15:09:12187#endif // CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_