Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / breakpad / src / client / linux / minidump_writer / minidump_writer.h
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 <sys/ucontext.h>
36 #include <unistd.h>
37
38 #include <list>
39 #include <utility>
40
41 #include "client/linux/minidump_writer/linux_dumper.h"
42 #include "google_breakpad/common/minidump_format.h"
43
44 namespace google_breakpad {
45
46 class ExceptionHandler;
47
48 struct MappingEntry {
49   MappingInfo first;
50   uint8_t second[sizeof(MDGUID)];
51 };
52
53 // A list of <MappingInfo, GUID>
54 typedef std::list<MappingEntry> MappingList;
55
56 #if defined(__aarch64__)
57 typedef struct fpsimd_context fpstate_t;
58 #elif !defined(__ARM_EABI__) && !defined(__mips__)
59 typedef struct _libc_fpstate fpstate_t;
60 #endif
61
62 // These entries store a list of memory regions that the client wants included
63 // in the minidump.
64 struct AppMemory {
65   void* ptr;
66   size_t length;
67
68   bool operator==(const struct AppMemory& other) const {
69     return ptr == other.ptr;
70   }
71
72   bool operator==(const void* other) const {
73     return ptr == other;
74   }
75 };
76 typedef std::list<AppMemory> AppMemoryList;
77
78 // Writes a minidump to the filesystem. These functions do not malloc nor use
79 // libc functions which may. Thus, it can be used in contexts where the state
80 // of the heap may be corrupt.
81 //   minidump_path: the path to the file to write to. This is opened O_EXCL and
82 //     fails open fails.
83 //   crashing_process: the pid of the crashing process. This must be trusted.
84 //   blob: a blob of data from the crashing process. See exception_handler.h
85 //   blob_size: the length of |blob|, in bytes
86 //
87 // Returns true iff successful.
88 bool WriteMinidump(const char* minidump_path, pid_t crashing_process,
89                    const void* blob, size_t blob_size);
90 // Same as above but takes an open file descriptor instead of a path.
91 bool WriteMinidump(int minidump_fd, pid_t crashing_process,
92                    const void* blob, size_t blob_size);
93
94 // Alternate form of WriteMinidump() that works with processes that
95 // are not expected to have crashed.  If |process_blamed_thread| is
96 // meaningful, it will be the one from which a crash signature is
97 // extracted.  It is not expected that this function will be called
98 // from a compromised context, but it is safe to do so.
99 bool WriteMinidump(const char* minidump_path, pid_t process,
100                    pid_t process_blamed_thread);
101
102 // These overloads also allow passing a list of known mappings and
103 // a list of additional memory regions to be included in the minidump.
104 bool WriteMinidump(const char* minidump_path, pid_t crashing_process,
105                    const void* blob, size_t blob_size,
106                    const MappingList& mappings,
107                    const AppMemoryList& appdata);
108 bool WriteMinidump(int minidump_fd, pid_t crashing_process,
109                    const void* blob, size_t blob_size,
110                    const MappingList& mappings,
111                    const AppMemoryList& appdata);
112
113 // These overloads also allow passing a file size limit for the minidump.
114 bool WriteMinidump(const char* minidump_path, off_t minidump_size_limit,
115                    pid_t crashing_process,
116                    const void* blob, size_t blob_size,
117                    const MappingList& mappings,
118                    const AppMemoryList& appdata);
119 bool WriteMinidump(int minidump_fd, off_t minidump_size_limit,
120                    pid_t crashing_process,
121                    const void* blob, size_t blob_size,
122                    const MappingList& mappings,
123                    const AppMemoryList& appdata);
124
125 bool WriteMinidump(const char* filename,
126                    const MappingList& mappings,
127                    const AppMemoryList& appdata,
128                    LinuxDumper* dumper);
129
130 }  // namespace google_breakpad
131
132 #endif  // CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_