xref: /aosp_15_r20/external/google-breakpad/src/client/windows/common/ipc_protocol.h (revision 9712c20fc9bbfbac4935993a2ca0b3958c5adad2)
1 // Copyright 2008 Google LLC
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //     * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //     * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //     * Neither the name of Google LLC nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #ifndef CLIENT_WINDOWS_COMMON_IPC_PROTOCOL_H__
30 #define CLIENT_WINDOWS_COMMON_IPC_PROTOCOL_H__
31 
32 #include <windows.h>
33 #include <dbghelp.h>
34 #include <string>
35 #include <utility>
36 #include "common/windows/string_utils-inl.h"
37 #include "google_breakpad/common/minidump_format.h"
38 
39 namespace google_breakpad {
40 
41 // Name/value pair for custom client information.
42 struct CustomInfoEntry {
43   // Maximum length for name and value for client custom info.
44   static const int kNameMaxLength = 64;
45   static const int kValueMaxLength = 64;
46 
CustomInfoEntryCustomInfoEntry47   CustomInfoEntry() {
48     // Putting name and value in initializer list makes VC++ show warning 4351.
49     set_name(NULL);
50     set_value(NULL);
51   }
52 
CustomInfoEntryCustomInfoEntry53   CustomInfoEntry(const wchar_t* name_arg, const wchar_t* value_arg) {
54     set_name(name_arg);
55     set_value(value_arg);
56   }
57 
set_nameCustomInfoEntry58   void set_name(const wchar_t* name_arg) {
59     if (!name_arg) {
60       name[0] = L'\0';
61       return;
62     }
63     WindowsStringUtils::safe_wcscpy(name, kNameMaxLength, name_arg);
64   }
65 
set_valueCustomInfoEntry66   void set_value(const wchar_t* value_arg) {
67     if (!value_arg) {
68       value[0] = L'\0';
69       return;
70     }
71 
72     WindowsStringUtils::safe_wcscpy(value, kValueMaxLength, value_arg);
73   }
74 
setCustomInfoEntry75   void set(const wchar_t* name_arg, const wchar_t* value_arg) {
76     set_name(name_arg);
77     set_value(value_arg);
78   }
79 
80   wchar_t name[kNameMaxLength];
81   wchar_t value[kValueMaxLength];
82 };
83 
84 // Constants for the protocol between client and the server.
85 
86 // Tags sent with each message indicating the purpose of
87 // the message.
88 enum MessageTag {
89   MESSAGE_TAG_NONE = 0,
90   MESSAGE_TAG_REGISTRATION_REQUEST = 1,
91   MESSAGE_TAG_REGISTRATION_RESPONSE = 2,
92   MESSAGE_TAG_REGISTRATION_ACK = 3,
93   MESSAGE_TAG_UPLOAD_REQUEST = 4
94 };
95 
96 struct CustomClientInfo {
97   const CustomInfoEntry* entries;
98   size_t count;
99 };
100 
101 // Message structure for IPC between crash client and crash server.
102 struct ProtocolMessage {
ProtocolMessageProtocolMessage103   ProtocolMessage()
104       : tag(MESSAGE_TAG_NONE),
105         id(0),
106         dump_type(MiniDumpNormal),
107         thread_id(0),
108         exception_pointers(NULL),
109         assert_info(NULL),
110         custom_client_info(),
111         dump_request_handle(NULL),
112         dump_generated_handle(NULL),
113         server_alive_handle(NULL) {
114   }
115 
116   // Creates an instance with the given parameters.
ProtocolMessageProtocolMessage117   ProtocolMessage(MessageTag arg_tag,
118                   DWORD arg_id,
119                   MINIDUMP_TYPE arg_dump_type,
120                   DWORD* arg_thread_id,
121                   EXCEPTION_POINTERS** arg_exception_pointers,
122                   MDRawAssertionInfo* arg_assert_info,
123                   const CustomClientInfo& custom_info,
124                   HANDLE arg_dump_request_handle,
125                   HANDLE arg_dump_generated_handle,
126                   HANDLE arg_server_alive)
127     : tag(arg_tag),
128       id(arg_id),
129       dump_type(arg_dump_type),
130       thread_id(arg_thread_id),
131       exception_pointers(arg_exception_pointers),
132       assert_info(arg_assert_info),
133       custom_client_info(custom_info),
134       dump_request_handle(arg_dump_request_handle),
135       dump_generated_handle(arg_dump_generated_handle),
136       server_alive_handle(arg_server_alive) {
137   }
138 
139   // Tag in the message.
140   MessageTag tag;
141 
142   // The id for this message. This may be either a process id or a crash id
143   // depending on the type of message.
144   DWORD id;
145 
146   // Dump type requested.
147   MINIDUMP_TYPE dump_type;
148 
149   // Client thread id pointer.
150   DWORD* thread_id;
151 
152   // Exception information.
153   EXCEPTION_POINTERS** exception_pointers;
154 
155   // Assert information in case of an invalid parameter or
156   // pure call failure.
157   MDRawAssertionInfo* assert_info;
158 
159   // Custom client information.
160   CustomClientInfo custom_client_info;
161 
162   // Handle to signal the crash event.
163   HANDLE dump_request_handle;
164 
165   // Handle to check if server is done generating crash.
166   HANDLE dump_generated_handle;
167 
168   // Handle to a mutex that becomes signaled (WAIT_ABANDONED)
169   // if server process goes down.
170   HANDLE server_alive_handle;
171 
172  private:
173   // Disable copy ctor and operator=.
174   ProtocolMessage(const ProtocolMessage& msg);
175   ProtocolMessage& operator=(const ProtocolMessage& msg);
176 };
177 
178 }  // namespace google_breakpad
179 
180 #endif  // CLIENT_WINDOWS_COMMON_IPC_PROTOCOL_H__
181