• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "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) const;
92   bool GetClientThreadId(DWORD* thread_id) const;
93 
94   // Reads the custom information from the client process address space.
95   bool PopulateCustomInfo();
96 
97   // Returns the client custom information.
98   CustomClientInfo GetCustomInfo() const;
99 
100  private:
101   // Calcualtes the uptime for the client process, converts it to a string and
102   // stores it in the last entry of client custom info.
103   void SetProcessUptime();
104 
105   // Crash generation server.
106   CrashGenerationServer* crash_server_;
107 
108   // Client process ID.
109   DWORD pid_;
110 
111   // Dump type requested by the client.
112   MINIDUMP_TYPE dump_type_;
113 
114   // Address of an EXCEPTION_POINTERS* variable in the client
115   // process address space that will point to an instance of
116   // EXCEPTION_POINTERS containing information about crash.
117   //
118   // WARNING: Do not dereference these pointers as they are pointers
119   // in the address space of another process.
120   EXCEPTION_POINTERS** ex_info_;
121 
122   // Address of an instance of MDRawAssertionInfo in the client
123   // process address space that will contain information about
124   // non-exception related crashes like invalid parameter assertion
125   // failures and pure calls.
126   //
127   // WARNING: Do not dereference these pointers as they are pointers
128   // in the address space of another process.
129   MDRawAssertionInfo* assert_info_;
130 
131   // Custom information about the client.
132   CustomClientInfo custom_client_info_;
133 
134   // Contains the custom client info entries read from the client process
135   // memory. This will be populated only if the method GetClientCustomInfo
136   // is called.
137   scoped_array<CustomInfoEntry> custom_info_entries_;
138 
139   // Address of a variable in the client process address space that
140   // will contain the thread id of the crashing client thread.
141   //
142   // WARNING: Do not dereference these pointers as they are pointers
143   // in the address space of another process.
144   DWORD* thread_id_;
145 
146   // Client process handle.
147   HANDLE process_handle_;
148 
149   // Dump request event handle.
150   HANDLE dump_requested_handle_;
151 
152   // Dump generated event handle.
153   HANDLE dump_generated_handle_;
154 
155   // Wait handle for dump request event.
156   HANDLE dump_request_wait_handle_;
157 
158   // Wait handle for process exit event.
159   HANDLE process_exit_wait_handle_;
160 
161   // Time when the client process started. It is used to determine the uptime
162   // for the client process when it signals a crash.
163   FILETIME start_time_;
164 
165   // The crash id which can be used to request an upload. This will be the
166   // value of the low order dword of the process creation time for the process
167   // being dumped.
168   DWORD crash_id_;
169 
170   // Disallow copy ctor and operator=.
171   ClientInfo(const ClientInfo& client_info);
172   ClientInfo& operator=(const ClientInfo& client_info);
173 };
174 
175 }  // namespace google_breakpad
176 
177 #endif  // CLIENT_WINDOWS_CRASH_GENERATION_CLIENT_INFO_H__
178