Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #ifndef CRASHPAD_UTIL_MACH_MACH_MESSAGE_SERVER_H_ | |
| 16 #define CRASHPAD_UTIL_MACH_MACH_MESSAGE_SERVER_H_ | |
| 17 | |
| 18 #include <mach/mach.h> | |
| 19 | |
| 20 namespace crashpad { | |
| 21 | |
| 22 //! \brief A Mach RPC callback interface, called by MachMessageServer(). | |
| 23 class MachMessageServerInterface { | |
| 24 public: | |
| 25 //! \brief Handles a Mach RPC request. | |
| 26 //! | |
| 27 //! This method is a stand-in for a MIG-generated Mach RPC server “demux” | |
| 28 //! function such as `exc_server()` and `mach_exc_server()`. Implementations | |
| 29 //! may call such a function directly. This method is expected to behave | |
| 30 //! exactly as these functions behave. | |
| 31 //! | |
| 32 //! \param[in] in The request message, received as a Mach message. | |
| 33 //! \param[out] out The reply message. The caller allocates storage, and the | |
| 34 //! callee is expected to populate the reply message appropriately. After | |
| 35 //! returning, the caller will send this reply as a Mach message via the | |
| 36 //! message’s reply port. | |
| 37 //! \param[out] destroy_complex_request `true` if a complex request message | |
| 38 //! is to be destroyed even when handled successfully, `false` otherwise. | |
| 39 //! The traditional behavior is `false`. In this case, the caller only | |
| 40 //! destroys the request message in \a in when the reply message in \a out | |
| 41 //! is not complex and when it indicates a return code other than | |
| 42 //! `KERN_SUCCESS` or `MIG_NO_REPLY`. The assumption is that the rights or | |
| 43 //! out-of-line data carried in a complex message may be retained by the | |
| 44 //! server in this situation, and that it is the responsibility of the | |
| 45 //! server to release these resources as needed. However, in many cases, | |
| 46 //! these resources are not needed beyond the duration of a request-reply | |
| 47 //! transaction, and in such cases, it is less error-prone to always have | |
| 48 //! the caller, MachMessageServer(), destroy complex request messages. To | |
| 49 //! choose this behavior, this parameter should be set to `true`. | |
| 50 //! | |
| 51 //! \return `true` on success and `false` on failure, although the caller | |
| 52 //! ignores the return value. However, the return code to be included in | |
| 53 //! the reply message should be set as `mig_reply_error_t::RetCode`. The | |
| 54 //! non-`void` return value is used for increased compatibility with | |
| 55 //! MIG-generated functions. | |
| 56 virtual bool MachMessageServerFunction(mach_msg_header_t* in, | |
| 57 mach_msg_header_t* out, | |
| 58 bool* destroy_complex_request) = 0; | |
| 59 | |
| 60 //! \return The expected or maximum size, in bytes, of a request message to be | |
| 61 //! received as the \a in parameter of MachMessageServerFunction(). | |
| 62 virtual mach_msg_size_t MachMessageServerRequestSize() = 0; | |
| 63 | |
| 64 //! \return The maximum size, in bytes, of a reply message to be sent via the | |
| 65 //! \a out parameter of MachMessageServerFunction(). This value does not | |
| 66 //! need to include the size of any trailer to be sent with the message. | |
| 67 virtual mach_msg_size_t MachMessageServerReplySize() = 0; | |
| 68 | |
| 69 protected: | |
| 70 ~MachMessageServerInterface() {} | |
| 71 }; | |
| 72 | |
| 73 //! \brief Runs a Mach message server to handle a Mach RPC request. | |
|
Robert Sesek
2014/09/08 16:28:47
I'd call out explicitly that this is used for MIG
| |
| 74 //! | |
| 75 //! This function listens for a request message and passes it to a callback | |
| 76 //! interface. A reponse is collected from that interface, and is sent back as | |
| 77 //! a reply. | |
| 78 //! | |
| 79 //! The size | |
|
Robert Sesek
2014/09/08 16:28:47
Incomplete comment.
| |
| 80 //! | |
| 81 //! This function is similar to `mach_msg_server()` and | |
| 82 //! `mach_msg_server_once()`. | |
| 83 //! | |
| 84 //! \param[in] interface The MachMessageServerInterface that is responsible for | |
| 85 //! handling the message. | |
| 86 //! MachMessageServerInterface::MachMessageServerRequestSize() is used as | |
| 87 //! the receive size for the request message, and | |
| 88 //! MachMessageServerInterface::MachMessageServerReplySize() is used as the | |
| 89 //! maximum size of the reply message. If \a options contains | |
| 90 //! `MACH_RCV_LARGE`, this function will retry a receive operation that | |
| 91 //! returns `MACH_RCV_TOO_LARGE` with an appropriately-sized buffer. | |
| 92 //! MachMessageServerInterface::MachMessageServerFunction() is called to | |
| 93 //! handle the request and populate the reply. | |
| 94 //! \param[in] receive_port The port on which to receive the request message. | |
| 95 //! \param[in] options Options suitable for mach_msg. | |
| 96 //! \param[in] persistent When `true`, this function operates in a loop rather | |
|
Robert Sesek
2014/09/08 16:28:47
I'm not sure how clear these two bool parameters a
| |
| 97 //! than returning immediately after handling the first request-response | |
| 98 //! pair. | |
| 99 //! \param[in] nonblocking When `true`, this function will not block during | |
| 100 //! receive or send. | |
| 101 //! \param[in] timeout When \a nonblocking is `false`, the the maximum duration | |
| 102 //! that this entire function will run, in milliseconds, or | |
| 103 //! `MACH_MSG_TIMEOUT_NONE` to specify no timeout (infinite waiting). When | |
| 104 //! \a nonblocking is `true`, this parameter has no effect. When \a | |
| 105 //! persistent is `true`, the timeout applies to the overall duration of | |
| 106 //! this function, not to any individual `mach_msg()` call. | |
| 107 //! | |
| 108 //! \return On success, `KERN_SUCCESS` (when \a persistent is `false`) or | |
| 109 //! `MACH_RCV_TIMED_OUT` (when \a persistent and \a nonblocking are both | |
| 110 //! `true`, or when \a persistent is `true`, \a nonblocking is `false`, and | |
| 111 //! \a timeout is not `MACH_MSG_TIMEOUT_NONE`. This function has no | |
| 112 //! successful return value when \a persistent is `true`, \a nonblocking is | |
| 113 //! `false`, and \a timeout is `MACH_MSG_TIMEOUT_NONE`. On failure, returns | |
| 114 //! a value identifying the nature of the error. | |
| 115 mach_msg_return_t MachMessageServer(MachMessageServerInterface* interface, | |
| 116 mach_port_t receive_port, | |
| 117 mach_msg_options_t options, | |
| 118 bool persistent, | |
| 119 bool nonblocking, | |
| 120 mach_msg_timeout_t timeout); | |
| 121 | |
| 122 } // namespace crashpad | |
| 123 | |
| 124 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_SERVER_H_ | |
| OLD | NEW |