| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 notify_port, | 109 notify_port, |
| 110 run_even_if_expired); | 110 run_even_if_expired); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace | 113 } // namespace |
| 114 | 114 |
| 115 // This method implements a server similar to 10.9.4 | 115 // This method implements a server similar to 10.9.4 |
| 116 // xnu-2422.110.17/libsyscall/mach/mach_msg.c mach_msg_server_once(). The server | 116 // xnu-2422.110.17/libsyscall/mach/mach_msg.c mach_msg_server_once(). The server |
| 117 // callback function and |max_size| parameter have been replaced with a C++ | 117 // callback function and |max_size| parameter have been replaced with a C++ |
| 118 // interface. The |persistent| parameter has been added, allowing this method to | 118 // interface. The |persistent| parameter has been added, allowing this method to |
| 119 // serve as a stand-in for mach_msg_server(). The |nonblocking| parameter has | 119 // serve as a stand-in for mach_msg_server(). The |timeout_ms| parameter has |
| 120 // been added, allowing blocking to be controlled directly. The |timeout_ms| | 120 // been added, allowing this function to not block indefinitely. |
| 121 // parameter has been added, allowing this function to not block indefinitely. | |
| 122 // | 121 // |
| 123 // static | 122 // static |
| 124 mach_msg_return_t MachMessageServer::Run(Interface* interface, | 123 mach_msg_return_t MachMessageServer::Run(Interface* interface, |
| 125 mach_port_t receive_port, | 124 mach_port_t receive_port, |
| 126 mach_msg_options_t options, | 125 mach_msg_options_t options, |
| 127 Persistent persistent, | 126 Persistent persistent, |
| 128 Nonblocking nonblocking, | |
| 129 ReceiveLarge receive_large, | 127 ReceiveLarge receive_large, |
| 130 mach_msg_timeout_t timeout_ms) { | 128 mach_msg_timeout_t timeout_ms) { |
| 131 options &= ~(MACH_RCV_MSG | MACH_SEND_MSG); | 129 options &= ~(MACH_RCV_MSG | MACH_SEND_MSG); |
| 132 | 130 |
| 133 MachMessageDeadline deadline; | 131 const MachMessageDeadline deadline = |
| 134 if (nonblocking == kNonblocking) { | 132 MachMessageDeadlineFromTimeout(timeout_ms); |
| 135 deadline = kMachMessageNonblocking; | |
| 136 } else if (timeout_ms == MACH_MSG_TIMEOUT_NONE) { | |
| 137 deadline = kMachMessageWaitIndefinitely; | |
| 138 } else { | |
| 139 deadline = MachMessageDeadlineFromTimeout(timeout_ms); | |
| 140 } | |
| 141 | 133 |
| 142 if (receive_large == kReceiveLargeResize) { | 134 if (receive_large == kReceiveLargeResize) { |
| 143 options |= MACH_RCV_LARGE; | 135 options |= MACH_RCV_LARGE; |
| 144 } else { | 136 } else { |
| 145 options &= ~MACH_RCV_LARGE; | 137 options &= ~MACH_RCV_LARGE; |
| 146 } | 138 } |
| 147 | 139 |
| 148 const mach_msg_size_t trailer_alloc = REQUESTED_TRAILER_SIZE(options); | 140 const mach_msg_size_t trailer_alloc = REQUESTED_TRAILER_SIZE(options); |
| 149 const mach_msg_size_t expected_receive_size = | 141 const mach_msg_size_t expected_receive_size = |
| 150 round_msg(interface->MachMessageServerRequestSize()) + trailer_alloc; | 142 round_msg(interface->MachMessageServerRequestSize()) + trailer_alloc; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 244 } |
| 253 | 245 |
| 254 if (reply_header->msgh_remote_port != MACH_PORT_NULL) { | 246 if (reply_header->msgh_remote_port != MACH_PORT_NULL) { |
| 255 // Avoid blocking indefinitely. This duplicates the logic in 10.9.5 | 247 // Avoid blocking indefinitely. This duplicates the logic in 10.9.5 |
| 256 // xnu-2422.115.4/libsyscall/mach/mach_msg.c mach_msg_server_once(), | 248 // xnu-2422.115.4/libsyscall/mach/mach_msg.c mach_msg_server_once(), |
| 257 // although the special provision for sending to a send-once right is not | 249 // although the special provision for sending to a send-once right is not |
| 258 // made, because kernel keeps sends to a send-once right on the fast path | 250 // made, because kernel keeps sends to a send-once right on the fast path |
| 259 // without considering the user-specified timeout. See 10.9.5 | 251 // without considering the user-specified timeout. See 10.9.5 |
| 260 // xnu-2422.115.4/osfmk/ipc/ipc_mqueue.c ipc_mqueue_send(). | 252 // xnu-2422.115.4/osfmk/ipc/ipc_mqueue.c ipc_mqueue_send(). |
| 261 const MachMessageDeadline send_deadline = | 253 const MachMessageDeadline send_deadline = |
| 262 deadline == kMachMessageWaitIndefinitely ? kMachMessageNonblocking | 254 deadline == kMachMessageDeadlineWaitIndefinitely |
| 263 : deadline; | 255 ? kMachMessageDeadlineNonblocking |
| 256 : deadline; |
| 264 | 257 |
| 265 kr = MachMessageWithDeadline(reply_header, | 258 kr = MachMessageWithDeadline(reply_header, |
| 266 options | MACH_SEND_MSG, | 259 options | MACH_SEND_MSG, |
| 267 0, | 260 0, |
| 268 MACH_PORT_NULL, | 261 MACH_PORT_NULL, |
| 269 send_deadline, | 262 send_deadline, |
| 270 MACH_PORT_NULL, | 263 MACH_PORT_NULL, |
| 271 true); | 264 true); |
| 272 | 265 |
| 273 if (kr != MACH_MSG_SUCCESS) { | 266 if (kr != MACH_MSG_SUCCESS) { |
| 274 if (kr == MACH_SEND_INVALID_DEST || | 267 if (kr == MACH_SEND_INVALID_DEST || |
| 275 kr == MACH_SEND_TIMED_OUT || | 268 kr == MACH_SEND_TIMED_OUT || |
| 276 kr == MACH_SEND_INTERRUPTED) { | 269 kr == MACH_SEND_INTERRUPTED) { |
| 277 mach_msg_destroy(reply_header); | 270 mach_msg_destroy(reply_header); |
| 278 } | 271 } |
| 279 return kr; | 272 return kr; |
| 280 } | 273 } |
| 281 } | 274 } |
| 282 } while (persistent == kPersistent || retry); | 275 } while (persistent == kPersistent || retry); |
| 283 | 276 |
| 284 return kr; | 277 return kr; |
| 285 } | 278 } |
| 286 | 279 |
| 287 } // namespace crashpad | 280 } // namespace crashpad |
| OLD | NEW |