crashpad/util/win/scoped_handle.h
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

61 lines
1.8 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.
#ifndef CRASHPAD_UTIL_WIN_SCOPED_HANDLE_H_
#define CRASHPAD_UTIL_WIN_SCOPED_HANDLE_H_
#include <windows.h>
#include "base/scoped_generic.h"
namespace crashpad {
namespace internal {
struct ScopedFileHANDLECloseTraits {
static HANDLE InvalidValue() { return INVALID_HANDLE_VALUE; }
static void Free(HANDLE handle);
};
struct ScopedKernelHANDLECloseTraits {
static HANDLE InvalidValue() { return nullptr; }
static void Free(HANDLE handle);
};
struct ScopedSearchHANDLECloseTraits {
static HANDLE InvalidValue() { return INVALID_HANDLE_VALUE; }
static void Free(HANDLE handle);
};
struct ScopedVectoredExceptionRegistrationCloseTraits {
static PVOID InvalidValue() { return nullptr; }
static void Free(PVOID handle);
};
} // namespace internal
using ScopedFileHANDLE =
base::ScopedGeneric<HANDLE, internal::ScopedFileHANDLECloseTraits>;
using ScopedKernelHANDLE =
base::ScopedGeneric<HANDLE, internal::ScopedKernelHANDLECloseTraits>;
using ScopedSearchHANDLE =
base::ScopedGeneric<HANDLE, internal::ScopedSearchHANDLECloseTraits>;
using ScopedVectoredExceptionRegistration = base::ScopedGeneric<
PVOID,
internal::ScopedVectoredExceptionRegistrationCloseTraits>;
} // namespace crashpad
#endif // CRASHPAD_UTIL_WIN_SCOPED_HANDLE_H_