Planeshift
|
00001 // Copyright (c) 2008, 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_WINDOWS_COMMON_IPC_PROTOCOL_H__ 00031 #define CLIENT_WINDOWS_COMMON_IPC_PROTOCOL_H__ 00032 00033 #include <Windows.h> 00034 #include <DbgHelp.h> 00035 #include <string> 00036 #include <utility> 00037 #include "common/windows/string_utils-inl.h" 00038 #include "google_breakpad/common/minidump_format.h" 00039 00040 namespace google_breakpad { 00041 00042 // Name/value pair for custom client information. 00043 struct CustomInfoEntry { 00044 // Maximum length for name and value for client custom info. 00045 static const int kNameMaxLength = 64; 00046 static const int kValueMaxLength = 64; 00047 00048 CustomInfoEntry() { 00049 // Putting name and value in initializer list makes VC++ show warning 4351. 00050 set_name(NULL); 00051 set_value(NULL); 00052 } 00053 00054 CustomInfoEntry(const wchar_t* name_arg, const wchar_t* value_arg) { 00055 set_name(name_arg); 00056 set_value(value_arg); 00057 } 00058 00059 void set_name(const wchar_t* name_arg) { 00060 if (!name_arg) { 00061 name[0] = L'\0'; 00062 return; 00063 } 00064 WindowsStringUtils::safe_wcscpy(name, kNameMaxLength, name_arg); 00065 } 00066 00067 void set_value(const wchar_t* value_arg) { 00068 if (!value_arg) { 00069 value[0] = L'\0'; 00070 return; 00071 } 00072 00073 WindowsStringUtils::safe_wcscpy(value, kValueMaxLength, value_arg); 00074 } 00075 00076 void set(const wchar_t* name_arg, const wchar_t* value_arg) { 00077 set_name(name_arg); 00078 set_value(value_arg); 00079 } 00080 00081 wchar_t name[kNameMaxLength]; 00082 wchar_t value[kValueMaxLength]; 00083 }; 00084 00085 // Constants for the protocol between client and the server. 00086 00087 // Tags sent with each message indicating the purpose of 00088 // the message. 00089 enum MessageTag { 00090 MESSAGE_TAG_NONE = 0, 00091 MESSAGE_TAG_REGISTRATION_REQUEST = 1, 00092 MESSAGE_TAG_REGISTRATION_RESPONSE = 2, 00093 MESSAGE_TAG_REGISTRATION_ACK = 3, 00094 MESSAGE_TAG_UPLOAD_REQUEST = 4 00095 }; 00096 00097 struct CustomClientInfo { 00098 const CustomInfoEntry* entries; 00099 size_t count; 00100 }; 00101 00102 // Message structure for IPC between crash client and crash server. 00103 struct ProtocolMessage { 00104 ProtocolMessage() 00105 : tag(MESSAGE_TAG_NONE), 00106 id(0), 00107 dump_type(MiniDumpNormal), 00108 thread_id(0), 00109 exception_pointers(NULL), 00110 assert_info(NULL), 00111 custom_client_info(), 00112 dump_request_handle(NULL), 00113 dump_generated_handle(NULL), 00114 server_alive_handle(NULL) { 00115 } 00116 00117 // Creates an instance with the given parameters. 00118 ProtocolMessage(MessageTag arg_tag, 00119 DWORD arg_id, 00120 MINIDUMP_TYPE arg_dump_type, 00121 DWORD* arg_thread_id, 00122 EXCEPTION_POINTERS** arg_exception_pointers, 00123 MDRawAssertionInfo* arg_assert_info, 00124 const CustomClientInfo& custom_info, 00125 HANDLE arg_dump_request_handle, 00126 HANDLE arg_dump_generated_handle, 00127 HANDLE arg_server_alive) 00128 : tag(arg_tag), 00129 id(arg_id), 00130 dump_type(arg_dump_type), 00131 thread_id(arg_thread_id), 00132 exception_pointers(arg_exception_pointers), 00133 assert_info(arg_assert_info), 00134 custom_client_info(custom_info), 00135 dump_request_handle(arg_dump_request_handle), 00136 dump_generated_handle(arg_dump_generated_handle), 00137 server_alive_handle(arg_server_alive) { 00138 } 00139 00140 // Tag in the message. 00141 MessageTag tag; 00142 00143 // The id for this message. This may be either a process id or a crash id 00144 // depending on the type of message. 00145 DWORD id; 00146 00147 // Dump type requested. 00148 MINIDUMP_TYPE dump_type; 00149 00150 // Client thread id pointer. 00151 DWORD* thread_id; 00152 00153 // Exception information. 00154 EXCEPTION_POINTERS** exception_pointers; 00155 00156 // Assert information in case of an invalid parameter or 00157 // pure call failure. 00158 MDRawAssertionInfo* assert_info; 00159 00160 // Custom client information. 00161 CustomClientInfo custom_client_info; 00162 00163 // Handle to signal the crash event. 00164 HANDLE dump_request_handle; 00165 00166 // Handle to check if server is done generating crash. 00167 HANDLE dump_generated_handle; 00168 00169 // Handle to a mutex that becomes signaled (WAIT_ABANDONED) 00170 // if server process goes down. 00171 HANDLE server_alive_handle; 00172 00173 private: 00174 // Disable copy ctor and operator=. 00175 ProtocolMessage(const ProtocolMessage& msg); 00176 ProtocolMessage& operator=(const ProtocolMessage& msg); 00177 }; 00178 00179 } // namespace google_breakpad 00180 00181 #endif // CLIENT_WINDOWS_COMMON_IPC_PROTOCOL_H__