crashpad/util/win/scoped_handle.cc
Alex Gough ac0c27a923 Deregister vectored exception handler on client destruction
Some users of crashpad load and unload the dll that hosts
crashpad code. crashpad registers a vectored exception handler
to help collect heap corruption crashes. If the dll is
unloaded this handler might still be called.

This CL adds a scoped handler for such registrations and
uses it on Windows crashpad client. To allow this to
be stored, RegisterHandler() on the client needs to move
onto the client object from being a helper function.

Bug: crashpad:462
Change-Id: I5d77c056e2a9a61ddcfa9d0186ab4bfd85a19bff
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/4898263
Reviewed-by: Ben Hamilton <benhamilton@google.com>
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
2023-09-28 17:24:39 +00:00

41 lines
1.2 KiB
C++

// Copyright 2014 The Crashpad Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "util/win/scoped_handle.h"
#include "base/check.h"
#include "util/file/file_io.h"
namespace crashpad {
namespace internal {
void ScopedFileHANDLECloseTraits::Free(HANDLE handle) {
CheckedCloseFile(handle);
}
void ScopedKernelHANDLECloseTraits::Free(HANDLE handle) {
PCHECK(CloseHandle(handle)) << "CloseHandle";
}
void ScopedSearchHANDLECloseTraits::Free(HANDLE handle) {
PCHECK(FindClose(handle)) << "FindClose";
}
void ScopedVectoredExceptionRegistrationCloseTraits::Free(PVOID handle) {
PCHECK(::RemoveVectoredExceptionHandler(handle));
}
} // namespace internal
} // namespace crashpad