183e085b7a331c96237cf8e814f97b3ef4c36a70fjimblandy// Copyright (c) 2010 Google Inc. 2bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// All rights reserved. 3bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// 4bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// Redistribution and use in source and binary forms, with or without 5bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// modification, are permitted provided that the following conditions are 6bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// met: 7bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// 8bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// * Redistributions of source code must retain the above copyright 9bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// notice, this list of conditions and the following disclaimer. 10bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// * Redistributions in binary form must reproduce the above 11bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// copyright notice, this list of conditions and the following disclaimer 12bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// in the documentation and/or other materials provided with the 13bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// distribution. 14bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// * Neither the name of Google Inc. nor the names of its 15bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// contributors may be used to endorse or promote products derived from 16bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// this software without specific prior written permission. 17bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// 18bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 30b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid#ifndef CLIENT_LINUX_HANDLER_EXCEPTION_HANDLER_H_ 31b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid#define CLIENT_LINUX_HANDLER_EXCEPTION_HANDLER_H_ 32bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 33b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid#include <signal.h> 34ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek#include <stdint.h> 35de545c09d0363e6964822ec92529a80feaca152dnealsid#include <stdio.h> 36ed58167cd13de4fed684dcd70dd2570ec98530cedigit@chromium.org#include <sys/ucontext.h> 37bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 382ca3140490a3f295d00db687ad52194d3c970526thestig@chromium.org#include <string> 392ca3140490a3f295d00db687ad52194d3c970526thestig@chromium.org 40f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek#include "client/linux/crash_generation/crash_generation_client.h" 41e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org#include "client/linux/handler/minidump_descriptor.h" 42ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek#include "client/linux/minidump_writer/minidump_writer.h" 432cc15ba4327831f917ff55b87e6d5fc3c7750085ted.mielczarek@gmail.com#include "common/scoped_ptr.h" 444e518a4357a2d1c379d4a91df6d4e153ee791101ivan.penkov@gmail.com#include "common/using_std_string.h" 45ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek#include "google_breakpad/common/minidump_format.h" 46f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek 47bcd46f007919b5063164c8c5c6c2bd4dfb62681elulynamespace google_breakpad { 48bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 49bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// ExceptionHandler 50bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// 51bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// ExceptionHandler can write a minidump file when an exception occurs, 52bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// or when WriteMinidump() is called explicitly by your program. 53bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// 54bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// To have the exception handler write minidumps when an uncaught exception 55bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// (crash) occurs, you should create an instance early in the execution 56bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// of your program, and keep it around for the entire time you want to 57bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// have crash handling active (typically, until shutdown). 58bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// (NOTE): There should be only be one this kind of exception handler 59bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// object per process. 60bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// 61bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// If you want to write minidumps without installing the exception handler, 62bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// you can create an ExceptionHandler with install_handler set to false, 63bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// then call WriteMinidump. You can also use this technique if you want to 64bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// use different minidump callbacks for different call sites. 65bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// 66bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// In either case, a callback function is called when a minidump is written, 67e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org// which receives the full path or file descriptor of the minidump. The 68e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org// caller can collect and write additional application state to that minidump, 69e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org// and launch an external crash-reporting application. 70bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// 71bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// Caller should try to make the callbacks as crash-friendly as possible, 72bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly// it should avoid use heap memory allocation as much as possible. 73e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org 74bcd46f007919b5063164c8c5c6c2bd4dfb62681elulyclass ExceptionHandler { 75bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly public: 76bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // A callback function to run before Breakpad performs any substantial 77bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // processing of an exception. A FilterCallback is called before writing 78e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // a minidump. |context| is the parameter supplied by the user as 79bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // callback_context when the handler was created. 80bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // 81bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // If a FilterCallback returns true, Breakpad will continue processing, 82bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // attempting to write a minidump. If a FilterCallback returns false, 83bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // Breakpad will immediately report the exception as unhandled without 84bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // writing a minidump, allowing another handler the opportunity to handle it. 85bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly typedef bool (*FilterCallback)(void *context); 86bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 87bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // A callback function to run after the minidump has been written. 88e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // |descriptor| contains the file descriptor or file path containing the 89e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // minidump. |context| is the parameter supplied by the user as 90e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // callback_context when the handler was created. |succeeded| indicates 91e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // whether a minidump file was successfully written. 92bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // 93bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // If an exception occurred and the callback returns true, Breakpad will 94bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // treat the exception as fully-handled, suppressing any other handlers from 95bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // being notified of the exception. If the callback returns false, Breakpad 96bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // will treat the exception as unhandled, and allow another handler to handle 97bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // it. If there are no other handlers, Breakpad will report the exception to 98bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // the system as unhandled, allowing a debugger or native crash dialog the 99bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // opportunity to handle the exception. Most callback implementations 100bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // should normally return the value of |succeeded|, or when they wish to 101bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // not report an exception of handled, false. Callbacks will rarely want to 102bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // return true directly (unless |succeeded| is true). 103e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org typedef bool (*MinidumpCallback)(const MinidumpDescriptor& descriptor, 104e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org void* context, 105bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly bool succeeded); 106bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 107b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid // In certain cases, a user may wish to handle the generation of the minidump 108b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid // themselves. In this case, they can install a handler callback which is 1099fc581226040d32b6f0d6b171378d5ea0cdf8fb1jessicag.feedback@gmail.com // called when a crash has occurred. If this function returns true, no other 110b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid // processing of occurs and the process will shortly be crashed. If this 111b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid // returns false, the normal processing continues. 112b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid typedef bool (*HandlerCallback)(const void* crash_context, 113b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid size_t crash_context_size, 114b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid void* context); 115b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid 116bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // Creates a new ExceptionHandler instance to handle writing minidumps. 117e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // Before writing a minidump, the optional |filter| callback will be called. 118bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // Its return value determines whether or not Breakpad should write a 119e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // minidump. The minidump content will be written to the file path or file 120e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // descriptor from |descriptor|, and the optional |callback| is called after 121e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // writing the dump file, as described above. 122bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // If install_handler is true, then a minidump will be written whenever 123bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // an unhandled exception occurs. If it is false, minidumps will only 124bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // be written when WriteMinidump is called. 125e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // If |server_fd| is valid, the minidump is generated out-of-process. If it 126e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // is -1, in-process generation will always be used. 127e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org ExceptionHandler(const MinidumpDescriptor& descriptor, 128e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org FilterCallback filter, 129e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org MinidumpCallback callback, 1302ca3140490a3f295d00db687ad52194d3c970526thestig@chromium.org void* callback_context, 131f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek bool install_handler, 132f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek const int server_fd); 133bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly ~ExceptionHandler(); 134bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 135e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org const MinidumpDescriptor& minidump_descriptor() const { 136e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org return minidump_descriptor_; 137bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly } 138bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 1397dd284bd90859fcafed60eda00a421cf94a67bb6ted.mielczarek@gmail.com void set_minidump_descriptor(const MinidumpDescriptor& descriptor) { 1407dd284bd90859fcafed60eda00a421cf94a67bb6ted.mielczarek@gmail.com minidump_descriptor_ = descriptor; 1417dd284bd90859fcafed60eda00a421cf94a67bb6ted.mielczarek@gmail.com } 1427dd284bd90859fcafed60eda00a421cf94a67bb6ted.mielczarek@gmail.com 143b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid void set_crash_handler(HandlerCallback callback) { 144b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid crash_handler_ = callback; 145b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid } 146b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid 1473daf3e4247a62dccea7187e94ae06f3ec578f619rsesek@chromium.org void set_crash_generation_client(CrashGenerationClient* client) { 1483daf3e4247a62dccea7187e94ae06f3ec578f619rsesek@chromium.org crash_generation_client_.reset(client); 1493daf3e4247a62dccea7187e94ae06f3ec578f619rsesek@chromium.org } 1503daf3e4247a62dccea7187e94ae06f3ec578f619rsesek@chromium.org 151e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // Writes a minidump immediately. This can be used to capture the execution 152e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // state independently of a crash. 153e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // Returns true on success. 154e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // If the ExceptionHandler has been created with a path, a new file is 155e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // generated for each minidump. The file path can be retrieved in the 156e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // MinidumpDescriptor passed to the MinidumpCallback or by accessing the 157e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // MinidumpDescriptor directly from the ExceptionHandler (with 158e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // minidump_descriptor()). 159e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // If the ExceptionHandler has been created with a file descriptor, the file 160e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // descriptor is repositioned to its beginning and the previous generated 161e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // minidump is overwritten. 162e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // Note that this method is not supposed to be called from a compromised 163e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org // context as it uses the heap. 164bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly bool WriteMinidump(); 165bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 16621d58c728185e616c9ae8076143af0955d6fe4dfted.mielczarek // Convenience form of WriteMinidump which does not require an 167bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly // ExceptionHandler instance. 168e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org static bool WriteMinidump(const string& dump_path, 169bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly MinidumpCallback callback, 170e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org void* callback_context); 171bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 172f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // Write a minidump of |child| immediately. This can be used to 173f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // capture the execution state of |child| independently of a crash. 174f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // Pass a meaningful |child_blamed_thread| to make that thread in 175f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // the child process the one from which a crash signature is 176f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // extracted. 177f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // 178f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // WARNING: the return of this function *must* happen before 179f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // the code that will eventually reap |child| executes. 180f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // Otherwise there's a pernicious race condition in which |child| 181f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // exits, is reaped, another process created with its pid, then that 182f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com // new process dumped. 183f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com static bool WriteMinidumpForChild(pid_t child, 184f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com pid_t child_blamed_thread, 185f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com const string& dump_path, 186f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com MinidumpCallback callback, 187f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com void* callback_context); 188f092d39bfc1090285476784307a10881702179fbted.mielczarek@gmail.com 189b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid // This structure is passed to minidump_writer.h:WriteMinidump via an opaque 190b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid // blob. It shouldn't be needed in any user code. 191b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid struct CrashContext { 192b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid siginfo_t siginfo; 193b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid pid_t tid; // the crashing thread. 194b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid struct ucontext context; 195b8c5896ddca70d6926083bba0aebf860e5a3b291rmcilroy@chromium.org#if !defined(__ARM_EABI__) && !defined(__mips__) 196b8c5896ddca70d6926083bba0aebf860e5a3b291rmcilroy@chromium.org // #ifdef this out because FP state is not part of user ABI for Linux ARM. 197b8c5896ddca70d6926083bba0aebf860e5a3b291rmcilroy@chromium.org // In case of MIPS Linux FP state is already part of struct 1982eedc625759a8943d72711769a84fce05a23ecd0rmcilroy@chromium.org // ucontext so 'float_state' is not required. 199b8c5896ddca70d6926083bba0aebf860e5a3b291rmcilroy@chromium.org fpstate_t float_state; 200de545c09d0363e6964822ec92529a80feaca152dnealsid#endif 201b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid }; 202c5f46b2f4b43e331650b32cb9d286246cd4fdac1ted.mielczarek 203f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek // Returns whether out-of-process dump generation is used or not. 204f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek bool IsOutOfProcess() const { 2053daf3e4247a62dccea7187e94ae06f3ec578f619rsesek@chromium.org return crash_generation_client_.get() != NULL; 206f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek } 207f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek 208ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek // Add information about a memory mapping. This can be used if 209ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek // a custom library loader is used that maps things in a way 210ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek // that the linux dumper can't handle by reading the maps file. 2114e518a4357a2d1c379d4a91df6d4e153ee791101ivan.penkov@gmail.com void AddMappingInfo(const string& name, 2126162aed3c3fcfc53373c963ac375d39a5dfa5a25ted.mielczarek@gmail.com const uint8_t identifier[sizeof(MDGUID)], 213ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek uintptr_t start_address, 214ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek size_t mapping_size, 215ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek size_t file_offset); 216ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek 21786f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com // Register a block of memory of length bytes starting at address ptr 21886f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com // to be copied to the minidump when a crash happens. 21986f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com void RegisterAppMemory(void* ptr, size_t length); 22086f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com 22186f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com // Unregister a block of memory that was registered with RegisterAppMemory. 22286f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com void UnregisterAppMemory(void* ptr); 22386f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com 2242302ba484b3632cdf54a269cc5f5dc15fa6efc20mark@chromium.org // Force signal handling for the specified signal. 2252302ba484b3632cdf54a269cc5f5dc15fa6efc20mark@chromium.org bool SimulateSignalDelivery(int sig); 226da94a383bce9a3c0789bf571ff3775f061f7eb25ted.mielczarek@gmail.com 227da94a383bce9a3c0789bf571ff3775f061f7eb25ted.mielczarek@gmail.com // Report a crash signal from an SA_SIGINFO signal handler. 228da94a383bce9a3c0789bf571ff3775f061f7eb25ted.mielczarek@gmail.com bool HandleSignal(int sig, siginfo_t* info, void* uc); 2292ca3140490a3f295d00db687ad52194d3c970526thestig@chromium.org 230bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly private: 2313253546d4cc0e534c9a28e44d654d432aeb05a44mark@chromium.org // Save the old signal handlers and install new ones. 2323253546d4cc0e534c9a28e44d654d432aeb05a44mark@chromium.org static bool InstallHandlersLocked(); 2333253546d4cc0e534c9a28e44d654d432aeb05a44mark@chromium.org // Restore the old signal handlers. 2343253546d4cc0e534c9a28e44d654d432aeb05a44mark@chromium.org static void RestoreHandlersLocked(); 2353253546d4cc0e534c9a28e44d654d432aeb05a44mark@chromium.org 236b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid void PreresolveSymbols(); 237f7f9dfcab6483033ea94a4756d53a6c052df3ae6brdevmn bool GenerateDump(CrashContext *context); 238662b6da59dd0218ea5496c085cb010d59f2b4219ted.mielczarek void SendContinueSignalToChild(); 239662b6da59dd0218ea5496c085cb010d59f2b4219ted.mielczarek void WaitForContinueSignal(); 240bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 241b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid static void SignalHandler(int sig, siginfo_t* info, void* uc); 242b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid static int ThreadEntry(void* arg); 243b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid bool DoDump(pid_t crashing_process, const void* context, 244b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid size_t context_size); 245c5f46b2f4b43e331650b32cb9d286246cd4fdac1ted.mielczarek 246b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid const FilterCallback filter_; 247b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid const MinidumpCallback callback_; 248b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid void* const callback_context_; 249c5f46b2f4b43e331650b32cb9d286246cd4fdac1ted.mielczarek 250f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek scoped_ptr<CrashGenerationClient> crash_generation_client_; 251f480ba116971a56d4de25ae1df2369e3d5503d16ted.mielczarek 252e751dcaed67b71fa950d1f2c54cd0ddc365248f8jcivelli@chromium.org MinidumpDescriptor minidump_descriptor_; 253bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 25467f3ea4cfdb24279389cc5c1f375213d961553cbrmcilroy@chromium.org // Must be volatile. The compiler is unaware of the code which runs in 25567f3ea4cfdb24279389cc5c1f375213d961553cbrmcilroy@chromium.org // the signal handler which reads this variable. Without volatile the 25667f3ea4cfdb24279389cc5c1f375213d961553cbrmcilroy@chromium.org // compiler is free to optimise away writes to this variable which it 25767f3ea4cfdb24279389cc5c1f375213d961553cbrmcilroy@chromium.org // believes are never read. 25867f3ea4cfdb24279389cc5c1f375213d961553cbrmcilroy@chromium.org volatile HandlerCallback crash_handler_; 259bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 260662b6da59dd0218ea5496c085cb010d59f2b4219ted.mielczarek // We need to explicitly enable ptrace of parent processes on some 261662b6da59dd0218ea5496c085cb010d59f2b4219ted.mielczarek // kernels, but we need to know the PID of the cloned process before we 262662b6da59dd0218ea5496c085cb010d59f2b4219ted.mielczarek // can do this. We create a pipe which we can use to block the 2632eedc625759a8943d72711769a84fce05a23ecd0rmcilroy@chromium.org // cloned process after creating it, until we have explicitly enabled 264662b6da59dd0218ea5496c085cb010d59f2b4219ted.mielczarek // ptrace. This is used to store the file descriptors for the pipe 265662b6da59dd0218ea5496c085cb010d59f2b4219ted.mielczarek int fdes[2]; 266ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek 267ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek // Callers can add extra info about mappings for cases where the 268ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek // dumper code cannot extract enough information from /proc/<pid>/maps. 269ef7262d4775bf6de750bc2a26dbf98368d7ec0c3ted.mielczarek MappingList mapping_list_; 27086f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com 27186f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com // Callers can request additional memory regions to be included in 27286f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com // the dump. 27386f79a00ae0829dae0136f758eafbe7c220e0c0dted.mielczarek@gmail.com AppMemoryList app_memory_list_; 274bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly}; 275bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 276bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly} // namespace google_breakpad 277bcd46f007919b5063164c8c5c6c2bd4dfb62681eluly 278b0baafc4da1f3ffb84e267dd19d176db3de1c14enealsid#endif // CLIENT_LINUX_HANDLER_EXCEPTION_HANDLER_H_ 279