mirror of
https://github.com/chromium/crashpad.git
synced 2024-12-27 07:14:10 +08:00
mac: Add CrashpadClient::GetHandlerMachPort()
Bug: chromium:699607 Change-Id: Ib1886550fe81787cb1ffc8d8853f6969cc96831e Reviewed-on: https://chromium-review.googlesource.com/451127 Reviewed-by: Robert Sesek <rsesek@chromium.org> Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
8e82f6fde0
commit
b5284cdcba
@ -132,6 +132,27 @@ class CrashpadClient {
|
||||
//!
|
||||
//! \return `true` on success, `false` on failure with a message logged.
|
||||
bool SetHandlerMachPort(base::mac::ScopedMachSendRight exception_port);
|
||||
|
||||
//! \brief Retrieves a send right to the process’ crash handler Mach port.
|
||||
//!
|
||||
//! This method is only defined on macOS.
|
||||
//!
|
||||
//! This method can be used to obtain the crash handler Mach port when a
|
||||
//! Crashpad client process wishes to provide a send right to this port to
|
||||
//! another process. The IPC mechanism used to convey the right is under the
|
||||
//! application’s control. If the other process wishes to become a client of
|
||||
//! the same crash handler, it can provide the transferred right to
|
||||
//! SetHandlerMachPort().
|
||||
//!
|
||||
//! See StartHandler() for more detail on how the port and handler are
|
||||
//! configured.
|
||||
//!
|
||||
//! \return The Mach port set by SetHandlerMachPort(), possibly indirectly by
|
||||
//! a call to another method such as StartHandler() or
|
||||
//! SetHandlerMachService(). This method must only be called after a
|
||||
//! successful call to one of those methods. `MACH_PORT_NULL` on failure
|
||||
//! with a message logged.
|
||||
base::mac::ScopedMachSendRight GetHandlerMachPort() const;
|
||||
#endif
|
||||
|
||||
#if defined(OS_WIN) || DOXYGEN
|
||||
@ -155,14 +176,15 @@ class CrashpadClient {
|
||||
//! \brief Retrieves the IPC pipe name used to register with the Crashpad
|
||||
//! handler.
|
||||
//!
|
||||
//! This method is only defined on Windows.
|
||||
//!
|
||||
//! This method retrieves the IPC pipe name set by SetHandlerIPCPipe(), or a
|
||||
//! suitable IPC pipe name chosen by StartHandler(). It is intended to be used
|
||||
//! suitable IPC pipe name chosen by StartHandler(). It must only be called
|
||||
//! after a successful call to one of those methods. It is intended to be used
|
||||
//! to obtain the IPC pipe name so that it may be passed to other processes,
|
||||
//! so that they may register with an existing Crashpad handler by calling
|
||||
//! SetHandlerIPCPipe().
|
||||
//!
|
||||
//! This method is only defined on Windows.
|
||||
//!
|
||||
//! \return The full name of the crash handler IPC pipe, a string of the form
|
||||
//! `"\\.\pipe\NAME"`.
|
||||
std::wstring GetHandlerIPCPipe() const;
|
||||
@ -257,10 +279,12 @@ class CrashpadClient {
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if defined(OS_WIN)
|
||||
#if defined(OS_MACOSX)
|
||||
base::mac::ScopedMachSendRight exception_port_;
|
||||
#elif defined(OS_WIN)
|
||||
std::wstring ipc_pipe_;
|
||||
ScopedKernelHANDLE handler_start_thread_;
|
||||
#endif
|
||||
#endif // OS_MACOSX
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CrashpadClient);
|
||||
};
|
||||
|
@ -523,7 +523,7 @@ class HandlerStarter final : public NotifyServer::DefaultInterface {
|
||||
|
||||
} // namespace
|
||||
|
||||
CrashpadClient::CrashpadClient() {
|
||||
CrashpadClient::CrashpadClient() : exception_port_(MACH_PORT_NULL) {
|
||||
}
|
||||
|
||||
CrashpadClient::~CrashpadClient() {
|
||||
@ -569,8 +569,42 @@ bool CrashpadClient::SetHandlerMachService(const std::string& service_name) {
|
||||
|
||||
bool CrashpadClient::SetHandlerMachPort(
|
||||
base::mac::ScopedMachSendRight exception_port) {
|
||||
DCHECK(!exception_port_.is_valid());
|
||||
DCHECK(exception_port.is_valid());
|
||||
return SetCrashExceptionPorts(exception_port.get());
|
||||
|
||||
if (!SetCrashExceptionPorts(exception_port.get())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
exception_port_.swap(exception_port);
|
||||
return true;
|
||||
}
|
||||
|
||||
base::mac::ScopedMachSendRight CrashpadClient::GetHandlerMachPort() const {
|
||||
DCHECK(exception_port_.is_valid());
|
||||
|
||||
// For the purposes of this method, only return a port set by
|
||||
// SetHandlerMachPort().
|
||||
//
|
||||
// It would be possible to use task_get_exception_ports() to look up the
|
||||
// EXC_CRASH task exception port, but that’s probably not what users of this
|
||||
// interface really want. If CrashpadClient is asked for the handler Mach
|
||||
// port, it should only return a port that it knows about by virtue of having
|
||||
// set it. It shouldn’t return any EXC_CRASH task exception port in effect if
|
||||
// SetHandlerMachPort() was never called, and it shouldn’t return any
|
||||
// EXC_CRASH task exception port that might be set by other code after
|
||||
// SetHandlerMachPort() is called.
|
||||
//
|
||||
// The caller is accepting its own new ScopedMachSendRight, so increment the
|
||||
// reference count of the underlying right.
|
||||
kern_return_t kr = mach_port_mod_refs(
|
||||
mach_task_self(), exception_port_.get(), MACH_PORT_RIGHT_SEND, 1);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
MACH_LOG(ERROR, kr) << "mach_port_mod_refs";
|
||||
return base::mac::ScopedMachSendRight(MACH_PORT_NULL);
|
||||
}
|
||||
|
||||
return base::mac::ScopedMachSendRight(exception_port_.get());
|
||||
}
|
||||
|
||||
// static
|
||||
|
Loading…
x
Reference in New Issue
Block a user