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