xref: /aosp_15_r20/external/cronet/base/win/scoped_handle.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "base/win/scoped_handle.h"
6 #include "base/win/scoped_handle_verifier.h"
7 #include "base/win/windows_types.h"
8 
9 namespace base {
10 namespace win {
11 
12 using base::win::internal::ScopedHandleVerifier;
13 
operator <<(std::ostream & os,HandleOperation operation)14 std::ostream& operator<<(std::ostream& os, HandleOperation operation) {
15   switch (operation) {
16     case HandleOperation::kHandleAlreadyTracked:
17       return os << "Handle Already Tracked";
18     case HandleOperation::kCloseHandleNotTracked:
19       return os << "Closing an untracked handle";
20     case HandleOperation::kCloseHandleNotOwner:
21       return os << "Closing a handle owned by something else";
22     case HandleOperation::kCloseHandleHook:
23       return os << "CloseHandleHook validation failure";
24     case HandleOperation::kDuplicateHandleHook:
25       return os << "DuplicateHandleHook validation failure";
26   }
27 }
28 
29 // Static.
CloseHandle(HANDLE handle)30 bool HandleTraits::CloseHandle(HANDLE handle) {
31   return ScopedHandleVerifier::Get()->CloseHandle(handle);
32 }
33 
34 // Static.
StartTracking(HANDLE handle,const void * owner,const void * pc1,const void * pc2)35 void VerifierTraits::StartTracking(HANDLE handle,
36                                    const void* owner,
37                                    const void* pc1,
38                                    const void* pc2) {
39   return ScopedHandleVerifier::Get()->StartTracking(handle, owner, pc1, pc2);
40 }
41 
42 // Static.
StopTracking(HANDLE handle,const void * owner,const void * pc1,const void * pc2)43 void VerifierTraits::StopTracking(HANDLE handle,
44                                   const void* owner,
45                                   const void* pc1,
46                                   const void* pc2) {
47   return ScopedHandleVerifier::Get()->StopTracking(handle, owner, pc1, pc2);
48 }
49 
DisableHandleVerifier()50 void DisableHandleVerifier() {
51   return ScopedHandleVerifier::Get()->Disable();
52 }
53 
OnHandleBeingClosed(HANDLE handle,HandleOperation operation)54 void OnHandleBeingClosed(HANDLE handle, HandleOperation operation) {
55   return ScopedHandleVerifier::Get()->OnHandleBeingClosed(handle, operation);
56 }
57 
58 }  // namespace win
59 }  // namespace base
60