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

Side by Side Diff: base/win/scoped_handle.cc

Issue 1767293005: Add creation tracking for ActiveVerifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win/scoped_handle.h" 5 #include "base/win/scoped_handle.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <unordered_map> 9 #include <unordered_map>
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 virtual void StopTracking(HANDLE handle, const void* owner, 88 virtual void StopTracking(HANDLE handle, const void* owner,
89 const void* pc1, const void* pc2); 89 const void* pc1, const void* pc2);
90 virtual void Disable(); 90 virtual void Disable();
91 virtual void OnHandleBeingClosed(HANDLE handle); 91 virtual void OnHandleBeingClosed(HANDLE handle);
92 92
93 private: 93 private:
94 ~ActiveVerifier(); // Not implemented. 94 ~ActiveVerifier(); // Not implemented.
95 95
96 static void InstallVerifier(); 96 static void InstallVerifier();
97 97
98 base::debug::StackTrace creation_stack_;
98 bool enabled_; 99 bool enabled_;
99 bool closing_; 100 bool closing_;
100 NativeLock* lock_; 101 NativeLock* lock_;
101 HandleMap map_; 102 HandleMap map_;
102 DISALLOW_COPY_AND_ASSIGN(ActiveVerifier); 103 DISALLOW_COPY_AND_ASSIGN(ActiveVerifier);
103 }; 104 };
104 ActiveVerifier* g_active_verifier = NULL; 105 ActiveVerifier* g_active_verifier = NULL;
105 106
106 // static 107 // static
107 ActiveVerifier* ActiveVerifier::Get() { 108 ActiveVerifier* ActiveVerifier::Get() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 DWORD thread_id = GetCurrentThreadId(); 162 DWORD thread_id = GetCurrentThreadId();
162 163
163 AutoNativeLock lock(*lock_); 164 AutoNativeLock lock(*lock_);
164 165
165 Info handle_info = { owner, pc1, pc2, base::debug::StackTrace(), thread_id }; 166 Info handle_info = { owner, pc1, pc2, base::debug::StackTrace(), thread_id };
166 std::pair<HANDLE, Info> item(handle, handle_info); 167 std::pair<HANDLE, Info> item(handle, handle_info);
167 std::pair<HandleMap::iterator, bool> result = map_.insert(item); 168 std::pair<HandleMap::iterator, bool> result = map_.insert(item);
168 if (!result.second) { 169 if (!result.second) {
169 Info other = result.first->second; 170 Info other = result.first->second;
170 base::debug::Alias(&other); 171 base::debug::Alias(&other);
172 base::debug::Alias(&creation_stack_);
171 CHECK(false); // Attempt to start tracking already tracked handle. 173 CHECK(false); // Attempt to start tracking already tracked handle.
172 } 174 }
173 } 175 }
174 176
175 void ActiveVerifier::StopTracking(HANDLE handle, const void* owner, 177 void ActiveVerifier::StopTracking(HANDLE handle, const void* owner,
176 const void* pc1, const void* pc2) { 178 const void* pc1, const void* pc2) {
177 if (!enabled_) 179 if (!enabled_)
178 return; 180 return;
179 181
180 AutoNativeLock lock(*lock_); 182 AutoNativeLock lock(*lock_);
181 HandleMap::iterator i = map_.find(handle); 183 HandleMap::iterator i = map_.find(handle);
182 if (i == map_.end()) 184 if (i == map_.end()) {
185 base::debug::Alias(&creation_stack_);
183 CHECK(false); // Attempting to close an untracked handle. 186 CHECK(false); // Attempting to close an untracked handle.
187 }
184 188
185 Info other = i->second; 189 Info other = i->second;
186 if (other.owner != owner) { 190 if (other.owner != owner) {
187 base::debug::Alias(&other); 191 base::debug::Alias(&other);
192 base::debug::Alias(&creation_stack_);
188 CHECK(false); // Attempting to close a handle not owned by opener. 193 CHECK(false); // Attempting to close a handle not owned by opener.
189 } 194 }
190 195
191 map_.erase(i); 196 map_.erase(i);
192 } 197 }
193 198
194 void ActiveVerifier::Disable() { 199 void ActiveVerifier::Disable() {
195 enabled_ = false; 200 enabled_ = false;
196 } 201 }
197 202
198 void ActiveVerifier::OnHandleBeingClosed(HANDLE handle) { 203 void ActiveVerifier::OnHandleBeingClosed(HANDLE handle) {
199 if (!enabled_) 204 if (!enabled_)
200 return; 205 return;
201 206
202 AutoNativeLock lock(*lock_); 207 AutoNativeLock lock(*lock_);
203 if (closing_) 208 if (closing_)
204 return; 209 return;
205 210
206 HandleMap::iterator i = map_.find(handle); 211 HandleMap::iterator i = map_.find(handle);
207 if (i == map_.end()) 212 if (i == map_.end())
208 return; 213 return;
209 214
210 Info other = i->second; 215 Info other = i->second;
211 base::debug::Alias(&other); 216 base::debug::Alias(&other);
217 base::debug::Alias(&creation_stack_);
212 CHECK(false); // CloseHandle called on tracked handle. 218 CHECK(false); // CloseHandle called on tracked handle.
213 } 219 }
214 220
215 } // namespace 221 } // namespace
216 222
217 void* GetHandleVerifier() { 223 void* GetHandleVerifier() {
218 return g_active_verifier; 224 return g_active_verifier;
219 } 225 }
220 226
221 namespace base { 227 namespace base {
(...skipping 19 matching lines...) Expand all
241 void DisableHandleVerifier() { 247 void DisableHandleVerifier() {
242 return ActiveVerifier::Get()->Disable(); 248 return ActiveVerifier::Get()->Disable();
243 } 249 }
244 250
245 void OnHandleBeingClosed(HANDLE handle) { 251 void OnHandleBeingClosed(HANDLE handle) {
246 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); 252 return ActiveVerifier::Get()->OnHandleBeingClosed(handle);
247 } 253 }
248 254
249 } // namespace win 255 } // namespace win
250 } // namespace base 256 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698