2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * @OSF_FREE_COPYRIGHT@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 * File: ipc/ipc_mqueue.c
58 * Functions to manipulate IPC message queues.
61 #include <mach/port.h>
62 #include <mach/message.h>
63 #include <mach/sync_policy.h>
65 #include <kern/assert.h>
66 #include <kern/counters.h>
67 #include <kern/sched_prim.h>
68 #include <kern/ipc_kobject.h>
69 #include <kern/ipc_mig.h> /* XXX - for mach_msg_receive_continue */
70 #include <kern/misc_protos.h>
71 #include <kern/task.h>
72 #include <kern/thread.h>
73 #include <kern/wait_queue.h>
75 #include <ipc/ipc_mqueue.h>
76 #include <ipc/ipc_kmsg.h>
77 #include <ipc/ipc_port.h>
78 #include <ipc/ipc_pset.h>
79 #include <ipc/ipc_space.h>
83 int ipc_mqueue_full
; /* address is event for queue space */
84 int ipc_mqueue_rcv
; /* address is event for message arrival */
88 /* forward declarations */
89 void ipc_mqueue_receive_results(wait_result_t result
);
92 * Routine: ipc_mqueue_init
94 * Initialize a newly-allocated message queue.
102 wait_queue_set_init(&mqueue
->imq_set_queue
, SYNC_POLICY_FIFO
);
104 wait_queue_init(&mqueue
->imq_wait_queue
, SYNC_POLICY_FIFO
);
105 ipc_kmsg_queue_init(&mqueue
->imq_messages
);
106 mqueue
->imq_seqno
= 0;
107 mqueue
->imq_msgcount
= 0;
108 mqueue
->imq_qlimit
= MACH_PORT_QLIMIT_DEFAULT
;
109 mqueue
->imq_fullwaiters
= FALSE
;
114 * Routine: ipc_mqueue_member
116 * Indicate whether the (port) mqueue is a member of
117 * this portset's mqueue. We do this by checking
118 * whether the portset mqueue's waitq is an member of
119 * the port's mqueue waitq.
121 * the portset's mqueue is not already a member
122 * this may block while allocating linkage structures.
127 ipc_mqueue_t port_mqueue
,
128 ipc_mqueue_t set_mqueue
)
130 wait_queue_t port_waitq
= &port_mqueue
->imq_wait_queue
;
131 wait_queue_set_t set_waitq
= &set_mqueue
->imq_set_queue
;
133 return (wait_queue_member(port_waitq
, set_waitq
));
138 * Routine: ipc_mqueue_remove
140 * Remove the association between the queue and the specified
147 ipc_mqueue_t set_mqueue
)
149 wait_queue_t mq_waitq
= &mqueue
->imq_wait_queue
;
150 wait_queue_set_t set_waitq
= &set_mqueue
->imq_set_queue
;
152 return wait_queue_unlink(mq_waitq
, set_waitq
);
156 * Routine: ipc_mqueue_remove_from_all
158 * Remove the mqueue from all the sets it is a member of
163 ipc_mqueue_remove_from_all(
166 wait_queue_t mq_waitq
= &mqueue
->imq_wait_queue
;
168 wait_queue_unlink_all(mq_waitq
);
173 * Routine: ipc_mqueue_remove_all
175 * Remove all the member queues from the specified set.
180 ipc_mqueue_remove_all(
183 wait_queue_set_t mq_setq
= &mqueue
->imq_set_queue
;
185 wait_queue_set_unlink_all(mq_setq
);
191 * Routine: ipc_mqueue_add
193 * Associate the portset's mqueue with the port's mqueue.
194 * This has to be done so that posting the port will wakeup
195 * a portset waiter. If there are waiters on the portset
196 * mqueue and messages on the port mqueue, try to match them
203 ipc_mqueue_t port_mqueue
,
204 ipc_mqueue_t set_mqueue
)
206 wait_queue_t port_waitq
= &port_mqueue
->imq_wait_queue
;
207 wait_queue_set_t set_waitq
= &set_mqueue
->imq_set_queue
;
208 ipc_kmsg_queue_t kmsgq
;
209 ipc_kmsg_t kmsg
, next
;
213 kr
= wait_queue_link(port_waitq
, set_waitq
);
214 if (kr
!= KERN_SUCCESS
)
218 * Now that the set has been added to the port, there may be
219 * messages queued on the port and threads waiting on the set
220 * waitq. Lets get them together.
223 imq_lock(port_mqueue
);
224 kmsgq
= &port_mqueue
->imq_messages
;
225 for (kmsg
= ipc_kmsg_queue_first(kmsgq
);
228 next
= ipc_kmsg_queue_next(kmsgq
, kmsg
);
233 th
= wait_queue_wakeup64_identity_locked(
238 /* waitq/mqueue still locked, thread locked */
240 if (th
== THREAD_NULL
)
244 * Found a receiver. see if they can handle the message
245 * correctly (the message is not too large for them, or
246 * they didn't care to be informed that the message was
247 * too large). If they can't handle it, take them off
248 * the list and let them go back and figure it out and
249 * just move onto the next.
252 kmsg
->ikm_header
->msgh_size
+
253 REQUESTED_TRAILER_SIZE(th
->ith_option
)) {
254 th
->ith_state
= MACH_RCV_TOO_LARGE
;
255 th
->ith_msize
= kmsg
->ikm_header
->msgh_size
;
256 if (th
->ith_option
& MACH_RCV_LARGE
) {
258 * let him go without message
260 th
->ith_kmsg
= IKM_NULL
;
263 continue; /* find another thread */
266 th
->ith_state
= MACH_MSG_SUCCESS
;
270 * This thread is going to take this message,
273 ipc_kmsg_rmqueue(kmsgq
, kmsg
);
274 ipc_mqueue_release_msgcount(port_mqueue
);
277 th
->ith_seqno
= port_mqueue
->imq_seqno
++;
279 break; /* go to next message */
284 imq_unlock(port_mqueue
);
290 * Routine: ipc_mqueue_changed
292 * Wake up receivers waiting in a message queue.
294 * The message queue is locked.
301 wait_queue_wakeup64_all_locked(
302 &mqueue
->imq_wait_queue
,
305 FALSE
); /* unlock waitq? */
312 * Routine: ipc_mqueue_send
314 * Send a message to a message queue. The message holds a reference
315 * for the destination port for this message queue in the
316 * msgh_remote_port field.
318 * If unsuccessful, the caller still has possession of
319 * the message and must do something with it. If successful,
320 * the message is queued, given to a receiver, or destroyed.
324 * MACH_MSG_SUCCESS The message was accepted.
325 * MACH_SEND_TIMED_OUT Caller still has message.
326 * MACH_SEND_INTERRUPTED Caller still has message.
332 mach_msg_option_t option
,
333 mach_msg_timeout_t send_timeout
)
340 * 1) We're under the queue limit.
341 * 2) Caller used the MACH_SEND_ALWAYS internal option.
342 * 3) Message is sent to a send-once right.
347 if (!imq_full(mqueue
) ||
348 (option
& MACH_SEND_ALWAYS
) ||
349 (MACH_MSGH_BITS_REMOTE(kmsg
->ikm_header
->msgh_bits
) ==
350 MACH_MSG_TYPE_PORT_SEND_ONCE
)) {
351 mqueue
->imq_msgcount
++;
352 assert(mqueue
->imq_msgcount
> 0);
356 thread_t cur_thread
= current_thread();
360 * We have to wait for space to be granted to us.
362 if ((option
& MACH_SEND_TIMEOUT
) && (send_timeout
== 0)) {
365 return MACH_SEND_TIMED_OUT
;
367 mqueue
->imq_fullwaiters
= TRUE
;
368 thread_lock(cur_thread
);
369 if (option
& MACH_SEND_TIMEOUT
)
370 clock_interval_to_deadline(send_timeout
, 1000*NSEC_PER_USEC
, &deadline
);
373 wresult
= wait_queue_assert_wait64_locked(
374 &mqueue
->imq_wait_queue
,
376 THREAD_ABORTSAFE
, deadline
,
378 thread_unlock(cur_thread
);
382 if (wresult
== THREAD_WAITING
) {
383 wresult
= thread_block(THREAD_CONTINUE_NULL
);
384 counter(c_ipc_mqueue_send_block
++);
388 case THREAD_TIMED_OUT
:
389 assert(option
& MACH_SEND_TIMEOUT
);
390 return MACH_SEND_TIMED_OUT
;
392 case THREAD_AWAKENED
:
393 /* we can proceed - inherited msgcount from waker */
394 assert(mqueue
->imq_msgcount
> 0);
397 case THREAD_INTERRUPTED
:
398 return MACH_SEND_INTERRUPTED
;
402 panic("ipc_mqueue_send");
406 ipc_mqueue_post(mqueue
, kmsg
);
407 return MACH_MSG_SUCCESS
;
411 * Routine: ipc_mqueue_release_msgcount
413 * Release a message queue reference in the case where we
417 * The message queue is locked.
418 * The message corresponding to this reference is off the queue.
421 ipc_mqueue_release_msgcount(
424 assert(imq_held(mqueue
));
425 assert(mqueue
->imq_msgcount
> 1 || ipc_kmsg_queue_empty(&mqueue
->imq_messages
));
427 mqueue
->imq_msgcount
--;
429 if (!imq_full(mqueue
) && mqueue
->imq_fullwaiters
) {
430 if (wait_queue_wakeup64_one_locked(
431 &mqueue
->imq_wait_queue
,
434 FALSE
) != KERN_SUCCESS
) {
435 mqueue
->imq_fullwaiters
= FALSE
;
437 /* gave away our slot - add reference back */
438 mqueue
->imq_msgcount
++;
444 * Routine: ipc_mqueue_post
446 * Post a message to a waiting receiver or enqueue it. If a
447 * receiver is waiting, we can release our reserved space in
451 * If we need to queue, our space in the message queue is reserved.
455 register ipc_mqueue_t mqueue
,
456 register ipc_kmsg_t kmsg
)
462 * While the msg queue is locked, we have control of the
463 * kmsg, so the ref in it for the port is still good.
465 * Check for a receiver for the message.
470 wait_queue_t waitq
= &mqueue
->imq_wait_queue
;
473 receiver
= wait_queue_wakeup64_identity_locked(
478 /* waitq still locked, thread locked */
480 if (receiver
== THREAD_NULL
) {
482 * no receivers; queue kmsg
484 assert(mqueue
->imq_msgcount
> 0);
485 ipc_kmsg_enqueue_macro(&mqueue
->imq_messages
, kmsg
);
490 * We found a waiting thread.
491 * If the message is too large or the scatter list is too small
492 * the thread we wake up will get that as its status.
494 if (receiver
->ith_msize
<
495 (kmsg
->ikm_header
->msgh_size
) +
496 REQUESTED_TRAILER_SIZE(receiver
->ith_option
)) {
497 receiver
->ith_msize
= kmsg
->ikm_header
->msgh_size
;
498 receiver
->ith_state
= MACH_RCV_TOO_LARGE
;
500 receiver
->ith_state
= MACH_MSG_SUCCESS
;
504 * If there is no problem with the upcoming receive, or the
505 * receiver thread didn't specifically ask for special too
506 * large error condition, go ahead and select it anyway.
508 if ((receiver
->ith_state
== MACH_MSG_SUCCESS
) ||
509 !(receiver
->ith_option
& MACH_RCV_LARGE
)) {
511 receiver
->ith_kmsg
= kmsg
;
512 receiver
->ith_seqno
= mqueue
->imq_seqno
++;
513 thread_unlock(receiver
);
515 /* we didn't need our reserved spot in the queue */
516 ipc_mqueue_release_msgcount(mqueue
);
521 * Otherwise, this thread needs to be released to run
522 * and handle its error without getting the message. We
523 * need to go back and pick another one.
525 receiver
->ith_kmsg
= IKM_NULL
;
526 receiver
->ith_seqno
= 0;
527 thread_unlock(receiver
);
533 current_task()->messages_sent
++;
539 ipc_mqueue_receive_results(wait_result_t saved_wait_result
)
541 thread_t self
= current_thread();
542 mach_msg_option_t option
= self
->ith_option
;
546 * why did we wake up?
548 switch (saved_wait_result
) {
549 case THREAD_TIMED_OUT
:
550 self
->ith_state
= MACH_RCV_TIMED_OUT
;
553 case THREAD_INTERRUPTED
:
554 self
->ith_state
= MACH_RCV_INTERRUPTED
;
558 /* something bad happened to the port/set */
559 self
->ith_state
= MACH_RCV_PORT_CHANGED
;
562 case THREAD_AWAKENED
:
564 * We do not need to go select a message, somebody
565 * handed us one (or a too-large indication).
567 mr
= MACH_MSG_SUCCESS
;
569 switch (self
->ith_state
) {
570 case MACH_RCV_SCATTER_SMALL
:
571 case MACH_RCV_TOO_LARGE
:
573 * Somebody tried to give us a too large
574 * message. If we indicated that we cared,
575 * then they only gave us the indication,
576 * otherwise they gave us the indication
577 * AND the message anyway.
579 if (option
& MACH_RCV_LARGE
) {
583 case MACH_MSG_SUCCESS
:
587 panic("ipc_mqueue_receive_results: strange ith_state");
591 panic("ipc_mqueue_receive_results: strange wait_result");
596 ipc_mqueue_receive_continue(
597 __unused
void *param
,
598 wait_result_t wresult
)
600 ipc_mqueue_receive_results(wresult
);
601 mach_msg_receive_continue(); /* hard-coded for now */
605 * Routine: ipc_mqueue_receive
607 * Receive a message from a message queue.
609 * If continuation is non-zero, then we might discard
610 * our kernel stack when we block. We will continue
611 * after unblocking by executing continuation.
613 * If resume is true, then we are resuming a receive
614 * operation after a blocked receive discarded our stack.
616 * Our caller must hold a reference for the port or port set
617 * to which this queue belongs, to keep the queue
618 * from being deallocated.
620 * The kmsg is returned with clean header fields
621 * and with the circular bit turned off.
623 * MACH_MSG_SUCCESS Message returned in kmsgp.
624 * MACH_RCV_TOO_LARGE Message size returned in kmsgp.
625 * MACH_RCV_TIMED_OUT No message obtained.
626 * MACH_RCV_INTERRUPTED No message obtained.
627 * MACH_RCV_PORT_DIED Port/set died; no message.
628 * MACH_RCV_PORT_CHANGED Port moved into set; no msg.
635 mach_msg_option_t option
,
636 mach_msg_size_t max_size
,
637 mach_msg_timeout_t rcv_timeout
,
640 ipc_kmsg_queue_t kmsgs
;
641 wait_result_t wresult
;
649 if (imq_is_set(mqueue
)) {
650 wait_queue_link_t wql
;
651 ipc_mqueue_t port_mq
;
654 q
= &mqueue
->imq_setlinks
;
657 * If we are waiting on a portset mqueue, we need to see if
658 * any of the member ports have work for us. If so, try to
659 * deliver one of those messages. By holding the portset's
660 * mqueue lock during the search, we tie up any attempts by
661 * mqueue_deliver or portset membership changes that may
662 * cross our path. But this is a lock order violation, so we
663 * have to do it "softly." If we don't find a message waiting
664 * for us, we will assert our intention to wait while still
665 * holding that lock. When we release the lock, the deliver/
666 * change will succeed and find us.
669 queue_iterate(q
, wql
, wait_queue_link_t
, wql_setlinks
) {
670 port_mq
= (ipc_mqueue_t
)wql
->wql_queue
;
671 kmsgs
= &port_mq
->imq_messages
;
673 if (!imq_lock_try(port_mq
)) {
679 goto search_set
; /* start again at beginning - SMP */
683 * If there is still a message to be had, we will
684 * try to select it (may not succeed because of size
685 * and options). In any case, we deliver those
686 * results back to the user.
688 * We also move the port's linkage to the tail of the
689 * list for this set (fairness). Future versions will
690 * sort by timestamp or priority.
692 if (ipc_kmsg_queue_first(kmsgs
) == IKM_NULL
) {
696 queue_remove(q
, wql
, wait_queue_link_t
, wql_setlinks
);
697 queue_enter(q
, wql
, wait_queue_link_t
, wql_setlinks
);
700 ipc_mqueue_select(port_mq
, option
, max_size
);
710 * Receive on a single port. Just try to get the messages.
712 kmsgs
= &mqueue
->imq_messages
;
713 if (ipc_kmsg_queue_first(kmsgs
) != IKM_NULL
) {
714 ipc_mqueue_select(mqueue
, option
, max_size
);
722 * Looks like we'll have to block. The mqueue we will
723 * block on (whether the set's or the local port's) is
726 self
= current_thread();
727 if (option
& MACH_RCV_TIMEOUT
) {
728 if (rcv_timeout
== 0) {
731 self
->ith_state
= MACH_RCV_TIMED_OUT
;
737 self
->ith_state
= MACH_RCV_IN_PROGRESS
;
738 self
->ith_option
= option
;
739 self
->ith_msize
= max_size
;
741 if (option
& MACH_RCV_TIMEOUT
)
742 clock_interval_to_deadline(rcv_timeout
, 1000*NSEC_PER_USEC
, &deadline
);
746 wresult
= wait_queue_assert_wait64_locked(&mqueue
->imq_wait_queue
,
748 interruptible
, deadline
,
754 if (wresult
== THREAD_WAITING
) {
755 counter((interruptible
== THREAD_ABORTSAFE
) ?
756 c_ipc_mqueue_receive_block_user
++ :
757 c_ipc_mqueue_receive_block_kernel
++);
759 if (self
->ith_continuation
)
760 thread_block(ipc_mqueue_receive_continue
);
763 wresult
= thread_block(THREAD_CONTINUE_NULL
);
765 ipc_mqueue_receive_results(wresult
);
770 * Routine: ipc_mqueue_select
772 * A receiver discovered that there was a message on the queue
773 * before he had to block. Pick the message off the queue and
774 * "post" it to himself.
777 * There is a message.
779 * MACH_MSG_SUCCESS Actually selected a message for ourselves.
780 * MACH_RCV_TOO_LARGE May or may not have pull it, but it is large
785 mach_msg_option_t option
,
786 mach_msg_size_t max_size
)
788 thread_t self
= current_thread();
790 mach_msg_return_t mr
;
791 mach_msg_size_t rcv_size
;
793 mr
= MACH_MSG_SUCCESS
;
797 * Do some sanity checking of our ability to receive
798 * before pulling the message off the queue.
800 kmsg
= ipc_kmsg_queue_first(&mqueue
->imq_messages
);
801 assert(kmsg
!= IKM_NULL
);
804 * If we really can't receive it, but we had the
805 * MACH_RCV_LARGE option set, then don't take it off
806 * the queue, instead return the appropriate error
809 rcv_size
= ipc_kmsg_copyout_size(kmsg
, self
->map
);
810 if (rcv_size
+ REQUESTED_TRAILER_SIZE(option
) > max_size
) {
811 mr
= MACH_RCV_TOO_LARGE
;
812 if (option
& MACH_RCV_LARGE
) {
813 self
->ith_kmsg
= IKM_NULL
;
814 self
->ith_msize
= rcv_size
;
816 self
->ith_state
= mr
;
821 ipc_kmsg_rmqueue_first_macro(&mqueue
->imq_messages
, kmsg
);
822 ipc_mqueue_release_msgcount(mqueue
);
823 self
->ith_seqno
= mqueue
->imq_seqno
++;
824 self
->ith_kmsg
= kmsg
;
825 self
->ith_state
= mr
;
827 current_task()->messages_received
++;
832 * Routine: ipc_mqueue_destroy
834 * Destroy a message queue. Set any blocked senders running.
835 * Destroy the kmsgs in the queue.
838 * Receivers were removed when the receive right was "changed"
844 ipc_kmsg_queue_t kmqueue
;
852 * rouse all blocked senders
854 mqueue
->imq_fullwaiters
= FALSE
;
855 wait_queue_wakeup64_all_locked(
856 &mqueue
->imq_wait_queue
,
861 kmqueue
= &mqueue
->imq_messages
;
863 while ((kmsg
= ipc_kmsg_dequeue(kmqueue
)) != IKM_NULL
) {
867 ipc_kmsg_destroy_dest(kmsg
);
877 * Routine: ipc_mqueue_set_qlimit
879 * Changes a message queue limit; the maximum number
880 * of messages which may be queued.
886 ipc_mqueue_set_qlimit(
888 mach_port_msgcount_t qlimit
)
892 assert(qlimit
<= MACH_PORT_QLIMIT_MAX
);
894 /* wake up senders allowed by the new qlimit */
897 if (qlimit
> mqueue
->imq_qlimit
) {
898 mach_port_msgcount_t i
, wakeup
;
900 /* caution: wakeup, qlimit are unsigned */
901 wakeup
= qlimit
- mqueue
->imq_qlimit
;
903 for (i
= 0; i
< wakeup
; i
++) {
904 if (wait_queue_wakeup64_one_locked(
905 &mqueue
->imq_wait_queue
,
908 FALSE
) == KERN_NOT_WAITING
) {
909 mqueue
->imq_fullwaiters
= FALSE
;
912 mqueue
->imq_msgcount
++; /* give it to the awakened thread */
915 mqueue
->imq_qlimit
= qlimit
;
921 * Routine: ipc_mqueue_set_seqno
923 * Changes an mqueue's sequence number.
925 * Caller holds a reference to the queue's containing object.
928 ipc_mqueue_set_seqno(
930 mach_port_seqno_t seqno
)
936 mqueue
->imq_seqno
= seqno
;
943 * Routine: ipc_mqueue_copyin
945 * Convert a name in a space to a message queue.
947 * Nothing locked. If successful, the caller gets a ref for
948 * for the object. This ref ensures the continued existence of
951 * MACH_MSG_SUCCESS Found a message queue.
952 * MACH_RCV_INVALID_NAME The space is dead.
953 * MACH_RCV_INVALID_NAME The name doesn't denote a right.
954 * MACH_RCV_INVALID_NAME
955 * The denoted right is not receive or port set.
956 * MACH_RCV_IN_SET Receive right is a member of a set.
962 mach_port_name_t name
,
963 ipc_mqueue_t
*mqueuep
,
964 ipc_object_t
*objectp
)
971 if (!space
->is_active
) {
972 is_read_unlock(space
);
973 return MACH_RCV_INVALID_NAME
;
976 entry
= ipc_entry_lookup(space
, name
);
977 if (entry
== IE_NULL
) {
978 is_read_unlock(space
);
979 return MACH_RCV_INVALID_NAME
;
982 object
= entry
->ie_object
;
984 if (entry
->ie_bits
& MACH_PORT_TYPE_RECEIVE
) {
987 port
= (ipc_port_t
) object
;
988 assert(port
!= IP_NULL
);
991 assert(ip_active(port
));
992 assert(port
->ip_receiver_name
== name
);
993 assert(port
->ip_receiver
== space
);
994 is_read_unlock(space
);
995 mqueue
= &port
->ip_messages
;
997 } else if (entry
->ie_bits
& MACH_PORT_TYPE_PORT_SET
) {
1000 pset
= (ipc_pset_t
) object
;
1001 assert(pset
!= IPS_NULL
);
1004 assert(ips_active(pset
));
1005 assert(pset
->ips_local_name
== name
);
1006 is_read_unlock(space
);
1008 mqueue
= &pset
->ips_messages
;
1010 is_read_unlock(space
);
1011 return MACH_RCV_INVALID_NAME
;
1015 * At this point, the object is locked and active,
1016 * the space is unlocked, and mqueue is initialized.
1019 io_reference(object
);
1024 return MACH_MSG_SUCCESS
;