Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1546)

Side by Side Diff: third_party/breakpad/src/client/windows/crash_generation/client_info.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include "client/windows/crash_generation/client_info.h"
31 #include "client/windows/common/ipc_protocol.h"
32
33 static const wchar_t kCustomInfoProcessUptimeName[] = L"ptime";
34
35 namespace google_breakpad {
36
37 ClientInfo::ClientInfo(CrashGenerationServer* crash_server,
38 DWORD pid,
39 MINIDUMP_TYPE dump_type,
40 DWORD* thread_id,
41 EXCEPTION_POINTERS** ex_info,
42 MDRawAssertionInfo* assert_info,
43 const CustomClientInfo& custom_client_info)
44 : crash_server_(crash_server),
45 pid_(pid),
46 dump_type_(dump_type),
47 ex_info_(ex_info),
48 assert_info_(assert_info),
49 custom_client_info_(custom_client_info),
50 thread_id_(thread_id),
51 process_handle_(NULL),
52 dump_requested_handle_(NULL),
53 dump_generated_handle_(NULL),
54 dump_request_wait_handle_(NULL),
55 process_exit_wait_handle_(NULL) {
56 GetSystemTimeAsFileTime(&start_time_);
57 }
58
59 bool ClientInfo::Initialize() {
60 process_handle_ = OpenProcess(GENERIC_ALL, FALSE, pid_);
61 if (!process_handle_) {
62 return false;
63 }
64
65 dump_requested_handle_ = CreateEvent(NULL, // Security attributes.
66 TRUE, // Manual reset.
67 FALSE, // Initial state.
68 NULL); // Name.
69 if (!dump_requested_handle_) {
70 return false;
71 }
72
73 dump_generated_handle_ = CreateEvent(NULL, // Security attributes.
74 TRUE, // Manual reset.
75 FALSE, // Initial state.
76 NULL); // Name.
77 return dump_generated_handle_ != NULL;
78 }
79
80 ClientInfo::~ClientInfo() {
81 if (dump_request_wait_handle_) {
82 // Wait for callbacks that might already be running to finish.
83 UnregisterWaitEx(dump_request_wait_handle_, INVALID_HANDLE_VALUE);
84 }
85
86 if (process_exit_wait_handle_) {
87 // Wait for the callback that might already be running to finish.
88 UnregisterWaitEx(process_exit_wait_handle_, INVALID_HANDLE_VALUE);
89 }
90
91 if (process_handle_) {
92 CloseHandle(process_handle_);
93 }
94
95 if (dump_requested_handle_) {
96 CloseHandle(dump_requested_handle_);
97 }
98
99 if (dump_generated_handle_) {
100 CloseHandle(dump_generated_handle_);
101 }
102 }
103
104 void ClientInfo::UnregisterWaits() {
105 if (dump_request_wait_handle_) {
106 UnregisterWait(dump_request_wait_handle_);
107 dump_request_wait_handle_ = NULL;
108 }
109
110 if (process_exit_wait_handle_) {
111 UnregisterWait(process_exit_wait_handle_);
112 process_exit_wait_handle_ = NULL;
113 }
114 }
115
116 bool ClientInfo::GetClientExceptionInfo(EXCEPTION_POINTERS** ex_info) const {
117 SIZE_T bytes_count = 0;
118 if (!ReadProcessMemory(process_handle_,
119 ex_info_,
120 ex_info,
121 sizeof(*ex_info),
122 &bytes_count)) {
123 return false;
124 }
125
126 return bytes_count == sizeof(*ex_info);
127 }
128
129 bool ClientInfo::GetClientThreadId(DWORD* thread_id) const {
130 SIZE_T bytes_count = 0;
131 if (!ReadProcessMemory(process_handle_,
132 thread_id_,
133 thread_id,
134 sizeof(*thread_id),
135 &bytes_count)) {
136 return false;
137 }
138
139 return bytes_count == sizeof(*thread_id);
140 }
141
142 void ClientInfo::SetProcessUptime() {
143 FILETIME now = {0};
144 GetSystemTimeAsFileTime(&now);
145
146 ULARGE_INTEGER time_start;
147 time_start.HighPart = start_time_.dwHighDateTime;
148 time_start.LowPart = start_time_.dwLowDateTime;
149
150 ULARGE_INTEGER time_now;
151 time_now.HighPart = now.dwHighDateTime;
152 time_now.LowPart = now.dwLowDateTime;
153
154 // Calculate the delay and convert it from 100-nanoseconds to milliseconds.
155 __int64 delay = (time_now.QuadPart - time_start.QuadPart) / 10 / 1000;
156
157 // Convert it to a string.
158 wchar_t* value = custom_info_entries_.get()[custom_client_info_.count].value;
159 _i64tow_s(delay, value, CustomInfoEntry::kValueMaxLength, 10);
160 }
161
162 bool ClientInfo::PopulateCustomInfo() {
163 SIZE_T bytes_count = 0;
164 SIZE_T read_count = sizeof(CustomInfoEntry) * custom_client_info_.count;
165
166 // If the scoped array for custom info already has an array, it will be
167 // the same size as what we need. This is because the number of custom info
168 // entries is always the same. So allocate memory only if scoped array has
169 // a NULL pointer.
170 if (!custom_info_entries_.get()) {
171 // Allocate an extra entry for reporting uptime for the client process.
172 custom_info_entries_.reset(
173 new CustomInfoEntry[custom_client_info_.count + 1]);
174 // Use the last element in the array for uptime.
175 custom_info_entries_.get()[custom_client_info_.count].set_name(
176 kCustomInfoProcessUptimeName);
177 }
178
179 if (!ReadProcessMemory(process_handle_,
180 custom_client_info_.entries,
181 custom_info_entries_.get(),
182 read_count,
183 &bytes_count)) {
184 return false;
185 }
186
187 SetProcessUptime();
188 return (bytes_count != read_count);
189 }
190
191 CustomClientInfo ClientInfo::GetCustomInfo() const {
192 CustomClientInfo custom_info;
193 custom_info.entries = custom_info_entries_.get();
194 // Add 1 to the count from the client process to account for extra entry for
195 // process uptime.
196 custom_info.count = custom_client_info_.count + 1;
197 return custom_info;
198 }
199
200 } // namespace google_breakpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698