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