Planeshift
minidump_writer.h
Go to the documentation of this file.
1 // Copyright (c) 2009, Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_
31 #define CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_
32 
33 #include <stdint.h>
34 #include <sys/types.h>
35 #include <unistd.h>
36 
37 #include <list>
38 #include <utility>
39 
42 
43 namespace google_breakpad {
44 
45 class ExceptionHandler;
46 
47 struct MappingEntry {
49  uint8_t second[sizeof(MDGUID)];
50 };
51 
52 // A list of <MappingInfo, GUID>
53 typedef std::list<MappingEntry> MappingList;
54 
55 // These entries store a list of memory regions that the client wants included
56 // in the minidump.
57 struct AppMemory {
58  void* ptr;
59  size_t length;
60 
61  bool operator==(const struct AppMemory& other) const {
62  return ptr == other.ptr;
63  }
64 
65  bool operator==(const void* other) const {
66  return ptr == other;
67  }
68 };
69 typedef std::list<AppMemory> AppMemoryList;
70 
71 // Writes a minidump to the filesystem. These functions do not malloc nor use
72 // libc functions which may. Thus, it can be used in contexts where the state
73 // of the heap may be corrupt.
74 // minidump_path: the path to the file to write to. This is opened O_EXCL and
75 // fails open fails.
76 // crashing_process: the pid of the crashing process. This must be trusted.
77 // blob: a blob of data from the crashing process. See exception_handler.h
78 // blob_size: the length of |blob|, in bytes
79 //
80 // Returns true iff successful.
81 bool WriteMinidump(const char* minidump_path, pid_t crashing_process,
82  const void* blob, size_t blob_size);
83 // Same as above but takes an open file descriptor instead of a path.
84 bool WriteMinidump(int minidump_fd, pid_t crashing_process,
85  const void* blob, size_t blob_size);
86 
87 // Alternate form of WriteMinidump() that works with processes that
88 // are not expected to have crashed. If |process_blamed_thread| is
89 // meaningful, it will be the one from which a crash signature is
90 // extracted. It is not expected that this function will be called
91 // from a compromised context, but it is safe to do so.
92 bool WriteMinidump(const char* minidump_path, pid_t process,
93  pid_t process_blamed_thread);
94 
95 // These overloads also allow passing a list of known mappings and
96 // a list of additional memory regions to be included in the minidump.
97 bool WriteMinidump(const char* minidump_path, pid_t crashing_process,
98  const void* blob, size_t blob_size,
99  const MappingList& mappings,
100  const AppMemoryList& appdata);
101 bool WriteMinidump(int minidump_fd, pid_t crashing_process,
102  const void* blob, size_t blob_size,
103  const MappingList& mappings,
104  const AppMemoryList& appdata);
105 
106 // These overloads also allow passing a file size limit for the minidump.
107 bool WriteMinidump(const char* minidump_path, off_t minidump_size_limit,
108  pid_t crashing_process,
109  const void* blob, size_t blob_size,
110  const MappingList& mappings,
111  const AppMemoryList& appdata);
112 bool WriteMinidump(int minidump_fd, off_t minidump_size_limit,
113  pid_t crashing_process,
114  const void* blob, size_t blob_size,
115  const MappingList& mappings,
116  const AppMemoryList& appdata);
117 
118 bool WriteMinidump(const char* filename,
119  const MappingList& mappings,
120  const AppMemoryList& appdata,
121  LinuxDumper* dumper);
122 
123 } // namespace google_breakpad
124 
125 #endif // CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_
bool operator==(const void *other) const
std::list< MappingEntry > MappingList
bool operator==(const struct AppMemory &other) const
bool WriteMinidump(const char *minidump_path, pid_t crashing_process, const void *blob, size_t blob_size)
std::list< AppMemory > AppMemoryList
uint8_t second[sizeof(MDGUID)]