2 * Copyright (c) 1999-2013 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
55 #include <mach/mach.h>
56 #include <mach/boolean.h>
57 #include <mach/kern_return.h>
58 #include <mach/message.h>
59 #include <mach/mig_errors.h>
60 #include <mach/vm_statistics.h>
61 #include <TargetConditionals.h>
63 extern int proc_importance_assertion_begin_with_msg(mach_msg_header_t
* msg
, mach_msg_trailer_t
* trailer
, uint64_t * assertion_handlep
);
64 extern int proc_importance_assertion_complete(uint64_t assertion_handle
);
66 #define MACH_MSG_TRAP(msg, opt, ssize, rsize, rname, to, not) \
67 mach_msg_trap((msg), (opt), (ssize), (rsize), (rname), (to), (not))
69 #define LIBMACH_OPTIONS (MACH_SEND_INTERRUPT|MACH_RCV_INTERRUPT)
74 * Send and/or receive a message. If the message operation
75 * is interrupted, and the user did not request an indication
76 * of that fact, then restart the appropriate parts of the
80 mach_msg(msg
, option
, send_size
, rcv_size
, rcv_name
, timeout
, notify
)
81 mach_msg_header_t
*msg
;
82 mach_msg_option_t option
;
83 mach_msg_size_t send_size
;
84 mach_msg_size_t rcv_size
;
86 mach_msg_timeout_t timeout
;
92 * Consider the following cases:
93 * 1) Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
95 * 2) Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
96 * 3) RPC calls with interruptions in one/both halves.
98 * We refrain from passing the option bits that we implement
99 * to the kernel. This prevents their presence from inhibiting
100 * the kernel's fast paths (when it checks the option value).
103 mr
= MACH_MSG_TRAP(msg
, option
& ~LIBMACH_OPTIONS
,
104 send_size
, rcv_size
, rcv_name
,
106 if (mr
== MACH_MSG_SUCCESS
) {
107 return MACH_MSG_SUCCESS
;
110 if ((option
& MACH_SEND_INTERRUPT
) == 0) {
111 while (mr
== MACH_SEND_INTERRUPTED
) {
112 mr
= MACH_MSG_TRAP(msg
,
113 option
& ~LIBMACH_OPTIONS
,
114 send_size
, rcv_size
, rcv_name
,
119 if ((option
& MACH_RCV_INTERRUPT
) == 0) {
120 while (mr
== MACH_RCV_INTERRUPTED
) {
121 mr
= MACH_MSG_TRAP(msg
,
122 option
& ~(LIBMACH_OPTIONS
| MACH_SEND_MSG
),
123 0, rcv_size
, rcv_name
,
132 * Routine: mach_msg_overwrite
134 * Send and/or receive a message. If the message operation
135 * is interrupted, and the user did not request an indication
136 * of that fact, then restart the appropriate parts of the
139 * Distinct send and receive buffers may be specified. If
140 * no separate receive buffer is specified, the msg parameter
141 * will be used for both send and receive operations.
143 * In addition to a distinct receive buffer, that buffer may
144 * already contain scatter control information to direct the
145 * receiving of the message.
148 mach_msg_overwrite(msg
, option
, send_size
, rcv_limit
, rcv_name
, timeout
,
149 notify
, rcv_msg
, rcv_scatter_size
)
150 mach_msg_header_t
*msg
;
151 mach_msg_option_t option
;
152 mach_msg_size_t send_size
;
153 mach_msg_size_t rcv_limit
;
154 mach_port_t rcv_name
;
155 mach_msg_timeout_t timeout
;
157 mach_msg_header_t
*rcv_msg
;
158 mach_msg_size_t rcv_scatter_size
;
160 mach_msg_return_t mr
;
163 * Consider the following cases:
164 * 1) Errors in pseudo-receive (eg, MACH_SEND_INTERRUPTED
165 * plus special bits).
166 * 2) Use of MACH_SEND_INTERRUPT/MACH_RCV_INTERRUPT options.
167 * 3) RPC calls with interruptions in one/both halves.
169 * We refrain from passing the option bits that we implement
170 * to the kernel. This prevents their presence from inhibiting
171 * the kernel's fast paths (when it checks the option value).
174 mr
= mach_msg_overwrite_trap(msg
, option
& ~LIBMACH_OPTIONS
,
175 send_size
, rcv_limit
, rcv_name
,
176 timeout
, notify
, rcv_msg
, rcv_scatter_size
);
177 if (mr
== MACH_MSG_SUCCESS
) {
178 return MACH_MSG_SUCCESS
;
181 if ((option
& MACH_SEND_INTERRUPT
) == 0) {
182 while (mr
== MACH_SEND_INTERRUPTED
) {
183 mr
= mach_msg_overwrite_trap(msg
,
184 option
& ~LIBMACH_OPTIONS
,
185 send_size
, rcv_limit
, rcv_name
,
186 timeout
, notify
, rcv_msg
, rcv_scatter_size
);
190 if ((option
& MACH_RCV_INTERRUPT
) == 0) {
191 while (mr
== MACH_RCV_INTERRUPTED
) {
192 mr
= mach_msg_overwrite_trap(msg
,
193 option
& ~(LIBMACH_OPTIONS
| MACH_SEND_MSG
),
194 0, rcv_limit
, rcv_name
,
195 timeout
, notify
, rcv_msg
, rcv_scatter_size
);
204 mach_msg_send(mach_msg_header_t
*msg
)
206 return mach_msg(msg
, MACH_SEND_MSG
,
207 msg
->msgh_size
, 0, MACH_PORT_NULL
,
208 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
212 mach_msg_receive(mach_msg_header_t
*msg
)
214 return mach_msg(msg
, MACH_RCV_MSG
,
215 0, msg
->msgh_size
, msg
->msgh_local_port
,
216 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
221 mach_msg_destroy_port(mach_port_t port
, mach_msg_type_name_t type
)
223 if (MACH_PORT_VALID(port
)) {
225 case MACH_MSG_TYPE_MOVE_SEND
:
226 case MACH_MSG_TYPE_MOVE_SEND_ONCE
:
227 /* destroy the send/send-once right */
228 (void) mach_port_deallocate(mach_task_self_
, port
);
231 case MACH_MSG_TYPE_MOVE_RECEIVE
:
232 /* destroy the receive right */
233 (void) mach_port_mod_refs(mach_task_self_
, port
,
234 MACH_PORT_RIGHT_RECEIVE
, -1);
237 case MACH_MSG_TYPE_MAKE_SEND
:
238 /* create a send right and then destroy it */
239 (void) mach_port_insert_right(mach_task_self_
, port
,
240 port
, MACH_MSG_TYPE_MAKE_SEND
);
241 (void) mach_port_deallocate(mach_task_self_
, port
);
244 case MACH_MSG_TYPE_MAKE_SEND_ONCE
:
245 /* create a send-once right and then destroy it */
246 (void) mach_port_extract_right(mach_task_self_
, port
,
247 MACH_MSG_TYPE_MAKE_SEND_ONCE
,
249 (void) mach_port_deallocate(mach_task_self_
, port
);
256 mach_msg_destroy_memory(vm_offset_t addr
, vm_size_t size
)
259 (void) vm_deallocate(mach_task_self_
, addr
, size
);
265 * Routine: mach_msg_destroy
267 * mach_msg_destroy is useful in two contexts.
269 * First, it can deallocate all port rights and
270 * out-of-line memory in a received message.
271 * When a server receives a request it doesn't want,
272 * it needs this functionality.
274 * Second, it can mimic the side-effects of a msg-send
275 * operation. The effect is as if the message were sent
276 * and then destroyed inside the kernel. When a server
277 * can't send a reply (because the client died),
278 * it needs this functionality.
281 mach_msg_destroy(mach_msg_header_t
*msg
)
283 mach_msg_bits_t mbits
= msg
->msgh_bits
;
286 * The msgh_local_port field doesn't hold a port right.
287 * The receive operation consumes the destination port right.
290 mach_msg_destroy_port(msg
->msgh_remote_port
, MACH_MSGH_BITS_REMOTE(mbits
));
291 mach_msg_destroy_port(msg
->msgh_voucher_port
, MACH_MSGH_BITS_VOUCHER(mbits
));
293 if (mbits
& MACH_MSGH_BITS_COMPLEX
) {
294 mach_msg_base_t
*base
;
295 mach_msg_type_number_t count
, i
;
296 mach_msg_descriptor_t
*daddr
;
298 base
= (mach_msg_base_t
*) msg
;
299 count
= base
->body
.msgh_descriptor_count
;
301 daddr
= (mach_msg_descriptor_t
*) (base
+ 1);
302 for (i
= 0; i
< count
; i
++) {
303 switch (daddr
->type
.type
) {
304 case MACH_MSG_PORT_DESCRIPTOR
: {
305 mach_msg_port_descriptor_t
*dsc
;
308 * Destroy port rights carried in the message
311 mach_msg_destroy_port(dsc
->name
, dsc
->disposition
);
312 daddr
= (mach_msg_descriptor_t
*)(dsc
+ 1);
316 case MACH_MSG_OOL_DESCRIPTOR
: {
317 mach_msg_ool_descriptor_t
*dsc
;
320 * Destroy memory carried in the message
322 dsc
= &daddr
->out_of_line
;
323 if (dsc
->deallocate
) {
324 mach_msg_destroy_memory((vm_offset_t
)dsc
->address
,
327 daddr
= (mach_msg_descriptor_t
*)(dsc
+ 1);
331 case MACH_MSG_OOL_VOLATILE_DESCRIPTOR
: {
332 mach_msg_ool_descriptor_t
*dsc
;
337 dsc
= &daddr
->out_of_line
;
338 daddr
= (mach_msg_descriptor_t
*)(dsc
+ 1);
342 case MACH_MSG_OOL_PORTS_DESCRIPTOR
: {
344 mach_msg_ool_ports_descriptor_t
*dsc
;
345 mach_msg_type_number_t j
;
348 * Destroy port rights carried in the message
350 dsc
= &daddr
->ool_ports
;
351 ports
= (mach_port_t
*) dsc
->address
;
352 for (j
= 0; j
< dsc
->count
; j
++, ports
++) {
353 mach_msg_destroy_port(*ports
, dsc
->disposition
);
357 * Destroy memory carried in the message
359 if (dsc
->deallocate
) {
360 mach_msg_destroy_memory((vm_offset_t
)dsc
->address
,
361 dsc
->count
* sizeof(mach_port_t
));
363 daddr
= (mach_msg_descriptor_t
*)(dsc
+ 1);
372 * Routine: mach_msg_server_once
374 * A simple generic server function. It allows more flexibility
375 * than mach_msg_server by processing only one message request
376 * and then returning to the user. Note that more in the way
377 * of error codes are returned to the user; specifically, any
378 * failing error from mach_msg calls will be returned
379 * (though errors from the demux routine or the routine it
380 * calls will not be).
383 mach_msg_server_once(
384 boolean_t (*demux
)(mach_msg_header_t
*, mach_msg_header_t
*),
385 mach_msg_size_t max_size
,
386 mach_port_t rcv_name
,
387 mach_msg_options_t options
)
389 mig_reply_error_t
*bufRequest
, *bufReply
;
390 mach_msg_size_t request_size
;
391 mach_msg_size_t request_alloc
;
392 mach_msg_size_t trailer_alloc
;
393 mach_msg_size_t reply_alloc
;
394 mach_msg_return_t mr
;
396 mach_port_t self
= mach_task_self_
;
397 voucher_mach_msg_state_t old_state
= VOUCHER_MACH_MSG_STATE_UNCHANGED
;
399 options
&= ~(MACH_SEND_MSG
| MACH_RCV_MSG
| MACH_RCV_VOUCHER
);
401 trailer_alloc
= REQUESTED_TRAILER_SIZE(options
);
402 request_alloc
= (mach_msg_size_t
)round_page(max_size
+ trailer_alloc
);
404 request_size
= (options
& MACH_RCV_LARGE
) ?
405 request_alloc
: max_size
+ trailer_alloc
;
407 reply_alloc
= (mach_msg_size_t
)round_page((options
& MACH_SEND_TRAILER
) ?
408 (max_size
+ MAX_TRAILER_SIZE
) :
411 kr
= vm_allocate(self
,
412 (vm_address_t
*)&bufReply
,
414 VM_MAKE_TAG(VM_MEMORY_MACH_MSG
) | TRUE
);
415 if (kr
!= KERN_SUCCESS
) {
420 mach_msg_size_t new_request_alloc
;
422 kr
= vm_allocate(self
,
423 (vm_address_t
*)&bufRequest
,
425 VM_MAKE_TAG(VM_MEMORY_MACH_MSG
) | TRUE
);
426 if (kr
!= KERN_SUCCESS
) {
428 (vm_address_t
)bufReply
,
433 mr
= mach_msg(&bufRequest
->Head
, MACH_RCV_MSG
| MACH_RCV_VOUCHER
| options
,
434 0, request_size
, rcv_name
,
435 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
437 if (!((mr
== MACH_RCV_TOO_LARGE
) && (options
& MACH_RCV_LARGE
))) {
441 new_request_alloc
= (mach_msg_size_t
)round_page(bufRequest
->Head
.msgh_size
+
444 (vm_address_t
) bufRequest
,
446 request_size
= request_alloc
= new_request_alloc
;
449 if (mr
== MACH_MSG_SUCCESS
) {
450 /* we have a request message */
452 old_state
= voucher_mach_msg_adopt(&bufRequest
->Head
);
454 (void) (*demux
)(&bufRequest
->Head
, &bufReply
->Head
);
456 if (!(bufReply
->Head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
)) {
457 if (bufReply
->RetCode
== MIG_NO_REPLY
) {
458 bufReply
->Head
.msgh_remote_port
= MACH_PORT_NULL
;
459 } else if ((bufReply
->RetCode
!= KERN_SUCCESS
) &&
460 (bufRequest
->Head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
)) {
461 /* destroy the request - but not the reply port */
462 bufRequest
->Head
.msgh_remote_port
= MACH_PORT_NULL
;
463 mach_msg_destroy(&bufRequest
->Head
);
468 * We don't want to block indefinitely because the client
469 * isn't receiving messages from the reply port.
470 * If we have a send-once right for the reply port, then
471 * this isn't a concern because the send won't block.
472 * If we have a send right, we need to use MACH_SEND_TIMEOUT.
473 * To avoid falling off the kernel's fast RPC path unnecessarily,
474 * we only supply MACH_SEND_TIMEOUT when absolutely necessary.
476 if (bufReply
->Head
.msgh_remote_port
!= MACH_PORT_NULL
) {
477 mr
= mach_msg(&bufReply
->Head
,
478 (MACH_MSGH_BITS_REMOTE(bufReply
->Head
.msgh_bits
) ==
479 MACH_MSG_TYPE_MOVE_SEND_ONCE
) ?
480 MACH_SEND_MSG
| options
:
481 MACH_SEND_MSG
| MACH_SEND_TIMEOUT
| options
,
482 bufReply
->Head
.msgh_size
, 0, MACH_PORT_NULL
,
483 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
485 if ((mr
!= MACH_SEND_INVALID_DEST
) &&
486 (mr
!= MACH_SEND_TIMED_OUT
)) {
489 mr
= MACH_MSG_SUCCESS
;
491 if (bufReply
->Head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
) {
492 mach_msg_destroy(&bufReply
->Head
);
497 voucher_mach_msg_revert(old_state
);
499 (void)vm_deallocate(self
,
500 (vm_address_t
) bufRequest
,
502 (void)vm_deallocate(self
,
503 (vm_address_t
) bufReply
,
509 * Routine: mach_msg_server
511 * A simple generic server function. Note that changes here
512 * should be considered for duplication above.
516 boolean_t (*demux
)(mach_msg_header_t
*, mach_msg_header_t
*),
517 mach_msg_size_t max_size
,
518 mach_port_t rcv_name
,
519 mach_msg_options_t options
)
521 mig_reply_error_t
*bufRequest
, *bufReply
;
522 mach_msg_size_t request_size
;
523 mach_msg_size_t new_request_alloc
;
524 mach_msg_size_t request_alloc
;
525 mach_msg_size_t trailer_alloc
;
526 mach_msg_size_t reply_alloc
;
527 mach_msg_return_t mr
;
529 mach_port_t self
= mach_task_self_
;
530 voucher_mach_msg_state_t old_state
= VOUCHER_MACH_MSG_STATE_UNCHANGED
;
531 boolean_t buffers_swapped
= FALSE
;
533 options
&= ~(MACH_SEND_MSG
| MACH_RCV_MSG
| MACH_RCV_VOUCHER
| MACH_RCV_OVERWRITE
);
535 reply_alloc
= (mach_msg_size_t
)round_page((options
& MACH_SEND_TRAILER
) ?
536 (max_size
+ MAX_TRAILER_SIZE
) : max_size
);
538 kr
= vm_allocate(self
,
539 (vm_address_t
*)&bufReply
,
541 VM_MAKE_TAG(VM_MEMORY_MACH_MSG
) | TRUE
);
542 if (kr
!= KERN_SUCCESS
) {
547 trailer_alloc
= REQUESTED_TRAILER_SIZE(options
);
548 new_request_alloc
= (mach_msg_size_t
)round_page(max_size
+ trailer_alloc
);
550 request_size
= (options
& MACH_RCV_LARGE
) ?
551 new_request_alloc
: max_size
+ trailer_alloc
;
554 if (request_alloc
< new_request_alloc
) {
555 request_alloc
= new_request_alloc
;
556 kr
= vm_allocate(self
,
557 (vm_address_t
*)&bufRequest
,
559 VM_MAKE_TAG(VM_MEMORY_MACH_MSG
) | TRUE
);
560 if (kr
!= KERN_SUCCESS
) {
562 (vm_address_t
)bufReply
,
568 mr
= mach_msg(&bufRequest
->Head
, MACH_RCV_MSG
| MACH_RCV_VOUCHER
| options
,
569 0, request_size
, rcv_name
,
570 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
572 while (mr
== MACH_MSG_SUCCESS
) {
573 /* we have another request message */
575 buffers_swapped
= FALSE
;
576 old_state
= voucher_mach_msg_adopt(&bufRequest
->Head
);
577 bufReply
->Head
= (mach_msg_header_t
){};
579 (void) (*demux
)(&bufRequest
->Head
, &bufReply
->Head
);
581 if (!(bufReply
->Head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
)) {
582 if (bufReply
->RetCode
== MIG_NO_REPLY
) {
583 bufReply
->Head
.msgh_remote_port
= MACH_PORT_NULL
;
584 } else if ((bufReply
->RetCode
!= KERN_SUCCESS
) &&
585 (bufRequest
->Head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
)) {
586 /* destroy the request - but not the reply port */
587 bufRequest
->Head
.msgh_remote_port
= MACH_PORT_NULL
;
588 mach_msg_destroy(&bufRequest
->Head
);
593 * We don't want to block indefinitely because the client
594 * isn't receiving messages from the reply port.
595 * If we have a send-once right for the reply port, then
596 * this isn't a concern because the send won't block.
597 * If we have a send right, we need to use MACH_SEND_TIMEOUT.
598 * To avoid falling off the kernel's fast RPC path,
599 * we only supply MACH_SEND_TIMEOUT when absolutely necessary.
601 if (bufReply
->Head
.msgh_remote_port
!= MACH_PORT_NULL
) {
602 if (request_alloc
== reply_alloc
) {
603 mig_reply_error_t
*bufTemp
;
607 (MACH_MSGH_BITS_REMOTE(bufReply
->Head
.msgh_bits
) ==
608 MACH_MSG_TYPE_MOVE_SEND_ONCE
) ?
609 MACH_SEND_MSG
| MACH_RCV_MSG
| MACH_RCV_TIMEOUT
| MACH_RCV_VOUCHER
| options
:
610 MACH_SEND_MSG
| MACH_RCV_MSG
| MACH_SEND_TIMEOUT
| MACH_RCV_TIMEOUT
| MACH_RCV_VOUCHER
| options
,
611 bufReply
->Head
.msgh_size
, request_size
, rcv_name
,
612 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
614 /* swap request and reply */
615 bufTemp
= bufRequest
;
616 bufRequest
= bufReply
;
618 buffers_swapped
= TRUE
;
620 mr
= mach_msg_overwrite(
622 (MACH_MSGH_BITS_REMOTE(bufReply
->Head
.msgh_bits
) ==
623 MACH_MSG_TYPE_MOVE_SEND_ONCE
) ?
624 MACH_SEND_MSG
| MACH_RCV_MSG
| MACH_RCV_TIMEOUT
| MACH_RCV_VOUCHER
| options
:
625 MACH_SEND_MSG
| MACH_RCV_MSG
| MACH_SEND_TIMEOUT
| MACH_RCV_TIMEOUT
| MACH_RCV_VOUCHER
| options
,
626 bufReply
->Head
.msgh_size
, request_size
, rcv_name
,
627 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
,
628 &bufRequest
->Head
, 0);
631 if ((mr
!= MACH_SEND_INVALID_DEST
) &&
632 (mr
!= MACH_SEND_TIMED_OUT
) &&
633 (mr
!= MACH_RCV_TIMED_OUT
)) {
634 voucher_mach_msg_revert(old_state
);
635 old_state
= VOUCHER_MACH_MSG_STATE_UNCHANGED
;
641 * Need to destroy the reply msg in case if there was a send timeout or
642 * invalid destination. The reply msg would be swapped with request msg
643 * if buffers_swapped is true, thus destroy request msg instead of
644 * reply msg in such cases.
646 if (mr
!= MACH_RCV_TIMED_OUT
) {
647 if (buffers_swapped
) {
648 if (bufRequest
->Head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
) {
649 mach_msg_destroy(&bufRequest
->Head
);
652 if (bufReply
->Head
.msgh_bits
& MACH_MSGH_BITS_COMPLEX
) {
653 mach_msg_destroy(&bufReply
->Head
);
657 voucher_mach_msg_revert(old_state
);
658 old_state
= VOUCHER_MACH_MSG_STATE_UNCHANGED
;
660 mr
= mach_msg(&bufRequest
->Head
, MACH_RCV_MSG
| MACH_RCV_VOUCHER
| options
,
661 0, request_size
, rcv_name
,
662 MACH_MSG_TIMEOUT_NONE
, MACH_PORT_NULL
);
663 } /* while (mr == MACH_MSG_SUCCESS) */
665 if ((mr
== MACH_RCV_TOO_LARGE
) && (options
& MACH_RCV_LARGE
)) {
666 new_request_alloc
= (mach_msg_size_t
)round_page(bufRequest
->Head
.msgh_size
+
668 request_size
= new_request_alloc
;
670 (vm_address_t
) bufRequest
,
678 (void)vm_deallocate(self
,
679 (vm_address_t
) bufRequest
,
681 (void)vm_deallocate(self
,
682 (vm_address_t
) bufReply
,
688 * Routine: mach_msg_server_importance
690 * A simple generic server function which handles importance
691 * promotion assertions for adaptive daemons.
694 mach_msg_server_importance(
695 boolean_t (*demux
)(mach_msg_header_t
*, mach_msg_header_t
*),
696 mach_msg_size_t max_size
,
697 mach_port_t rcv_name
,
698 mach_msg_options_t options
)
700 return mach_msg_server(demux
, max_size
, rcv_name
, options
);
704 mach_voucher_deallocate(
705 mach_voucher_t voucher
)
707 return mach_port_deallocate(mach_task_self(), voucher
);