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 <list>
34 : #include <utility>
35 :
36 : #include <stdint.h>
37 : #include <unistd.h>
38 :
39 : #include "google_breakpad/common/minidump_format.h"
40 :
41 : namespace google_breakpad {
42 :
43 : // A list of <MappingInfo, GUID>
44 : typedef std::pair<struct MappingInfo, u_int8_t[sizeof(MDGUID)]> MappingEntry;
45 : typedef std::list<MappingEntry> MappingList;
46 :
47 : // These entries store a list of memory regions that the client wants included
48 : // in the minidump.
49 : struct AppMemory {
50 0 : AppMemory(void *ptr, size_t length) : ptr(ptr), length(length) {}
51 :
52 : void *ptr;
53 : size_t length;
54 : };
55 : typedef std::list<AppMemory> AppMemoryList;
56 :
57 : // Write a minidump to the filesystem. This function does not malloc nor use
58 : // libc functions which may. Thus, it can be used in contexts where the state
59 : // of the heap may be corrupt.
60 : // filename: the filename to write to. This is opened O_EXCL and fails if
61 : // open fails.
62 : // crashing_process: the pid of the crashing process. This must be trusted.
63 : // blob: a blob of data from the crashing process. See exception_handler.h
64 : // blob_size: the length of |blob|, in bytes
65 : //
66 : // Returns true iff successful.
67 : bool WriteMinidump(const char* filename, pid_t crashing_process,
68 : const void* blob, size_t blob_size);
69 :
70 : // Alternate form of WriteMinidump() that works with processes that
71 : // are not expected to have crashed. If |process_blamed_thread| is
72 : // meaningful, it will be the one from which a crash signature is
73 : // extracted. It is not expected that this function will be called
74 : // from a compromised context, but it is safe to do so.
75 : bool WriteMinidump(const char* filename, pid_t process,
76 : pid_t process_blamed_thread);
77 :
78 : // This overload also allows passing a list of known mappings and
79 : // a list of additional memory regions to be included in the minidump.
80 : bool WriteMinidump(const char* filename, pid_t crashing_process,
81 : const void* blob, size_t blob_size,
82 : const MappingList& mappings,
83 : const AppMemoryList& appdata);
84 :
85 : } // namespace google_breakpad
86 :
87 : #endif // CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_
|