diff --git a/handler/mac/exception_handler_server.cc b/handler/mac/exception_handler_server.cc index 400df562..3757c454 100644 --- a/handler/mac/exception_handler_server.cc +++ b/handler/mac/exception_handler_server.cc @@ -27,13 +27,13 @@ namespace crashpad { namespace { class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, - public NotifyServer::Interface { + public NotifyServer::DefaultInterface { public: ExceptionHandlerServerRun( mach_port_t exception_port, UniversalMachExcServer::Interface* exception_interface) : UniversalMachExcServer::Interface(), - NotifyServer::Interface(), + NotifyServer::DefaultInterface(), mach_exc_server_(this), notify_server_(this), composite_mach_message_server_(), @@ -144,22 +144,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, destroy_complex_request); } - // NotifyServer::Interface: - - kern_return_t DoMachNotifyPortDeleted( - notify_port_t notify, - mach_port_name_t name, - const mach_msg_trailer_t* trailer) override { - return UnimplementedNotifyRoutine(notify); - } - - kern_return_t DoMachNotifyPortDestroyed(notify_port_t notify, - mach_port_t rights, - const mach_msg_trailer_t* trailer, - bool* destroy_request) override { - *destroy_request = true; - return UnimplementedNotifyRoutine(notify); - } + // NotifyServer::DefaultInterface: kern_return_t DoMachNotifyNoSenders( notify_port_t notify, @@ -180,32 +165,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, return KERN_SUCCESS; } - kern_return_t DoMachNotifySendOnce( - notify_port_t notify, - const mach_msg_trailer_t* trailer) override { - return UnimplementedNotifyRoutine(notify); - } - - kern_return_t DoMachNotifyDeadName( - notify_port_t notify, - mach_port_name_t name, - const mach_msg_trailer_t* trailer) override { - return UnimplementedNotifyRoutine(notify); - } - private: - kern_return_t UnimplementedNotifyRoutine(notify_port_t notify) { - // Most of the routines in the notify subsystem are not expected to be - // called. - if (notify != notify_port_) { - LOG(WARNING) << "notify port mismatch"; - return KERN_FAILURE; - } - - NOTREACHED(); - return MIG_BAD_ID; - } - UniversalMachExcServer mach_exc_server_; NotifyServer notify_server_; CompositeMachMessageServer composite_mach_message_server_; diff --git a/util/mach/notify_server.cc b/util/mach/notify_server.cc index 05495c65..48a4a9e9 100644 --- a/util/mach/notify_server.cc +++ b/util/mach/notify_server.cc @@ -105,6 +105,42 @@ kern_return_t MIGCheckRequestMachNotifyDeadName( namespace crashpad { +kern_return_t NotifyServer::DefaultInterface::DoMachNotifyPortDeleted( + notify_port_t notify, + mach_port_name_t name, + const mach_msg_trailer_t* trailer) { + return MIG_BAD_ID; +} + +kern_return_t NotifyServer::DefaultInterface::DoMachNotifyPortDestroyed( + notify_port_t notify, + mach_port_t rights, + const mach_msg_trailer_t* trailer, + bool* destroy_request) { + *destroy_request = true; + return MIG_BAD_ID; +} + +kern_return_t NotifyServer::DefaultInterface::DoMachNotifyNoSenders( + notify_port_t notify, + mach_port_mscount_t mscount, + const mach_msg_trailer_t* trailer) { + return MIG_BAD_ID; +} + +kern_return_t NotifyServer::DefaultInterface::DoMachNotifySendOnce( + notify_port_t notify, + const mach_msg_trailer_t* trailer) { + return MIG_BAD_ID; +} + +kern_return_t NotifyServer::DefaultInterface::DoMachNotifyDeadName( + notify_port_t notify, + mach_port_name_t name, + const mach_msg_trailer_t* trailer) { + return MIG_BAD_ID; +} + NotifyServer::NotifyServer(NotifyServer::Interface* interface) : MachMessageServer::Interface(), interface_(interface) { diff --git a/util/mach/notify_server.h b/util/mach/notify_server.h index 311ad3a0..ce33b21b 100644 --- a/util/mach/notify_server.h +++ b/util/mach/notify_server.h @@ -37,6 +37,9 @@ class NotifyServer : public MachMessageServer::Interface { public: //! \brief An interface that the different request messages that are a part of //! the `notify` Mach subsystem can be dispatched to. + //! + //! Default implementations of all methods are available in the + //! DefaultInterface class. class Interface { public: //! \brief Handles port-deleted notifications sent by @@ -166,6 +169,52 @@ class NotifyServer : public MachMessageServer::Interface { ~Interface() {} }; + //! \brief A concrete implementation of Interface that provides a default + //! behavior for all `notify` routines. + //! + //! The Mach `notify` subsystem contains a collection of unrelated routines, + //! and a single server would rarely need to implement all of them. To make it + //! easier to use NotifyServer, a server can inherit from DefaultInterface + //! instead of Interface. Unless overridden, each routine in DefaultInterface + //! returns `MIG_BAD_ID` to indicate to the caller that the `notify` message + //! was unexpected and not processed. + class DefaultInterface : public Interface { + public: + // Interface: + + kern_return_t DoMachNotifyPortDeleted( + notify_port_t notify, + mach_port_name_t name, + const mach_msg_trailer_t* trailer) override; + + kern_return_t DoMachNotifyPortDestroyed( + notify_port_t notify, + mach_port_t rights, + const mach_msg_trailer_t* trailer, + bool* destroy_request) override; + + kern_return_t DoMachNotifyNoSenders( + notify_port_t notify, + mach_port_mscount_t mscount, + const mach_msg_trailer_t* trailer) override; + + kern_return_t DoMachNotifySendOnce( + notify_port_t notify, + const mach_msg_trailer_t* trailer) override; + + kern_return_t DoMachNotifyDeadName( + notify_port_t notify, + mach_port_name_t name, + const mach_msg_trailer_t* trailer) override; + + protected: + DefaultInterface() : Interface() {} + ~DefaultInterface() {} + + private: + DISALLOW_COPY_AND_ASSIGN(DefaultInterface); + }; + //! \brief Constructs an object of this class. //! //! \param[in] interface The interface to dispatch requests to. Weak.