Crashpad

Public Member Functions | List of all members
crashpad::CompositeMachMessageServer Class Reference

Adapts multiple MachMessageServer::Interface implementations for simultaneous use in a single MachMessageServer::Run() call. More...

`#include "util/mach/composite_mach_message_server.h"`

Inheritance diagram for crashpad::CompositeMachMessageServer:

## Public Member Functions
void | AddHandler (MachMessageServer::Interface *handler)
| Adds a handler that messages can be dispatched to based on request message ID. More...
bool | MachMessageServerFunction (const mach_msg_header_t *in, mach_msg_header_t *out, bool *destroy_complex_request) override
| Handles a Mach RPC request. More...
std::set< mach_msg_id_t > | MachMessageServerRequestIDs () override
mach_msg_size_t | MachMessageServerRequestSize () override
mach_msg_size_t | MachMessageServerReplySize () override

## Detailed Description

Adapts multiple MachMessageServer::Interface implementations for simultaneous use in a single MachMessageServer::Run() call.

This class implements a MachMessageServer::Interface that contains other other MachMessageServer::Interface objects.

In some situations, it may be desirable for a Mach message server to handle messages from distinct MIG subsystems with distinct MachMessageServer::Interface implementations. This may happen if a single receive right is shared for multiple subsystems, or if distinct receive rights are combined in a Mach port set. In these cases, this class performs a first-level demultiplexing to forward request messages to the proper subsystem-level demultiplexers.

## Member Function Documentation

## ◆ AddHandler()

void crashpad::CompositeMachMessageServer::AddHandler | ( | MachMessageServer::Interface * | handler | ) |

Adds a handler that messages can be dispatched to based on request message ID.

Parameters

  [in] | handler | A MachMessageServer handler. Ownership of this object is not taken. Cycles must not be created between objects. It is invalid to add an object as its own handler.

If handler claims to support any request ID that this object is already able to handle, execution will be terminated.

## ◆ MachMessageServerFunction()

bool crashpad::CompositeMachMessageServer::MachMessageServerFunction | ( | const mach_msg_header_t * | in,
|  | mach_msg_header_t * | out,
|  | bool * | destroy_complex_request
| ) |  |
| override virtual

Handles a Mach RPC request.

This method is a stand-in for a MIG-generated Mach RPC server “demux” function such as `exc_server()` and `mach_exc_server()`. Implementations may call such a function directly. This method is expected to behave exactly as these functions behave.

Parameters

  [in] | in | The request message, received as a Mach message. Note that this interface uses a `const` parameter for this purpose, whereas MIG-generated “demux” functions do not.
  [out] | out | The reply message. The caller allocates storage, and the callee is expected to populate the reply message appropriately. After returning, the caller will send this reply as a Mach message via the message’s reply port.
  [out] | destroy_complex_request | `true` if a complex request message is to be destroyed even when handled successfully, `false` otherwise. The traditional behavior is `false`. In this case, the caller only destroys the request message in in when the reply message in out is not complex and when it indicates a return code other than `KERN_SUCCESS` or `MIG_NO_REPLY`. The assumption is that the rights or out-of-line data carried in a complex message may be retained by the server in this situation, and that it is the responsibility of the server to release these resources as needed. However, in many cases, these resources are not needed beyond the duration of a request-reply transaction, and in such cases, it is less error-prone to always have the caller, MachMessageServer::Run(), destroy complex request messages. To choose this behavior, this parameter should be set to `true`.

Returns
  `true` on success and `false` on failure, although the caller ignores the return value. However, the return code to be included in the reply message should be set as `mig_reply_error_t::RetCode`. The non-`void` return value is used for increased compatibility with MIG-generated functions.

This implementation forwards the message to an appropriate handler added by AddHandler() on the basis of the in request message’s message ID. If no appropriate handler exists, the out reply message is treated as a `mig_reply_error_t`, its return code is set to `MIG_BAD_ID`, and `false` is returned.

Implements crashpad::MachMessageServer::Interface.

## ◆ MachMessageServerReplySize()

mach_msg_size_t crashpad::CompositeMachMessageServer::MachMessageServerReplySize | ( |  | ) |
| override virtual

Returns
  The maximum size, in bytes, of a reply message to be sent via the out parameter of MachMessageServerFunction(). This value does not need to include the size of any trailer to be sent with the message.

This implementation returns the maximum reply message size of all handlers added by AddHandler(). If no handlers are present, returns the size of `mig_reply_error_t`, the minimum size of a MIG reply message.

Implements crashpad::MachMessageServer::Interface.

## ◆ MachMessageServerRequestIDs()

std::set< mach_msg_id_t > crashpad::CompositeMachMessageServer::MachMessageServerRequestIDs | ( |  | ) |
| override virtual

Returns
  The set of request message Mach message IDs that MachMessageServerFunction() is able to handle.

This implementation returns the set of all request message Mach message IDs of all handlers added by AddHandler().

Implements crashpad::MachMessageServer::Interface.

## ◆ MachMessageServerRequestSize()

mach_msg_size_t crashpad::CompositeMachMessageServer::MachMessageServerRequestSize | ( |  | ) |
| override virtual

Returns
  The expected or maximum size, in bytes, of a request message to be received as the in parameter of MachMessageServerFunction().

This implementation returns the maximum request message size of all handlers added by AddHandler(). If no handlers are present, returns the size of `mach_msg_header_t`, the minimum size of a MIG request message that can be received for demultiplexing purposes.

Implements crashpad::MachMessageServer::Interface.

The documentation for this class was generated from the following files:

- util/mach/composite_mach_message_server.h
- util/mach/composite_mach_message_server.cc