From 261679b3d2f3336d8531ed38e110254c3e2d1c10 Mon Sep 17 00:00:00 2001 From: Alan Zhao Date: Wed, 31 Aug 2022 13:51:18 -0400 Subject: [PATCH] Move registration_protocol_win structs to their own header file registration_protocol_win.h includes , which adds an unacceptable dependency on libc++ in //components/crash/win:chrome_wer in Chrome as that file is included in crashpad_wer.cc. Rather than remove , which would require doing a lot of transitive refactoring work in Crashpad, we just extract the data structures into another file, as crashpad_wer.cc only includes registration_protocol_win.h for its struct definitions. Bug: chromium:1357827 Change-Id: Ic20c2952be07ea75d063702cd346cdca0ab65038 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3864251 Commit-Queue: Alan Zhao Reviewed-by: Joshua Peraza --- handler/win/wer/crashpad_wer.cc | 2 +- util/BUILD.gn | 3 +- util/win/registration_protocol_win.h | 143 +--------------- util/win/registration_protocol_win_structs.h | 169 +++++++++++++++++++ 4 files changed, 173 insertions(+), 144 deletions(-) create mode 100644 util/win/registration_protocol_win_structs.h diff --git a/handler/win/wer/crashpad_wer.cc b/handler/win/wer/crashpad_wer.cc index 6266fab6..071bb92f 100644 --- a/handler/win/wer/crashpad_wer.cc +++ b/handler/win/wer/crashpad_wer.cc @@ -18,7 +18,7 @@ #include "handler/win/wer/crashpad_wer.h" #include "util/misc/address_types.h" -#include "util/win/registration_protocol_win.h" +#include "util/win/registration_protocol_win_structs.h" #include #include diff --git a/util/BUILD.gn b/util/BUILD.gn index 22f8e2dd..59e02d23 100644 --- a/util/BUILD.gn +++ b/util/BUILD.gn @@ -165,7 +165,7 @@ if (crashpad_is_win) { sources = [ "misc/address_types.h", "win/address_types.h", - "win/registration_protocol_win.h", + "win/registration_protocol_win_structs.h", ] public_deps = [ "../third_party/mini_chromium:build" ] public_configs = [ "..:crashpad_config" ] @@ -505,6 +505,7 @@ crashpad_static_library("util") { "win/process_structs.h", "win/registration_protocol_win.cc", "win/registration_protocol_win.h", + "win/registration_protocol_win_structs.h", "win/safe_terminate_process.h", "win/scoped_handle.cc", "win/scoped_handle.h", diff --git a/util/win/registration_protocol_win.h b/util/win/registration_protocol_win.h index e467fd84..de3d57a4 100644 --- a/util/win/registration_protocol_win.h +++ b/util/win/registration_protocol_win.h @@ -21,151 +21,10 @@ #include #include "util/win/address_types.h" +#include "util/win/registration_protocol_win_structs.h" namespace crashpad { -#pragma pack(push, 1) - -//! \brief Structure read out of the client process by the crash handler when an -//! exception occurs. -struct ExceptionInformation { - //! \brief The address of an EXCEPTION_POINTERS structure in the client - //! process that describes the exception. - WinVMAddress exception_pointers; - - //! \brief The thread on which the exception happened. - DWORD thread_id; -}; - -//! \brief Context to be passed to WerRegisterRuntimeExceptionModule(). -//! -//! Used by the crashpad client, and the WER exception DLL. -struct WerRegistration { - //! \brief The expected value of `version`. This should be changed whenever - //! this struct is modified incompatibly. - enum { kWerRegistrationVersion = 1 }; - //! \brief Version field to detect skew between target process and helper. - //! Should be set to kWerRegistrationVersion. - int version; - //! \brief Used by DumpWithoutCrashing and the WER module to initiate a dump. - //! These handles are leaked in the client process. - HANDLE dump_without_crashing; - //! \brief Used by DumpWithoutCrashing to signal that a dump has been taken. - //! These handles are leaked in the client process. - HANDLE dump_completed; - //! \brief Set just before and cleared just after the events above are - //! triggered or signalled in a normal DumpWithoutCrashing call. - //! When `true` the WER handler should not set the exception structures until - //! after dump_completed has been signalled. - bool in_dump_without_crashing; - //! \brief Address of g_non_crash_exception_information. - //! - //! Provided by the target process. Just before dumping we will point - //! (*crashpad_exception_info).exception_pointers at `pointers`. As WerFault - //! loads the helper with the same bitness as the client this can be void*. - void* crashpad_exception_info; - //! \brief These will point into the `exception` and `context` members in this - //! structure. - //! - //! Filled in by the helper DLL. - EXCEPTION_POINTERS pointers; - //! \brief The exception provided by WerFault. - //! - //! Filled in by the helper DLL. - EXCEPTION_RECORD exception; - //! \brief The context provided by WerFault. - //! - //! Filled in by the helper DLL. - CONTEXT context; -}; - -//! \brief A client registration request. -struct RegistrationRequest { - //! \brief The expected value of `version`. This should be changed whenever - //! the messages or ExceptionInformation are modified incompatibly. - enum { kMessageVersion = 1 }; - - //! \brief Version field to detect skew between client and server. Should be - //! set to kMessageVersion. - int version; - - //! \brief The PID of the client process. - DWORD client_process_id; - - //! \brief The address, in the client process's address space, of an - //! ExceptionInformation structure, used when handling a crash dump - //! request. - WinVMAddress crash_exception_information; - - //! \brief The address, in the client process's address space, of an - //! ExceptionInformation structure, used when handling a non-crashing dump - //! request. - WinVMAddress non_crash_exception_information; - - //! \brief The address, in the client process's address space, of a - //! `CRITICAL_SECTION` allocated with a valid .DebugInfo field. This can - //! be accomplished by using - //! InitializeCriticalSectionWithDebugInfoIfPossible() or equivalent. This - //! value can be `0`, however then limited lock data will be available in - //! minidumps. - WinVMAddress critical_section_address; -}; - -//! \brief A message only sent to the server by itself to trigger shutdown. -struct ShutdownRequest { - //! \brief A randomly generated token used to validate the the shutdown - //! request was not sent from another process. - uint64_t token; -}; - -//! \brief The message passed from client to server by -//! SendToCrashHandlerServer(). -struct ClientToServerMessage { - //! \brief Indicates which field of the union is in use. - enum Type : uint32_t { - //! \brief For RegistrationRequest. - kRegister, - - //! \brief For ShutdownRequest. - kShutdown, - - //! \brief An empty message sent by the initial client in asynchronous mode. - //! No data is required, this just confirms that the server is ready to - //! accept client registrations. - kPing, - } type; - - union { - RegistrationRequest registration; - ShutdownRequest shutdown; - }; -}; - -//! \brief A client registration response. -struct RegistrationResponse { - //! \brief An event `HANDLE`, valid in the client process, that should be - //! signaled to request a crash report. Clients should convert the value - //! to a `HANDLE` by calling IntToHandle(). - int request_crash_dump_event; - - //! \brief An event `HANDLE`, valid in the client process, that should be - //! signaled to request a non-crashing dump be taken. Clients should - //! convert the value to a `HANDLE` by calling IntToHandle(). - int request_non_crash_dump_event; - - //! \brief An event `HANDLE`, valid in the client process, that will be - //! signaled by the server when the non-crashing dump is complete. Clients - //! should convert the value to a `HANDLE` by calling IntToHandle(). - int non_crash_dump_completed_event; -}; - -//! \brief The response sent back to the client via SendToCrashHandlerServer(). -union ServerToClientMessage { - RegistrationResponse registration; -}; - -#pragma pack(pop) - //! \brief Connect over the given \a pipe_name, passing \a message to the //! server, storing the server's reply into \a response. //! diff --git a/util/win/registration_protocol_win_structs.h b/util/win/registration_protocol_win_structs.h new file mode 100644 index 00000000..2800cacc --- /dev/null +++ b/util/win/registration_protocol_win_structs.h @@ -0,0 +1,169 @@ +// Copyright 2015 The Crashpad Authors. All rights reserved. +// +// 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_REGISTRATION_PROTOCOL_WIN_STRUCTS_H_ +#define CRASHPAD_UTIL_WIN_REGISTRATION_PROTOCOL_WIN_STRUCTS_H_ + +#include +#include + +#include "util/win/address_types.h" + +namespace crashpad { + +#pragma pack(push, 1) + +//! \brief Structure read out of the client process by the crash handler when an +//! exception occurs. +struct ExceptionInformation { + //! \brief The address of an EXCEPTION_POINTERS structure in the client + //! process that describes the exception. + WinVMAddress exception_pointers; + + //! \brief The thread on which the exception happened. + DWORD thread_id; +}; + +//! \brief Context to be passed to WerRegisterRuntimeExceptionModule(). +//! +//! Used by the crashpad client, and the WER exception DLL. +struct WerRegistration { + //! \brief The expected value of `version`. This should be changed whenever + //! this struct is modified incompatibly. + enum { kWerRegistrationVersion = 1 }; + //! \brief Version field to detect skew between target process and helper. + //! Should be set to kWerRegistrationVersion. + int version; + //! \brief Used by DumpWithoutCrashing and the WER module to initiate a dump. + //! These handles are leaked in the client process. + HANDLE dump_without_crashing; + //! \brief Used by DumpWithoutCrashing to signal that a dump has been taken. + //! These handles are leaked in the client process. + HANDLE dump_completed; + //! \brief Set just before and cleared just after the events above are + //! triggered or signalled in a normal DumpWithoutCrashing call. + //! When `true` the WER handler should not set the exception structures until + //! after dump_completed has been signalled. + bool in_dump_without_crashing; + //! \brief Address of g_non_crash_exception_information. + //! + //! Provided by the target process. Just before dumping we will point + //! (*crashpad_exception_info).exception_pointers at `pointers`. As WerFault + //! loads the helper with the same bitness as the client this can be void*. + void* crashpad_exception_info; + //! \brief These will point into the `exception` and `context` members in this + //! structure. + //! + //! Filled in by the helper DLL. + EXCEPTION_POINTERS pointers; + //! \brief The exception provided by WerFault. + //! + //! Filled in by the helper DLL. + EXCEPTION_RECORD exception; + //! \brief The context provided by WerFault. + //! + //! Filled in by the helper DLL. + CONTEXT context; +}; + +//! \brief A client registration request. +struct RegistrationRequest { + //! \brief The expected value of `version`. This should be changed whenever + //! the messages or ExceptionInformation are modified incompatibly. + enum { kMessageVersion = 1 }; + + //! \brief Version field to detect skew between client and server. Should be + //! set to kMessageVersion. + int version; + + //! \brief The PID of the client process. + DWORD client_process_id; + + //! \brief The address, in the client process's address space, of an + //! ExceptionInformation structure, used when handling a crash dump + //! request. + WinVMAddress crash_exception_information; + + //! \brief The address, in the client process's address space, of an + //! ExceptionInformation structure, used when handling a non-crashing dump + //! request. + WinVMAddress non_crash_exception_information; + + //! \brief The address, in the client process's address space, of a + //! `CRITICAL_SECTION` allocated with a valid .DebugInfo field. This can + //! be accomplished by using + //! InitializeCriticalSectionWithDebugInfoIfPossible() or equivalent. This + //! value can be `0`, however then limited lock data will be available in + //! minidumps. + WinVMAddress critical_section_address; +}; + +//! \brief A message only sent to the server by itself to trigger shutdown. +struct ShutdownRequest { + //! \brief A randomly generated token used to validate the the shutdown + //! request was not sent from another process. + uint64_t token; +}; + +//! \brief The message passed from client to server by +//! SendToCrashHandlerServer(). +struct ClientToServerMessage { + //! \brief Indicates which field of the union is in use. + enum Type : uint32_t { + //! \brief For RegistrationRequest. + kRegister, + + //! \brief For ShutdownRequest. + kShutdown, + + //! \brief An empty message sent by the initial client in asynchronous mode. + //! No data is required, this just confirms that the server is ready to + //! accept client registrations. + kPing, + } type; + + union { + RegistrationRequest registration; + ShutdownRequest shutdown; + }; +}; + +//! \brief A client registration response. +struct RegistrationResponse { + //! \brief An event `HANDLE`, valid in the client process, that should be + //! signaled to request a crash report. Clients should convert the value + //! to a `HANDLE` by calling IntToHandle(). + int request_crash_dump_event; + + //! \brief An event `HANDLE`, valid in the client process, that should be + //! signaled to request a non-crashing dump be taken. Clients should + //! convert the value to a `HANDLE` by calling IntToHandle(). + int request_non_crash_dump_event; + + //! \brief An event `HANDLE`, valid in the client process, that will be + //! signaled by the server when the non-crashing dump is complete. Clients + //! should convert the value to a `HANDLE` by calling IntToHandle(). + int non_crash_dump_completed_event; +}; + +//! \brief The response sent back to the client via SendToCrashHandlerServer(). +union ServerToClientMessage { + RegistrationResponse registration; +}; + +#pragma pack(pop) + +} // namespace crashpad + +#endif // CRASHPAD_UTIL_WIN_REGISTRATION_PROTOCOL_WIN_STRUCTS_H_