[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [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] | 1602cde | 2012-06-26 15:09:12 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_ |
6 | #define CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_ | ||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 7 | |
[email protected] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
[email protected] | 154cbabd | 2011-02-17 23:01:57 | [diff] [blame] | 9 | #include "base/message_loop.h" |
10 | |||||
11 | #if defined(USE_LINUX_BREAKPAD) | ||||
12 | #include <sys/types.h> | ||||
13 | |||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 14 | #include <string> |
15 | |||||
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/scoped_ptr.h" |
[email protected] | d3c6c0d7 | 2010-12-09 08:15:04 | [diff] [blame] | 17 | |
[email protected] | 5879d18 | 2012-05-10 22:27:46 | [diff] [blame] | 18 | struct BreakpadInfo; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 19 | |
20 | namespace base { | ||||
21 | class Thread; | ||||
22 | } | ||||
[email protected] | 154cbabd | 2011-02-17 23:01:57 | [diff] [blame] | 23 | #endif // defined(USE_LINUX_BREAKPAD) |
24 | |||||
25 | template <typename T> struct DefaultSingletonTraits; | ||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 26 | |
27 | // This is the base class for singleton objects which crash dump renderers and | ||||
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 28 | // 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] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 30 | // |
[email protected] | 6653c19 | 2012-04-10 22:52:44 | [diff] [blame] | 31 | // PluginCrashHandlerHostLinux and RendererCrashHandlerHostLinux are |
32 | // singletons that handle plugin and renderer crashes, respectively. | ||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 33 | // |
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. | ||||
37 | class 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] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 47 | virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
48 | virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | ||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 49 | |
50 | // MessageLoop::DestructionObserver impl: | ||||
[email protected] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 51 | virtual void WillDestroyCurrentMessageLoop() OVERRIDE; |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 52 | |
[email protected] | ca77966 | 2010-11-11 23:28:43 | [diff] [blame] | 53 | #if defined(USE_LINUX_BREAKPAD) |
54 | // Whether we are shutting down or not. | ||||
55 | bool IsShuttingDown() const; | ||||
56 | #endif | ||||
57 | |||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 58 | protected: |
59 | CrashHandlerHostLinux(); | ||||
[email protected] | 46ebf064 | 2010-07-24 02:47:40 | [diff] [blame] | 60 | virtual ~CrashHandlerHostLinux(); |
[email protected] | 19eef06 | 2010-09-16 19:44:09 | [diff] [blame] | 61 | |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 62 | #if defined(USE_LINUX_BREAKPAD) |
[email protected] | 19eef06 | 2010-09-16 19:44:09 | [diff] [blame] | 63 | // Only called in concrete subclasses. |
64 | void InitCrashUploaderThread(); | ||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 65 | |
66 | std::string process_type_; | ||||
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 67 | #endif |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 68 | |
69 | private: | ||||
70 | void Init(); | ||||
71 | |||||
[email protected] | 19eef06 | 2010-09-16 19:44:09 | [diff] [blame] | 72 | #if defined(USE_LINUX_BREAKPAD) |
73 | // This is here on purpose to make CrashHandlerHostLinux abstract. | ||||
74 | virtual void SetProcessType() = 0; | ||||
[email protected] | 154cbabd | 2011-02-17 23:01:57 | [diff] [blame] | 75 | |
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] | 19eef06 | 2010-09-16 19:44:09 | [diff] [blame] | 84 | #endif |
85 | |||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 86 | int process_socket_; |
87 | int browser_socket_; | ||||
[email protected] | 19eef06 | 2010-09-16 19:44:09 | [diff] [blame] | 88 | |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 89 | #if defined(USE_LINUX_BREAKPAD) |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 90 | MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 91 | scoped_ptr<base::Thread> uploader_thread_; |
[email protected] | ca77966 | 2010-11-11 23:28:43 | [diff] [blame] | 92 | bool shutting_down_; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 93 | #endif |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 94 | |
[email protected] | a83291d6 | 2012-08-23 14:39:45 | [diff] [blame] | 95 | #if defined(ADDRESS_SANITIZER) |
96 | char* asan_report_str_; | ||||
97 | #endif | ||||
98 | |||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 99 | DISALLOW_COPY_AND_ASSIGN(CrashHandlerHostLinux); |
100 | }; | ||||
101 | |||||
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 102 | class 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] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 113 | virtual void SetProcessType() OVERRIDE; |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 114 | #endif |
115 | |||||
116 | DISALLOW_COPY_AND_ASSIGN(ExtensionCrashHandlerHostLinux); | ||||
117 | }; | ||||
118 | |||||
[email protected] | 9289af82 | 2011-02-03 18:21:20 | [diff] [blame] | 119 | class 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] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 130 | virtual void SetProcessType() OVERRIDE; |
[email protected] | 9289af82 | 2011-02-03 18:21:20 | [diff] [blame] | 131 | #endif |
132 | |||||
133 | DISALLOW_COPY_AND_ASSIGN(GpuCrashHandlerHostLinux); | ||||
134 | }; | ||||
135 | |||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 136 | class PluginCrashHandlerHostLinux : public CrashHandlerHostLinux { |
[email protected] | d3c6c0d7 | 2010-12-09 08:15:04 | [diff] [blame] | 137 | public: |
138 | // Returns the singleton instance. | ||||
139 | static PluginCrashHandlerHostLinux* GetInstance(); | ||||
140 | |||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 141 | private: |
142 | friend struct DefaultSingletonTraits<PluginCrashHandlerHostLinux>; | ||||
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 143 | PluginCrashHandlerHostLinux(); |
144 | virtual ~PluginCrashHandlerHostLinux(); | ||||
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 145 | |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 146 | #if defined(USE_LINUX_BREAKPAD) |
[email protected] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 147 | virtual void SetProcessType() OVERRIDE; |
[email protected] | b064f0eb | 2010-09-02 23:53:26 | [diff] [blame] | 148 | #endif |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 149 | |
150 | DISALLOW_COPY_AND_ASSIGN(PluginCrashHandlerHostLinux); | ||||
151 | }; | ||||
152 | |||||
[email protected] | 54457f3 | 2011-04-15 22:05:29 | [diff] [blame] | 153 | class 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] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 164 | virtual void SetProcessType() OVERRIDE; |
[email protected] | 54457f3 | 2011-04-15 22:05:29 | [diff] [blame] | 165 | #endif |
166 | |||||
167 | DISALLOW_COPY_AND_ASSIGN(PpapiCrashHandlerHostLinux); | ||||
168 | }; | ||||
169 | |||||
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 170 | class 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] | dfd5064 | 2011-11-28 20:00:44 | [diff] [blame] | 181 | virtual void SetProcessType() OVERRIDE; |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 182 | #endif |
183 | |||||
184 | DISALLOW_COPY_AND_ASSIGN(RendererCrashHandlerHostLinux); | ||||
185 | }; | ||||
186 | |||||
[email protected] | 1602cde | 2012-06-26 15:09:12 | [diff] [blame] | 187 | #endif // CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_ |