Bug 628949 - Update visible region / glass regions after we paint. r=roc a=2.0.
[mozilla-central.git] / toolkit / crashreporter / nsExceptionHandler.h
blob6478c6204aac8346a22798ac7d9c983fd3d070a4
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Breakpad integration
17 * The Initial Developer of the Original Code is
18 * Ted Mielczarek <ted.mielczarek@gmail.com>
19 * Portions created by the Initial Developer are Copyright (C) 2006
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsExceptionHandler_h__
39 #define nsExceptionHandler_h__
41 #include "nscore.h"
42 #include "nsDataHashtable.h"
43 #include "nsXPCOM.h"
44 #include "nsStringGlue.h"
46 #include "nsIFile.h"
48 #if defined(XP_WIN32)
49 #ifdef WIN32_LEAN_AND_MEAN
50 #undef WIN32_LEAN_AND_MEAN
51 #endif
52 #include <windows.h>
53 #endif
55 #if defined(XP_MACOSX)
56 #include <mach/mach.h>
57 #endif
59 namespace CrashReporter {
60 nsresult SetExceptionHandler(nsILocalFile* aXREDirectory, bool force=false);
61 nsresult UnsetExceptionHandler();
62 bool GetEnabled();
63 bool GetServerURL(nsACString& aServerURL);
64 nsresult SetServerURL(const nsACString& aServerURL);
65 bool GetMinidumpPath(nsAString& aPath);
66 nsresult SetMinidumpPath(const nsAString& aPath);
67 nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data);
68 nsresult AppendAppNotesToCrashReport(const nsACString& data);
69 nsresult SetRestartArgs(int argc, char** argv);
70 nsresult SetupExtraData(nsILocalFile* aAppDataDirectory,
71 const nsACString& aBuildID);
73 // Functions for working with minidumps and .extras
74 typedef nsDataHashtable<nsCStringHashKey, nsCString> AnnotationTable;
76 bool GetMinidumpForID(const nsAString& id, nsILocalFile** minidump);
77 bool GetIDFromMinidump(nsILocalFile* minidump, nsAString& id);
78 bool GetExtraFileForID(const nsAString& id, nsILocalFile** extraFile);
79 bool GetExtraFileForMinidump(nsILocalFile* minidump, nsILocalFile** extraFile);
80 bool AppendExtraData(const nsAString& id, const AnnotationTable& data);
81 bool AppendExtraData(nsILocalFile* extraFile, const AnnotationTable& data);
83 #ifdef XP_WIN32
84 nsresult WriteMinidumpForException(EXCEPTION_POINTERS* aExceptionInfo);
85 #endif
86 #ifdef XP_MACOSX
87 nsresult AppendObjCExceptionInfoToAppNotes(void *inException);
88 #endif
89 nsresult GetSubmitReports(PRBool* aSubmitReport);
90 nsresult SetSubmitReports(PRBool aSubmitReport);
92 #ifdef MOZ_IPC
93 // Out-of-process crash reporter API.
95 // Return true iff a dump was found for |childPid|, and return the
96 // path in |dump|. The caller owns the last reference to |dump| if it
97 // is non-NULL.
98 bool TakeMinidumpForChild(PRUint32 childPid,
99 nsILocalFile** dump NS_OUTPARAM);
101 #if defined(XP_WIN)
102 typedef HANDLE ProcessHandle;
103 typedef DWORD ThreadId;
104 #elif defined(XP_MACOSX)
105 typedef task_t ProcessHandle;
106 typedef mach_port_t ThreadId;
107 #else
108 typedef int ProcessHandle;
109 typedef int ThreadId;
110 #endif
112 // Return the current thread's ID.
114 // XXX: this is a somewhat out-of-place interface to expose through
115 // crashreporter, but it takes significant work to call sys_gettid()
116 // correctly on Linux and breakpad has already jumped through those
117 // hoops for us.
118 ThreadId CurrentThreadId();
120 // Create new minidumps that are snapshots of the state of this parent
121 // process and |childPid|. Return true on success along with the
122 // minidumps and a new UUID that can be used to correlate the dumps.
124 // If this function fails, it's the caller's responsibility to clean
125 // up |childDump| and |parentDump|. Either or both can be created and
126 // returned non-null on failure.
127 bool CreatePairedMinidumps(ProcessHandle childPid,
128 ThreadId childBlamedThread,
129 nsAString* pairGUID NS_OUTPARAM,
130 nsILocalFile** childDump NS_OUTPARAM,
131 nsILocalFile** parentDump NS_OUTPARAM);
133 # if defined(XP_WIN32) || defined(XP_MACOSX)
134 // Parent-side API for children
135 const char* GetChildNotificationPipe();
137 // Child-side API
138 bool SetRemoteExceptionHandler(const nsACString& crashPipe);
140 # elif defined(XP_LINUX)
141 // Parent-side API for children
143 // Set the outparams for crash reporter server's fd (|childCrashFd|)
144 // and the magic fd number it should be remapped to
145 // (|childCrashRemapFd|) before exec() in the child process.
146 // |SetRemoteExceptionHandler()| in the child process expects to find
147 // the server at |childCrashRemapFd|. Return true iff successful.
149 // If crash reporting is disabled, both outparams will be set to -1
150 // and |true| will be returned.
151 bool CreateNotificationPipeForChild(int* childCrashFd, int* childCrashRemapFd);
153 // Child-side API
154 bool SetRemoteExceptionHandler();
156 #endif // XP_WIN32
158 bool UnsetRemoteExceptionHandler();
159 #endif // MOZ_IPC
161 #if defined(__ANDROID__)
162 // Android builds use a custom library loader, so /proc/<pid>/maps
163 // will just show anonymous mappings for all the non-system
164 // shared libraries. This API is to work around that by providing
165 // info about the shared libraries that are mapped into these anonymous
166 // mappings.
167 void AddLibraryMapping(const char* library_name,
168 const char* file_id,
169 uintptr_t start_address,
170 size_t mapping_length,
171 size_t file_offset);
173 #if defined(MOZ_IPC)
174 void AddLibraryMappingForChild(PRUint32 childPid,
175 const char* library_name,
176 const char* file_id,
177 uintptr_t start_address,
178 size_t mapping_length,
179 size_t file_offset);
180 void RemoveLibraryMappingsForChild(PRUint32 childPid);
181 #endif
182 #endif
185 #endif /* nsExceptionHandler_h__ */