Planeshift

minidump_writer.h

Go to the documentation of this file.
00001 // Copyright (c) 2009, Google Inc.
00002 // All rights reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 
00030 #ifndef CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_
00031 #define CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_
00032 
00033 #include <stdint.h>
00034 #include <sys/types.h>
00035 #include <unistd.h>
00036 
00037 #include <list>
00038 #include <utility>
00039 
00040 #include "client/linux/minidump_writer/linux_dumper.h"
00041 #include "google_breakpad/common/minidump_format.h"
00042 
00043 namespace google_breakpad {
00044 
00045 class ExceptionHandler;
00046 
00047 struct MappingEntry {
00048   MappingInfo first;
00049   uint8_t second[sizeof(MDGUID)];
00050 };
00051 
00052 // A list of <MappingInfo, GUID>
00053 typedef std::list<MappingEntry> MappingList;
00054 
00055 // These entries store a list of memory regions that the client wants included
00056 // in the minidump.
00057 struct AppMemory {
00058   void* ptr;
00059   size_t length;
00060 
00061   bool operator==(const struct AppMemory& other) const {
00062     return ptr == other.ptr;
00063   }
00064 
00065   bool operator==(const void* other) const {
00066     return ptr == other;
00067   }
00068 };
00069 typedef std::list<AppMemory> AppMemoryList;
00070 
00071 // Writes a minidump to the filesystem. These functions do not malloc nor use
00072 // libc functions which may. Thus, it can be used in contexts where the state
00073 // of the heap may be corrupt.
00074 //   minidump_path: the path to the file to write to. This is opened O_EXCL and
00075 //     fails open fails.
00076 //   crashing_process: the pid of the crashing process. This must be trusted.
00077 //   blob: a blob of data from the crashing process. See exception_handler.h
00078 //   blob_size: the length of |blob|, in bytes
00079 //
00080 // Returns true iff successful.
00081 bool WriteMinidump(const char* minidump_path, pid_t crashing_process,
00082                    const void* blob, size_t blob_size);
00083 // Same as above but takes an open file descriptor instead of a path.
00084 bool WriteMinidump(int minidump_fd, pid_t crashing_process,
00085                    const void* blob, size_t blob_size);
00086 
00087 // Alternate form of WriteMinidump() that works with processes that
00088 // are not expected to have crashed.  If |process_blamed_thread| is
00089 // meaningful, it will be the one from which a crash signature is
00090 // extracted.  It is not expected that this function will be called
00091 // from a compromised context, but it is safe to do so.
00092 bool WriteMinidump(const char* minidump_path, pid_t process,
00093                    pid_t process_blamed_thread);
00094 
00095 // These overloads also allow passing a list of known mappings and
00096 // a list of additional memory regions to be included in the minidump.
00097 bool WriteMinidump(const char* minidump_path, pid_t crashing_process,
00098                    const void* blob, size_t blob_size,
00099                    const MappingList& mappings,
00100                    const AppMemoryList& appdata);
00101 bool WriteMinidump(int minidump_fd, pid_t crashing_process,
00102                    const void* blob, size_t blob_size,
00103                    const MappingList& mappings,
00104                    const AppMemoryList& appdata);
00105 
00106 // These overloads also allow passing a file size limit for the minidump.
00107 bool WriteMinidump(const char* minidump_path, off_t minidump_size_limit,
00108                    pid_t crashing_process,
00109                    const void* blob, size_t blob_size,
00110                    const MappingList& mappings,
00111                    const AppMemoryList& appdata);
00112 bool WriteMinidump(int minidump_fd, off_t minidump_size_limit,
00113                    pid_t crashing_process,
00114                    const void* blob, size_t blob_size,
00115                    const MappingList& mappings,
00116                    const AppMemoryList& appdata);
00117 
00118 bool WriteMinidump(const char* filename,
00119                    const MappingList& mappings,
00120                    const AppMemoryList& appdata,
00121                    LinuxDumper* dumper);
00122 
00123 }  // namespace google_breakpad
00124 
00125 #endif  // CLIENT_LINUX_MINIDUMP_WRITER_MINIDUMP_WRITER_H_