1 // Copyright (c) 2008, 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_WINDOWS_CRASH_GENERATION_CLIENT_INFO_H__ 31 #define CLIENT_WINDOWS_CRASH_GENERATION_CLIENT_INFO_H__ 32 33 #include <Windows.h> 34 #include <DbgHelp.h> 35 #include "client/windows/common/ipc_protocol.h" 36 #include "google_breakpad/common/minidump_format.h" 37 #include "processor/scoped_ptr.h" 38 39 namespace google_breakpad { 40 41 class CrashGenerationServer; 42 43 // Abstraction for a crash client process. 44 class ClientInfo { 45 public: 46 // Creates an instance with the given values. Gets the process 47 // handle for the given process id and creates necessary event 48 // objects. 49 ClientInfo(CrashGenerationServer* crash_server, 50 DWORD pid, 51 MINIDUMP_TYPE dump_type, 52 DWORD* thread_id, 53 EXCEPTION_POINTERS** ex_info, 54 MDRawAssertionInfo* assert_info, 55 const CustomClientInfo& custom_client_info); 56 57 ~ClientInfo(); 58 crash_server()59 CrashGenerationServer* crash_server() const { return crash_server_; } pid()60 DWORD pid() const { return pid_; } dump_type()61 MINIDUMP_TYPE dump_type() const { return dump_type_; } ex_info()62 EXCEPTION_POINTERS** ex_info() const { return ex_info_; } assert_info()63 MDRawAssertionInfo* assert_info() const { return assert_info_; } thread_id()64 DWORD* thread_id() const { return thread_id_; } process_handle()65 HANDLE process_handle() const { return process_handle_; } dump_requested_handle()66 HANDLE dump_requested_handle() const { return dump_requested_handle_; } dump_generated_handle()67 HANDLE dump_generated_handle() const { return dump_generated_handle_; } 68 dump_request_wait_handle()69 HANDLE dump_request_wait_handle() const { 70 return dump_request_wait_handle_; 71 } 72 set_dump_request_wait_handle(HANDLE value)73 void set_dump_request_wait_handle(HANDLE value) { 74 dump_request_wait_handle_ = value; 75 } 76 process_exit_wait_handle()77 HANDLE process_exit_wait_handle() const { 78 return process_exit_wait_handle_; 79 } 80 set_process_exit_wait_handle(HANDLE value)81 void set_process_exit_wait_handle(HANDLE value) { 82 process_exit_wait_handle_ = value; 83 } 84 85 // Unregister all waits for the client. 86 bool UnregisterWaits(); 87 88 bool Initialize(); 89 bool GetClientExceptionInfo(EXCEPTION_POINTERS** ex_info) const; 90 bool GetClientThreadId(DWORD* thread_id) const; 91 92 // Reads the custom information from the client process address space. 93 bool PopulateCustomInfo(); 94 95 // Returns the client custom information. 96 CustomClientInfo GetCustomInfo() const; 97 98 private: 99 // Calcualtes the uptime for the client process, converts it to a string and 100 // stores it in the last entry of client custom info. 101 void SetProcessUptime(); 102 103 // Crash generation server. 104 CrashGenerationServer* crash_server_; 105 106 // Client process ID. 107 DWORD pid_; 108 109 // Dump type requested by the client. 110 MINIDUMP_TYPE dump_type_; 111 112 // Address of an EXCEPTION_POINTERS* variable in the client 113 // process address space that will point to an instance of 114 // EXCEPTION_POINTERS containing information about crash. 115 // 116 // WARNING: Do not dereference these pointers as they are pointers 117 // in the address space of another process. 118 EXCEPTION_POINTERS** ex_info_; 119 120 // Address of an instance of MDRawAssertionInfo in the client 121 // process address space that will contain information about 122 // non-exception related crashes like invalid parameter assertion 123 // failures and pure calls. 124 // 125 // WARNING: Do not dereference these pointers as they are pointers 126 // in the address space of another process. 127 MDRawAssertionInfo* assert_info_; 128 129 // Custom information about the client. 130 CustomClientInfo custom_client_info_; 131 132 // Contains the custom client info entries read from the client process 133 // memory. This will be populated only if the method GetClientCustomInfo 134 // is called. 135 scoped_array<CustomInfoEntry> custom_info_entries_; 136 137 // Address of a variable in the client process address space that 138 // will contain the thread id of the crashing client thread. 139 // 140 // WARNING: Do not dereference these pointers as they are pointers 141 // in the address space of another process. 142 DWORD* thread_id_; 143 144 // Client process handle. 145 HANDLE process_handle_; 146 147 // Dump request event handle. 148 HANDLE dump_requested_handle_; 149 150 // Dump generated event handle. 151 HANDLE dump_generated_handle_; 152 153 // Wait handle for dump request event. 154 HANDLE dump_request_wait_handle_; 155 156 // Wait handle for process exit event. 157 HANDLE process_exit_wait_handle_; 158 159 // Time when the client process started. It is used to determine the uptime 160 // for the client process when it signals a crash. 161 FILETIME start_time_; 162 163 // Disallow copy ctor and operator=. 164 ClientInfo(const ClientInfo& client_info); 165 ClientInfo& operator=(const ClientInfo& client_info); 166 }; 167 168 } // namespace google_breakpad 169 170 #endif // CLIENT_WINDOWS_CRASH_GENERATION_CLIENT_INFO_H__ 171