| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 //! \brief Informs Run() whether or not to block while waiting for requests. | 96 //! \brief Informs Run() whether or not to block while waiting for requests. |
| 97 enum Nonblocking { | 97 enum Nonblocking { |
| 98 //! \brief Wait for a request message if none is queued. | 98 //! \brief Wait for a request message if none is queued. |
| 99 kBlocking = false, | 99 kBlocking = false, |
| 100 | 100 |
| 101 //! \brief Return as soon as there no request messages queued. This may | 101 //! \brief Return as soon as there no request messages queued. This may |
| 102 //! result in an immediate return without handling any requests. | 102 //! result in an immediate return without handling any requests. |
| 103 kNonblocking, | 103 kNonblocking, |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 //! \brief Determines how to handle the reception of messages larger than the |
| 107 //! size of the buffer allocated to store them. |
| 108 enum ReceiveLarge { |
| 109 //! \brief Return `MACH_RCV_TOO_LARGE` upon receipt of a large message. |
| 110 //! |
| 111 //! This mimics the default behavior of `mach_msg_server()` when `options` |
| 112 //! does not contain `MACH_RCV_LARGE`. |
| 113 kReceiveLargeError = 0, |
| 114 |
| 115 //! \brief Ignore large messages, and attempt to receive the next queued |
| 116 //! message upon encountering one. |
| 117 //! |
| 118 //! When a large message is encountered, a warning will be logged. |
| 119 //! |
| 120 //! `mach_msg()` will be called to receive the next message after a large |
| 121 //! one even when accompanied by a #Persistent value of #kOneShot. |
| 122 kReceiveLargeIgnore, |
| 123 |
| 124 //! \brief Allocate an appropriately-sized buffer upon encountering a large |
| 125 //! message. The buffer will be used to receive the message. This |
| 126 //! |
| 127 //! This mimics the behavior of `mach_msg_server()` when `options` contains |
| 128 //! `MACH_RCV_LARGE`. |
| 129 kReceiveLargeResize, |
| 130 }; |
| 131 |
| 106 //! \brief Runs a Mach message server to handle a Mach RPC request for MIG | 132 //! \brief Runs a Mach message server to handle a Mach RPC request for MIG |
| 107 //! servers. | 133 //! servers. |
| 108 //! | 134 //! |
| 109 //! This function listens for a request message and passes it to a callback | 135 //! This function listens for a request message and passes it to a callback |
| 110 //! interface. A reponse is collected from that interface, and is sent back as | 136 //! interface. A reponse is collected from that interface, and is sent back as |
| 111 //! a reply. | 137 //! a reply. |
| 112 //! | 138 //! |
| 113 //! This function is similar to `mach_msg_server()` and | 139 //! This function is similar to `mach_msg_server()` and |
| 114 //! `mach_msg_server_once()`. | 140 //! `mach_msg_server_once()`. |
| 115 //! | 141 //! |
| 116 //! \param[in] interface The MachMessageServerInterface that is responsible | 142 //! \param[in] interface The MachMessageServerInterface that is responsible |
| 117 //! for handling the message. Interface::MachMessageServerRequestSize() is | 143 //! for handling the message. Interface::MachMessageServerRequestSize() is |
| 118 //! used as the receive size for the request message, and | 144 //! used as the receive size for the request message, and |
| 119 //! Interface::MachMessageServerReplySize() is used as the | 145 //! Interface::MachMessageServerReplySize() is used as the |
| 120 //! maximum size of the reply message. If \a options contains | 146 //! maximum size of the reply message. If \a options contains |
| 121 //! `MACH_RCV_LARGE`, this function will retry a receive operation that | 147 //! `MACH_RCV_LARGE`, this function will retry a receive operation that |
| 122 //! returns `MACH_RCV_TOO_LARGE` with an appropriately-sized buffer. | 148 //! returns `MACH_RCV_TOO_LARGE` with an appropriately-sized buffer. |
| 123 //! MachMessageServerInterface::MachMessageServerFunction() is called to | 149 //! MachMessageServerInterface::MachMessageServerFunction() is called to |
| 124 //! handle the request and populate the reply. | 150 //! handle the request and populate the reply. |
| 125 //! \param[in] receive_port The port on which to receive the request message. | 151 //! \param[in] receive_port The port on which to receive the request message. |
| 126 //! \param[in] options Options suitable for mach_msg. For the defaults, use | 152 //! \param[in] options Options suitable for mach_msg. For the defaults, use |
| 127 //! `MACH_MSG_OPTION_NONE`. | 153 //! `MACH_MSG_OPTION_NONE`. `MACH_RCV_LARGE` when specified here is |
| 154 //! ignored. Set \a receive_large to #kReceiveLargeResize instead. |
| 128 //! \param[in] persistent Chooses between one-shot and persistent operation. | 155 //! \param[in] persistent Chooses between one-shot and persistent operation. |
| 129 //! \param[in] nonblocking Chooses between blocking and nonblocking operation. | 156 //! \param[in] nonblocking Chooses between blocking and nonblocking operation. |
| 157 //! \param[in] receive_large Determines the behavior upon encountering a |
| 158 //! message larger than the receive buffer’s size. |
| 130 //! \param[in] timeout_ms When \a nonblocking is `false`, the the maximum | 159 //! \param[in] timeout_ms When \a nonblocking is `false`, the the maximum |
| 131 //! duration that this entire function will run, in milliseconds, or | 160 //! duration that this entire function will run, in milliseconds, or |
| 132 //! `MACH_MSG_TIMEOUT_NONE` to specify no timeout (infinite waiting). When | 161 //! `MACH_MSG_TIMEOUT_NONE` to specify no timeout (infinite waiting). When |
| 133 //! \a nonblocking is `true`, this parameter has no effect. When \a | 162 //! \a nonblocking is `true`, this parameter has no effect. When \a |
| 134 //! persistent is `true`, the timeout applies to the overall duration of | 163 //! persistent is `true`, the timeout applies to the overall duration of |
| 135 //! this function, not to any individual `mach_msg()` call. | 164 //! this function, not to any individual `mach_msg()` call. |
| 136 //! | 165 //! |
| 137 //! \return On success, `KERN_SUCCESS` (when \a persistent is `false`) or | 166 //! \return On success, `KERN_SUCCESS` (when \a persistent is `false`) or |
| 138 //! `MACH_RCV_TIMED_OUT` (when \a persistent and \a nonblocking are both | 167 //! `MACH_RCV_TIMED_OUT` (when \a persistent and \a nonblocking are both |
| 139 //! `true`, or when \a persistent is `true`, \a nonblocking is `false`, | 168 //! `true`, or when \a persistent is `true`, \a nonblocking is `false`, |
| 140 //! and \a timeout is not `MACH_MSG_TIMEOUT_NONE`. This function has no | 169 //! and \a timeout is not `MACH_MSG_TIMEOUT_NONE`. This function has no |
| 141 //! successful return value when \a persistent is `true`, \a nonblocking | 170 //! successful return value when \a persistent is `true`, \a nonblocking |
| 142 //! is `false`, and \a timeout is `MACH_MSG_TIMEOUT_NONE`. On failure, | 171 //! is `false`, and \a timeout is `MACH_MSG_TIMEOUT_NONE`. On failure, |
| 143 //! returns a value identifying the nature of the error. | 172 //! returns a value identifying the nature of the error. |
| 144 static mach_msg_return_t Run(Interface* interface, | 173 static mach_msg_return_t Run(Interface* interface, |
| 145 mach_port_t receive_port, | 174 mach_port_t receive_port, |
| 146 mach_msg_options_t options, | 175 mach_msg_options_t options, |
| 147 Persistent persistent, | 176 Persistent persistent, |
| 148 Nonblocking nonblocking, | 177 Nonblocking nonblocking, |
| 178 ReceiveLarge receive_large, |
| 149 mach_msg_timeout_t timeout_ms); | 179 mach_msg_timeout_t timeout_ms); |
| 150 | 180 |
| 151 private: | 181 private: |
| 152 DISALLOW_IMPLICIT_CONSTRUCTORS(MachMessageServer); | 182 DISALLOW_IMPLICIT_CONSTRUCTORS(MachMessageServer); |
| 153 }; | 183 }; |
| 154 | 184 |
| 155 } // namespace crashpad | 185 } // namespace crashpad |
| 156 | 186 |
| 157 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_SERVER_H_ | 187 #endif // CRASHPAD_UTIL_MACH_MACH_MESSAGE_SERVER_H_ |
| OLD | NEW |