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

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

Issue 1977833003: Add a buildflag to use the handle verifier in a per module mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GN. Created 4 years, 7 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
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 #ifndef BASE_WIN_SCOPED_HANDLE_H_ 5 #ifndef BASE_WIN_SCOPED_HANDLE_H_
6 #define BASE_WIN_SCOPED_HANDLE_H_ 6 #define BASE_WIN_SCOPED_HANDLE_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/move.h" 15 #include "base/move.h"
16 #include "base/win/base_features.h"
16 17
17 // TODO(rvargas): remove this with the rest of the verifier. 18 // TODO(rvargas): remove this with the rest of the verifier.
18 #if defined(COMPILER_MSVC) 19 #if defined(COMPILER_MSVC)
19 #include <intrin.h> 20 #include <intrin.h>
20 #define BASE_WIN_GET_CALLER _ReturnAddress() 21 #define BASE_WIN_GET_CALLER _ReturnAddress()
21 #elif defined(COMPILER_GCC) 22 #elif defined(COMPILER_GCC)
22 #define BASE_WIN_GET_CALLER __builtin_extract_return_addr(\\ 23 #define BASE_WIN_GET_CALLER __builtin_extract_return_addr(\\
23 __builtin_return_address(0)) 24 __builtin_return_address(0))
24 #endif 25 #endif
25 26
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 146
146 static void StartTracking(HANDLE handle, const void* owner, 147 static void StartTracking(HANDLE handle, const void* owner,
147 const void* pc1, const void* pc2) {} 148 const void* pc1, const void* pc2) {}
148 static void StopTracking(HANDLE handle, const void* owner, 149 static void StopTracking(HANDLE handle, const void* owner,
149 const void* pc1, const void* pc2) {} 150 const void* pc1, const void* pc2) {}
150 151
151 private: 152 private:
152 DISALLOW_IMPLICIT_CONSTRUCTORS(DummyVerifierTraits); 153 DISALLOW_IMPLICIT_CONSTRUCTORS(DummyVerifierTraits);
153 }; 154 };
154 155
156 #if BUILDFLAG(ENABLE_HANDLE_VERIFIER)
155 // Performs actual run-time tracking. 157 // Performs actual run-time tracking.
156 class BASE_EXPORT VerifierTraits { 158 class BASE_EXPORT VerifierTraits {
157 public: 159 public:
158 typedef HANDLE Handle; 160 typedef HANDLE Handle;
159 161
160 static void StartTracking(HANDLE handle, const void* owner, 162 static void StartTracking(HANDLE handle, const void* owner,
161 const void* pc1, const void* pc2); 163 const void* pc1, const void* pc2);
162 static void StopTracking(HANDLE handle, const void* owner, 164 static void StopTracking(HANDLE handle, const void* owner,
163 const void* pc1, const void* pc2); 165 const void* pc1, const void* pc2);
164 166
165 private: 167 private:
166 DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits); 168 DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits);
167 }; 169 };
168 170
169 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle; 171 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle;
170 172
173 // This testing function returns the module that the ActiveVerifier concrete
174 // implementation was instantiated in.
175 BASE_EXPORT HMODULE GetHandleVerifierModuleForTesting();
176 #else
177 typedef GenericScopedHandle<HandleTraits, DummyVerifierTraits> ScopedHandle;
178 #endif // BUILDFLAG(ENABLE_HANDLE_VERIFIER)
179
180 // This should be called whenever the OS is closing a handle, if extended
181 // verification of improper handle closing is desired. If |handle| is being
182 // tracked by the handle verifier and ScopedHandle is not the one closing it,
183 // a CHECK is generated.
184 BASE_EXPORT void OnHandleBeingClosed(HANDLE handle);
185
171 // This function may be called by the embedder to disable the use of 186 // This function may be called by the embedder to disable the use of
172 // VerifierTraits at runtime. It has no effect if DummyVerifierTraits is used 187 // VerifierTraits at runtime. It has no effect if DummyVerifierTraits is used
173 // for ScopedHandle. 188 // for ScopedHandle.
174 BASE_EXPORT void DisableHandleVerifier(); 189 BASE_EXPORT void DisableHandleVerifier();
175 190
176 // This should be called whenever the OS is closing a handle, if extended 191 // This should be called whenever the OS is closing a handle, if extended
177 // verification of improper handle closing is desired. If |handle| is being 192 // verification of improper handle closing is desired. If |handle| is being
178 // tracked by the handle verifier and ScopedHandle is not the one closing it, 193 // tracked by the handle verifier and ScopedHandle is not the one closing it,
179 // a CHECK is generated. 194 // a CHECK is generated.
180 BASE_EXPORT void OnHandleBeingClosed(HANDLE handle); 195 BASE_EXPORT void OnHandleBeingClosed(HANDLE handle);
181 196
182 // This testing function returns the module that the ActiveVerifier concrete
183 // implementation was instantiated in.
184 BASE_EXPORT HMODULE GetHandleVerifierModuleForTesting();
185
186 } // namespace win 197 } // namespace win
187 } // namespace base 198 } // namespace base
188 199
189 #endif // BASE_WIN_SCOPED_HANDLE_H_ 200 #endif // BASE_WIN_SCOPED_HANDLE_H_
OLDNEW
« base/win/BUILD.gn ('K') | « base/win/BUILD.gn ('k') | base/win/scoped_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698