Planeshift

client_info.h

Go to the documentation of this file.
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_CRASH_GENERATION_CLIENT_INFO_H__
00031 #define CLIENT_WINDOWS_CRASH_GENERATION_CLIENT_INFO_H__
00032 
00033 #include <Windows.h>
00034 #include <DbgHelp.h>
00035 #include "client/windows/common/ipc_protocol.h"
00036 #include "common/scoped_ptr.h"
00037 #include "google_breakpad/common/minidump_format.h"
00038 
00039 namespace google_breakpad {
00040 
00041 class CrashGenerationServer;
00042 
00043 // Abstraction for a crash client process.
00044 class ClientInfo {
00045  public:
00046   // Creates an instance with the given values. Gets the process
00047   // handle for the given process id and creates necessary event
00048   // objects.
00049   ClientInfo(CrashGenerationServer* crash_server,
00050              DWORD pid,
00051              MINIDUMP_TYPE dump_type,
00052              DWORD* thread_id,
00053              EXCEPTION_POINTERS** ex_info,
00054              MDRawAssertionInfo* assert_info,
00055              const CustomClientInfo& custom_client_info);
00056 
00057   ~ClientInfo();
00058 
00059   CrashGenerationServer* crash_server() const { return crash_server_; }
00060   DWORD pid() const { return pid_; }
00061   MINIDUMP_TYPE dump_type() const { return dump_type_; }
00062   EXCEPTION_POINTERS** ex_info() const { return ex_info_; }
00063   MDRawAssertionInfo* assert_info() const { return assert_info_; }
00064   DWORD* thread_id() const { return thread_id_; }
00065   HANDLE process_handle() const { return process_handle_; }
00066   HANDLE dump_requested_handle() const { return dump_requested_handle_; }
00067   HANDLE dump_generated_handle() const { return dump_generated_handle_; }
00068   DWORD crash_id() const { return crash_id_; }
00069   const CustomClientInfo& custom_client_info() const {
00070     return custom_client_info_;
00071   }
00072 
00073   void set_dump_request_wait_handle(HANDLE value) {
00074     dump_request_wait_handle_ = value;
00075   }
00076 
00077   void set_process_exit_wait_handle(HANDLE value) {
00078     process_exit_wait_handle_ = value;
00079   }
00080 
00081   // Unregister the dump request wait operation and wait for all callbacks
00082   // that might already be running to complete before returning.
00083   void UnregisterDumpRequestWaitAndBlockUntilNoPending();
00084 
00085   // Unregister the process exit wait operation.  If block_until_no_pending is
00086   // true, wait for all callbacks that might already be running to complete
00087   // before returning.
00088   void UnregisterProcessExitWait(bool block_until_no_pending);
00089 
00090   bool Initialize();
00091   bool GetClientExceptionInfo(EXCEPTION_POINTERS** ex_info) const;
00092   bool GetClientThreadId(DWORD* thread_id) const;
00093 
00094   // Reads the custom information from the client process address space.
00095   bool PopulateCustomInfo();
00096 
00097   // Returns the client custom information.
00098   CustomClientInfo GetCustomInfo() const;
00099 
00100  private:
00101   // Calcualtes the uptime for the client process, converts it to a string and
00102   // stores it in the last entry of client custom info.
00103   void SetProcessUptime();
00104 
00105   // Crash generation server.
00106   CrashGenerationServer* crash_server_;
00107 
00108   // Client process ID.
00109   DWORD pid_;
00110 
00111   // Dump type requested by the client.
00112   MINIDUMP_TYPE dump_type_;
00113 
00114   // Address of an EXCEPTION_POINTERS* variable in the client
00115   // process address space that will point to an instance of
00116   // EXCEPTION_POINTERS containing information about crash.
00117   //
00118   // WARNING: Do not dereference these pointers as they are pointers
00119   // in the address space of another process.
00120   EXCEPTION_POINTERS** ex_info_;
00121 
00122   // Address of an instance of MDRawAssertionInfo in the client
00123   // process address space that will contain information about
00124   // non-exception related crashes like invalid parameter assertion
00125   // failures and pure calls.
00126   //
00127   // WARNING: Do not dereference these pointers as they are pointers
00128   // in the address space of another process.
00129   MDRawAssertionInfo* assert_info_;
00130 
00131   // Custom information about the client.
00132   CustomClientInfo custom_client_info_;
00133 
00134   // Contains the custom client info entries read from the client process
00135   // memory. This will be populated only if the method GetClientCustomInfo
00136   // is called.
00137   scoped_array<CustomInfoEntry> custom_info_entries_;
00138 
00139   // Address of a variable in the client process address space that
00140   // will contain the thread id of the crashing client thread.
00141   //
00142   // WARNING: Do not dereference these pointers as they are pointers
00143   // in the address space of another process.
00144   DWORD* thread_id_;
00145 
00146   // Client process handle.
00147   HANDLE process_handle_;
00148 
00149   // Dump request event handle.
00150   HANDLE dump_requested_handle_;
00151 
00152   // Dump generated event handle.
00153   HANDLE dump_generated_handle_;
00154 
00155   // Wait handle for dump request event.
00156   HANDLE dump_request_wait_handle_;
00157 
00158   // Wait handle for process exit event.
00159   HANDLE process_exit_wait_handle_;
00160 
00161   // Time when the client process started. It is used to determine the uptime
00162   // for the client process when it signals a crash.
00163   FILETIME start_time_;
00164 
00165   // The crash id which can be used to request an upload. This will be the
00166   // value of the low order dword of the process creation time for the process
00167   // being dumped.
00168   DWORD crash_id_;
00169 
00170   // Disallow copy ctor and operator=.
00171   ClientInfo(const ClientInfo& client_info);
00172   ClientInfo& operator=(const ClientInfo& client_info);
00173 };
00174 
00175 }  // namespace google_breakpad
00176 
00177 #endif  // CLIENT_WINDOWS_CRASH_GENERATION_CLIENT_INFO_H__