2014-12-30 14:23:47 -05:00
|
|
|
|
// Copyright 2014 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_HANDLER_MAC_EXCEPTION_HANDLER_SERVER_H_
|
|
|
|
|
#define CRASHPAD_HANDLER_MAC_EXCEPTION_HANDLER_SERVER_H_
|
|
|
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
|
|
#include <mach/mach.h>
|
|
|
|
|
|
|
|
|
|
#include "base/mac/scoped_mach_port.h"
|
2015-02-04 18:32:42 -05:00
|
|
|
|
#include "util/mach/exc_server_variants.h"
|
2014-12-30 14:23:47 -05:00
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
|
|
|
|
//! \brief Runs the main exception-handling server in Crashpad’s handler
|
|
|
|
|
//! process.
|
|
|
|
|
class ExceptionHandlerServer {
|
|
|
|
|
public:
|
2015-10-29 18:09:03 -04:00
|
|
|
|
//! \brief Constructs an ExceptionHandlerServer object.
|
|
|
|
|
//!
|
|
|
|
|
//! \param[in] receive_port The port that exception messages and no-senders
|
|
|
|
|
//! notifications will be received on.
|
2015-11-03 19:20:29 -05:00
|
|
|
|
//! \param[in] launchd If `true`, the exception handler is being run from
|
|
|
|
|
//! launchd. \a receive_port is not monitored for no-senders
|
|
|
|
|
//! notifications, and instead, the expected “quit” signal is receipt of
|
|
|
|
|
//! `SIGTERM`.
|
|
|
|
|
ExceptionHandlerServer(base::mac::ScopedMachReceiveRight receive_port,
|
|
|
|
|
bool launchd);
|
2014-12-30 14:23:47 -05:00
|
|
|
|
~ExceptionHandlerServer();
|
|
|
|
|
|
|
|
|
|
//! \brief Runs the exception-handling server.
|
|
|
|
|
//!
|
2015-02-04 18:32:42 -05:00
|
|
|
|
//! \param[in] exception_interface An object to send exception messages to.
|
|
|
|
|
//!
|
2015-11-03 19:20:29 -05:00
|
|
|
|
//! This method monitors the receive port for exception messages and, if
|
|
|
|
|
//! not being run by launchd, no-senders notifications. It continues running
|
|
|
|
|
//! until it has no more clients, indicated by the receipt of a no-senders
|
|
|
|
|
//! notification, or if being run by launchd, receipt of `SIGTERM`. When not
|
|
|
|
|
//! being run by launchd, it is important to assure that a send right exists
|
|
|
|
|
//! in a client (or has been queued by `mach_msg()` to be sent to a client)
|
|
|
|
|
//! prior to calling this method, or it will detect that it is sender-less and
|
|
|
|
|
//! return immediately.
|
2015-02-04 18:32:42 -05:00
|
|
|
|
//!
|
|
|
|
|
//! All exception messages will be passed to \a exception_interface.
|
2014-12-30 14:23:47 -05:00
|
|
|
|
//!
|
|
|
|
|
//! This method must only be called once on an ExceptionHandlerServer object.
|
|
|
|
|
//!
|
|
|
|
|
//! If an unexpected condition that prevents this method from functioning is
|
|
|
|
|
//! encountered, it will log a message and terminate execution. Receipt of an
|
2015-10-29 18:09:03 -04:00
|
|
|
|
//! invalid message on the receive port will cause a message to be logged, but
|
2014-12-30 14:23:47 -05:00
|
|
|
|
//! this method will continue running normally.
|
2015-02-04 18:32:42 -05:00
|
|
|
|
void Run(UniversalMachExcServer::Interface* exception_interface);
|
2014-12-30 14:23:47 -05:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
base::mac::ScopedMachReceiveRight receive_port_;
|
2015-11-03 19:20:29 -05:00
|
|
|
|
bool launchd_;
|
2014-12-30 14:23:47 -05:00
|
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServer);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace crashpad
|
|
|
|
|
|
|
|
|
|
#endif // CRASHPAD_HANDLER_MAC_EXCEPTION_HANDLER_SERVER_H_
|