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 "windows/common/ipc_protocol.h" 36 #include "common/scoped_ptr.h" 37 #include "google_breakpad/common/minidump_format.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_; } crash_id()68 DWORD crash_id() const { return crash_id_; } custom_client_info()69 const CustomClientInfo& custom_client_info() const { 70 return custom_client_info_; 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 set_process_exit_wait_handle(HANDLE value)77 void set_process_exit_wait_handle(HANDLE value) { 78 process_exit_wait_handle_ = value; 79 } 80 81 // Unregister the dump request wait operation and wait for all callbacks 82 // that might already be running to complete before returning. 83 void UnregisterDumpRequestWaitAndBlockUntilNoPending(); 84 85 // Unregister the process exit wait operation. If block_until_no_pending is 86 // true, wait for all callbacks that might already be running to complete 87 // before returning. 88 void UnregisterProcessExitWait(bool block_until_no_pending); 89 90 bool Initialize(); 91 bool GetClientExceptionInfo(EXCEPTION_POINTERS** ex_info_ptr) const; 92 93 // Reads the content of exception CONTEXT from the client process. 94 bool PopulateClientExceptionContext(EXCEPTION_POINTERS* ex_info, 95 CONTEXT* out_context) const; 96 97 bool GetClientThreadId(DWORD* thread_id) const; 98 99 // Reads the custom information from the client process address space. 100 bool PopulateCustomInfo(); 101 102 // Returns the client custom information. 103 CustomClientInfo GetCustomInfo() const; 104 105 private: 106 // Calcualtes the uptime for the client process, converts it to a string and 107 // stores it in the last entry of client custom info. 108 void SetProcessUptime(); 109 110 // Crash generation server. 111 CrashGenerationServer* crash_server_; 112 113 // Client process ID. 114 DWORD pid_; 115 116 // Dump type requested by the client. 117 MINIDUMP_TYPE dump_type_; 118 119 // Address of an EXCEPTION_POINTERS* variable in the client 120 // process address space that will point to an instance of 121 // EXCEPTION_POINTERS containing information about crash. 122 // 123 // WARNING: Do not dereference these pointers as they are pointers 124 // in the address space of another process. 125 EXCEPTION_POINTERS** ex_info_; 126 127 // Address of an instance of MDRawAssertionInfo in the client 128 // process address space that will contain information about 129 // non-exception related crashes like invalid parameter assertion 130 // failures and pure calls. 131 // 132 // WARNING: Do not dereference these pointers as they are pointers 133 // in the address space of another process. 134 MDRawAssertionInfo* assert_info_; 135 136 // Custom information about the client. 137 CustomClientInfo custom_client_info_; 138 139 // Contains the custom client info entries read from the client process 140 // memory. This will be populated only if the method GetClientCustomInfo 141 // is called. 142 scoped_array<CustomInfoEntry> custom_info_entries_; 143 144 // Address of a variable in the client process address space that 145 // will contain the thread id of the crashing client thread. 146 // 147 // WARNING: Do not dereference these pointers as they are pointers 148 // in the address space of another process. 149 DWORD* thread_id_; 150 151 // Client process handle. 152 HANDLE process_handle_; 153 154 // Dump request event handle. 155 HANDLE dump_requested_handle_; 156 157 // Dump generated event handle. 158 HANDLE dump_generated_handle_; 159 160 // Wait handle for dump request event. 161 HANDLE dump_request_wait_handle_; 162 163 // Wait handle for process exit event. 164 HANDLE process_exit_wait_handle_; 165 166 // Time when the client process started. It is used to determine the uptime 167 // for the client process when it signals a crash. 168 FILETIME start_time_; 169 170 // The crash id which can be used to request an upload. This will be the 171 // value of the low order dword of the process creation time for the process 172 // being dumped. 173 DWORD crash_id_; 174 175 // Disallow copy ctor and operator=. 176 ClientInfo(const ClientInfo& client_info); 177 ClientInfo& operator=(const ClientInfo& client_info); 178 }; 179 180 } // namespace google_breakpad 181 182 #endif // CLIENT_WINDOWS_CRASH_GENERATION_CLIENT_INFO_H__ 183