scoped_handle.cc 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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
  3. // found in the LICENSE file.
  4. #include "base/win/scoped_handle.h"
  5. #include "base/win/scoped_handle_verifier.h"
  6. #include "base/win/windows_types.h"
  7. namespace base {
  8. namespace win {
  9. using base::win::internal::ScopedHandleVerifier;
  10. std::ostream& operator<<(std::ostream& os, HandleOperation operation) {
  11. switch (operation) {
  12. case HandleOperation::kHandleAlreadyTracked:
  13. return os << "Handle Already Tracked";
  14. case HandleOperation::kCloseHandleNotTracked:
  15. return os << "Closing an untracked handle";
  16. case HandleOperation::kCloseHandleNotOwner:
  17. return os << "Closing a handle owned by something else";
  18. case HandleOperation::kCloseHandleHook:
  19. return os << "CloseHandleHook validation failure";
  20. case HandleOperation::kDuplicateHandleHook:
  21. return os << "DuplicateHandleHook validation failure";
  22. }
  23. }
  24. // Static.
  25. bool HandleTraits::CloseHandle(HANDLE handle) {
  26. return ScopedHandleVerifier::Get()->CloseHandle(handle);
  27. }
  28. // Static.
  29. void VerifierTraits::StartTracking(HANDLE handle,
  30. const void* owner,
  31. const void* pc1,
  32. const void* pc2) {
  33. return ScopedHandleVerifier::Get()->StartTracking(handle, owner, pc1, pc2);
  34. }
  35. // Static.
  36. void VerifierTraits::StopTracking(HANDLE handle,
  37. const void* owner,
  38. const void* pc1,
  39. const void* pc2) {
  40. return ScopedHandleVerifier::Get()->StopTracking(handle, owner, pc1, pc2);
  41. }
  42. void DisableHandleVerifier() {
  43. return ScopedHandleVerifier::Get()->Disable();
  44. }
  45. void OnHandleBeingClosed(HANDLE handle, HandleOperation operation) {
  46. return ScopedHandleVerifier::Get()->OnHandleBeingClosed(handle, operation);
  47. }
  48. } // namespace win
  49. } // namespace base