2 * Copyright (c) 2000-2004 Apple Computer, 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 * @OSF_FREE_COPYRIGHT@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 * File: ipc/ipc_mqueue.c
63 * Functions to manipulate IPC message queues.
66 #include <mach/port.h>
67 #include <mach/message.h>
68 #include <mach/sync_policy.h>
70 #include <kern/assert.h>
71 #include <kern/counters.h>
72 #include <kern/sched_prim.h>
73 #include <kern/ipc_kobject.h>
74 #include <kern/ipc_mig.h> /* XXX - for mach_msg_receive_continue */
75 #include <kern/misc_protos.h>
76 #include <kern/task.h>
77 #include <kern/thread.h>
78 #include <kern/wait_queue.h>
80 #include <ipc/ipc_mqueue.h>
81 #include <ipc/ipc_kmsg.h>
82 #include <ipc/ipc_port.h>
83 #include <ipc/ipc_pset.h>
84 #include <ipc/ipc_space.h>
88 int ipc_mqueue_full
; /* address is event for queue space */
89 int ipc_mqueue_rcv
; /* address is event for message arrival */
93 /* forward declarations */
94 void ipc_mqueue_receive_results(wait_result_t result
);
97 * Routine: ipc_mqueue_init
99 * Initialize a newly-allocated message queue.
107 wait_queue_set_init(&mqueue
->imq_set_queue
, SYNC_POLICY_FIFO
);
109 wait_queue_init(&mqueue
->imq_wait_queue
, SYNC_POLICY_FIFO
);
110 ipc_kmsg_queue_init(&mqueue
->imq_messages
);
111 mqueue
->imq_seqno
= 0;
112 mqueue
->imq_msgcount
= 0;
113 mqueue
->imq_qlimit
= MACH_PORT_QLIMIT_DEFAULT
;
114 mqueue
->imq_fullwaiters
= FALSE
;
119 * Routine: ipc_mqueue_member
121 * Indicate whether the (port) mqueue is a member of
122 * this portset's mqueue. We do this by checking
123 * whether the portset mqueue's waitq is an member of
124 * the port's mqueue waitq.
126 * the portset's mqueue is not already a member
127 * this may block while allocating linkage structures.
132 ipc_mqueue_t port_mqueue
,
133 ipc_mqueue_t set_mqueue
)
135 wait_queue_t port_waitq
= &port_mqueue
->imq_wait_queue
;
136 wait_queue_set_t set_waitq
= &set_mqueue
->imq_set_queue
;
138 return (wait_queue_member(port_waitq
, set_waitq
));
143 * Routine: ipc_mqueue_remove
145 * Remove the association between the queue and the specified
152 ipc_mqueue_t set_mqueue
)
154 wait_queue_t mq_waitq
= &mqueue
->imq_wait_queue
;
155 wait_queue_set_t set_waitq
= &set_mqueue
->imq_set_queue
;
157 return wait_queue_unlink(mq_waitq
, set_waitq
);
161 * Routine: ipc_mqueue_remove_from_all
163 * Remove the mqueue from all the sets it is a member of
168 ipc_mqueue_remove_from_all(
171 wait_queue_t mq_waitq
= &mqueue
->imq_wait_queue
;
173 wait_queue_unlink_all(mq_waitq
);
178 * Routine: ipc_mqueue_remove_all
180 * Remove all the member queues from the specified set.
185 ipc_mqueue_remove_all(
188 wait_queue_set_t mq_setq
= &mqueue
->imq_set_queue
;
190 wait_queue_set_unlink_all(mq_setq
);
196 * Routine: ipc_mqueue_add
198 * Associate the portset's mqueue with the port's mqueue.
199 * This has to be done so that posting the port will wakeup
200 * a portset waiter. If there are waiters on the portset
201 * mqueue and messages on the port mqueue, try to match them
208 ipc_mqueue_t port_mqueue
,
209 ipc_mqueue_t set_mqueue
)
211 wait_queue_t port_waitq
= &port_mqueue
->imq_wait_queue
;
212 wait_queue_set_t set_waitq
= &set_mqueue
->imq_set_queue
;
213 ipc_kmsg_queue_t kmsgq
;
214 ipc_kmsg_t kmsg
, next
;
218 kr
= wait_queue_link(port_waitq
, set_waitq
);
219 if (kr
!= KERN_SUCCESS
)
223 * Now that the set has been added to the port, there may be
224 * messages queued on the port and threads waiting on the set
225 * waitq. Lets get them together.
228 imq_lock(port_mqueue
);
229 kmsgq
= &port_mqueue
->imq_messages
;
230 for (kmsg
= ipc_kmsg_queue_first(kmsgq
);
233 next
= ipc_kmsg_queue_next(kmsgq
, kmsg
);
238 th
= wait_queue_wakeup64_identity_locked(
243 /* waitq/mqueue still locked, thread locked */
245 if (th
== THREAD_NULL
)
249 * Found a receiver. see if they can handle the message
250 * correctly (the message is not too large for them, or
251 * they didn't care to be informed that the message was
252 * too large). If they can't handle it, take them off
253 * the list and let them go back and figure it out and
254 * just move onto the next.
257 kmsg
->ikm_header
->msgh_size
+
258 REQUESTED_TRAILER_SIZE(th
->ith_option
)) {
259 th
->ith_state
= MACH_RCV_TOO_LARGE
;
260 th
->ith_msize
= kmsg
->ikm_header
->msgh_size
;
261 if (th
->ith_option
& MACH_RCV_LARGE
) {
263 * let him go without message
265 th
->ith_kmsg
= IKM_NULL
;
268 continue; /* find another thread */
271 th
->ith_state
= MACH_MSG_SUCCESS
;
275 * This thread is going to take this message,
278 ipc_kmsg_rmqueue(kmsgq
, kmsg
);
279 ipc_mqueue_release_msgcount(port_mqueue
);
282 th
->ith_seqno
= port_mqueue
->imq_seqno
++;
284 break; /* go to next message */
289 imq_unlock(port_mqueue
);
295 * Routine: ipc_mqueue_changed
297 * Wake up receivers waiting in a message queue.
299 * The message queue is locked.
306 wait_queue_wakeup64_all_locked(
307 &mqueue
->imq_wait_queue
,
310 FALSE
); /* unlock waitq? */
317 * Routine: ipc_mqueue_send
319 * Send a message to a message queue. The message holds a reference
320 * for the destination port for this message queue in the
321 * msgh_remote_port field.
323 * If unsuccessful, the caller still has possession of
324 * the message and must do something with it. If successful,
325 * the message is queued, given to a receiver, or destroyed.
329 * MACH_MSG_SUCCESS The message was accepted.
330 * MACH_SEND_TIMED_OUT Caller still has message.
331 * MACH_SEND_INTERRUPTED Caller still has message.
337 mach_msg_option_t option
,
338 mach_msg_timeout_t send_timeout
)
345 * 1) We're under the queue limit.
346 * 2) Caller used the MACH_SEND_ALWAYS internal option.
347 * 3) Message is sent to a send-once right.
352 if (!imq_full(mqueue
) ||
353 (option
& MACH_SEND_ALWAYS
) ||
354 (MACH_MSGH_BITS_REMOTE(kmsg
->ikm_header
->msgh_bits
) ==
355 MACH_MSG_TYPE_PORT_SEND_ONCE
)) {
356 mqueue
->imq_msgcount
++;
357 assert(mqueue
->imq_msgcount
> 0);
361 thread_t cur_thread
= current_thread();
365 * We have to wait for space to be granted to us.
367 if ((option
& MACH_SEND_TIMEOUT
) && (send_timeout
== 0)) {
370 return MACH_SEND_TIMED_OUT
;
372 mqueue
->imq_fullwaiters
= TRUE
;
373 thread_lock(cur_thread
);
374 if (option
& MACH_SEND_TIMEOUT
)
375 clock_interval_to_deadline(send_timeout
, 1000*NSEC_PER_USEC
, &deadline
);
378 wresult
= wait_queue_assert_wait64_locked(
379 &mqueue
->imq_wait_queue
,
381 THREAD_ABORTSAFE
, deadline
,
383 thread_unlock(cur_thread
);
387 if (wresult
== THREAD_WAITING
) {
388 wresult
= thread_block(THREAD_CONTINUE_NULL
);
389 counter(c_ipc_mqueue_send_block
++);
393 case THREAD_TIMED_OUT
:
394 assert(option
& MACH_SEND_TIMEOUT
);
395 return MACH_SEND_TIMED_OUT
;
397 case THREAD_AWAKENED
:
398 /* we can proceed - inherited msgcount from waker */
399 assert(mqueue
->imq_msgcount
> 0);
402 case THREAD_INTERRUPTED
:
403 return MACH_SEND_INTERRUPTED
;
407 panic("ipc_mqueue_send");
411 ipc_mqueue_post(mqueue
, kmsg
);
412 return MACH_MSG_SUCCESS
;
416 * Routine: ipc_mqueue_release_msgcount
418 * Release a message queue reference in the case where we
422 * The message queue is locked.
423 * The message corresponding to this reference is off the queue.
426 ipc_mqueue_release_msgcount(
429 assert(imq_held(mqueue
));
430 assert(mqueue
->imq_msgcount
> 1 || ipc_kmsg_queue_empty(&mqueue
->imq_messages
));
432 mqueue
->imq_msgcount
--;
434 if (!imq_full(mqueue
) && mqueue
->imq_fullwaiters
) {
435 if (wait_queue_wakeup64_one_locked(
436 &mqueue
->imq_wait_queue
,
439 FALSE
) != KERN_SUCCESS
) {
440 mqueue
->imq_fullwaiters
= FALSE
;
442 /* gave away our slot - add reference back */
443 mqueue
->imq_msgcount
++;
449 * Routine: ipc_mqueue_post
451 * Post a message to a waiting receiver or enqueue it. If a
452 * receiver is waiting, we can release our reserved space in
456 * If we need to queue, our space in the message queue is reserved.
460 register ipc_mqueue_t mqueue
,
461 register ipc_kmsg_t kmsg
)
467 * While the msg queue is locked, we have control of the
468 * kmsg, so the ref in it for the port is still good.
470 * Check for a receiver for the message.
475 wait_queue_t waitq
= &mqueue
->imq_wait_queue
;
478 receiver
= wait_queue_wakeup64_identity_locked(
483 /* waitq still locked, thread locked */
485 if (receiver
== THREAD_NULL
) {
487 * no receivers; queue kmsg
489 assert(mqueue
->imq_msgcount
> 0);
490 ipc_kmsg_enqueue_macro(&mqueue
->imq_messages
, kmsg
);
495 * We found a waiting thread.
496 * If the message is too large or the scatter list is too small
497 * the thread we wake up will get that as its status.
499 if (receiver
->ith_msize
<
500 (kmsg
->ikm_header
->msgh_size
) +
501 REQUESTED_TRAILER_SIZE(receiver
->ith_option
)) {
502 receiver
->ith_msize
= kmsg
->ikm_header
->msgh_size
;
503 receiver
->ith_state
= MACH_RCV_TOO_LARGE
;
505 receiver
->ith_state
= MACH_MSG_SUCCESS
;
509 * If there is no problem with the upcoming receive, or the
510 * receiver thread didn't specifically ask for special too
511 * large error condition, go ahead and select it anyway.
513 if ((receiver
->ith_state
== MACH_MSG_SUCCESS
) ||
514 !(receiver
->ith_option
& MACH_RCV_LARGE
)) {
516 receiver
->ith_kmsg
= kmsg
;
517 receiver
->ith_seqno
= mqueue
->imq_seqno
++;
518 thread_unlock(receiver
);
520 /* we didn't need our reserved spot in the queue */
521 ipc_mqueue_release_msgcount(mqueue
);
526 * Otherwise, this thread needs to be released to run
527 * and handle its error without getting the message. We
528 * need to go back and pick another one.
530 receiver
->ith_kmsg
= IKM_NULL
;
531 receiver
->ith_seqno
= 0;
532 thread_unlock(receiver
);
538 current_task()->messages_sent
++;
544 ipc_mqueue_receive_results(wait_result_t saved_wait_result
)
546 thread_t self
= current_thread();
547 mach_msg_option_t option
= self
->ith_option
;
551 * why did we wake up?
553 switch (saved_wait_result
) {
554 case THREAD_TIMED_OUT
:
555 self
->ith_state
= MACH_RCV_TIMED_OUT
;
558 case THREAD_INTERRUPTED
:
559 self
->ith_state
= MACH_RCV_INTERRUPTED
;
563 /* something bad happened to the port/set */
564 self
->ith_state
= MACH_RCV_PORT_CHANGED
;
567 case THREAD_AWAKENED
:
569 * We do not need to go select a message, somebody
570 * handed us one (or a too-large indication).
572 mr
= MACH_MSG_SUCCESS
;
574 switch (self
->ith_state
) {
575 case MACH_RCV_SCATTER_SMALL
:
576 case MACH_RCV_TOO_LARGE
:
578 * Somebody tried to give us a too large
579 * message. If we indicated that we cared,
580 * then they only gave us the indication,
581 * otherwise they gave us the indication
582 * AND the message anyway.
584 if (option
& MACH_RCV_LARGE
) {
588 case MACH_MSG_SUCCESS
:
592 panic("ipc_mqueue_receive_results: strange ith_state");
596 panic("ipc_mqueue_receive_results: strange wait_result");
601 ipc_mqueue_receive_continue(
602 __unused
void *param
,
603 wait_result_t wresult
)
605 ipc_mqueue_receive_results(wresult
);
606 mach_msg_receive_continue(); /* hard-coded for now */
610 * Routine: ipc_mqueue_receive
612 * Receive a message from a message queue.
614 * If continuation is non-zero, then we might discard
615 * our kernel stack when we block. We will continue
616 * after unblocking by executing continuation.
618 * If resume is true, then we are resuming a receive
619 * operation after a blocked receive discarded our stack.
621 * Our caller must hold a reference for the port or port set
622 * to which this queue belongs, to keep the queue
623 * from being deallocated.
625 * The kmsg is returned with clean header fields
626 * and with the circular bit turned off.
628 * MACH_MSG_SUCCESS Message returned in kmsgp.
629 * MACH_RCV_TOO_LARGE Message size returned in kmsgp.
630 * MACH_RCV_TIMED_OUT No message obtained.
631 * MACH_RCV_INTERRUPTED No message obtained.
632 * MACH_RCV_PORT_DIED Port/set died; no message.
633 * MACH_RCV_PORT_CHANGED Port moved into set; no msg.
640 mach_msg_option_t option
,
641 mach_msg_size_t max_size
,
642 mach_msg_timeout_t rcv_timeout
,
645 ipc_kmsg_queue_t kmsgs
;
646 wait_result_t wresult
;
654 if (imq_is_set(mqueue
)) {
655 wait_queue_link_t wql
;
656 ipc_mqueue_t port_mq
;
659 q
= &mqueue
->imq_setlinks
;
662 * If we are waiting on a portset mqueue, we need to see if
663 * any of the member ports have work for us. If so, try to
664 * deliver one of those messages. By holding the portset's
665 * mqueue lock during the search, we tie up any attempts by
666 * mqueue_deliver or portset membership changes that may
667 * cross our path. But this is a lock order violation, so we
668 * have to do it "softly." If we don't find a message waiting
669 * for us, we will assert our intention to wait while still
670 * holding that lock. When we release the lock, the deliver/
671 * change will succeed and find us.
674 queue_iterate(q
, wql
, wait_queue_link_t
, wql_setlinks
) {
675 port_mq
= (ipc_mqueue_t
)wql
->wql_queue
;
676 kmsgs
= &port_mq
->imq_messages
;
678 if (!imq_lock_try(port_mq
)) {
684 goto search_set
; /* start again at beginning - SMP */
688 * If there is still a message to be had, we will
689 * try to select it (may not succeed because of size
690 * and options). In any case, we deliver those
691 * results back to the user.
693 * We also move the port's linkage to the tail of the
694 * list for this set (fairness). Future versions will
695 * sort by timestamp or priority.
697 if (ipc_kmsg_queue_first(kmsgs
) == IKM_NULL
) {
701 queue_remove(q
, wql
, wait_queue_link_t
, wql_setlinks
);
702 queue_enter(q
, wql
, wait_queue_link_t
, wql_setlinks
);
705 ipc_mqueue_select(port_mq
, option
, max_size
);
715 * Receive on a single port. Just try to get the messages.
717 kmsgs
= &mqueue
->imq_messages
;
718 if (ipc_kmsg_queue_first(kmsgs
) != IKM_NULL
) {
719 ipc_mqueue_select(mqueue
, option
, max_size
);
727 * Looks like we'll have to block. The mqueue we will
728 * block on (whether the set's or the local port's) is
731 self
= current_thread();
732 if (option
& MACH_RCV_TIMEOUT
) {
733 if (rcv_timeout
== 0) {
736 self
->ith_state
= MACH_RCV_TIMED_OUT
;
742 self
->ith_state
= MACH_RCV_IN_PROGRESS
;
743 self
->ith_option
= option
;
744 self
->ith_msize
= max_size
;
746 if (option
& MACH_RCV_TIMEOUT
)
747 clock_interval_to_deadline(rcv_timeout
, 1000*NSEC_PER_USEC
, &deadline
);
751 wresult
= wait_queue_assert_wait64_locked(&mqueue
->imq_wait_queue
,
753 interruptible
, deadline
,
759 if (wresult
== THREAD_WAITING
) {
760 counter((interruptible
== THREAD_ABORTSAFE
) ?
761 c_ipc_mqueue_receive_block_user
++ :
762 c_ipc_mqueue_receive_block_kernel
++);
764 if (self
->ith_continuation
)
765 thread_block(ipc_mqueue_receive_continue
);
768 wresult
= thread_block(THREAD_CONTINUE_NULL
);
770 ipc_mqueue_receive_results(wresult
);
775 * Routine: ipc_mqueue_select
777 * A receiver discovered that there was a message on the queue
778 * before he had to block. Pick the message off the queue and
779 * "post" it to himself.
782 * There is a message.
784 * MACH_MSG_SUCCESS Actually selected a message for ourselves.
785 * MACH_RCV_TOO_LARGE May or may not have pull it, but it is large
790 mach_msg_option_t option
,
791 mach_msg_size_t max_size
)
793 thread_t self
= current_thread();
795 mach_msg_return_t mr
;
796 mach_msg_size_t rcv_size
;
798 mr
= MACH_MSG_SUCCESS
;
802 * Do some sanity checking of our ability to receive
803 * before pulling the message off the queue.
805 kmsg
= ipc_kmsg_queue_first(&mqueue
->imq_messages
);
806 assert(kmsg
!= IKM_NULL
);
809 * If we really can't receive it, but we had the
810 * MACH_RCV_LARGE option set, then don't take it off
811 * the queue, instead return the appropriate error
814 rcv_size
= ipc_kmsg_copyout_size(kmsg
, self
->map
);
815 if (rcv_size
+ REQUESTED_TRAILER_SIZE(option
) > max_size
) {
816 mr
= MACH_RCV_TOO_LARGE
;
817 if (option
& MACH_RCV_LARGE
) {
818 self
->ith_kmsg
= IKM_NULL
;
819 self
->ith_msize
= rcv_size
;
821 self
->ith_state
= mr
;
826 ipc_kmsg_rmqueue_first_macro(&mqueue
->imq_messages
, kmsg
);
827 ipc_mqueue_release_msgcount(mqueue
);
828 self
->ith_seqno
= mqueue
->imq_seqno
++;
829 self
->ith_kmsg
= kmsg
;
830 self
->ith_state
= mr
;
832 current_task()->messages_received
++;
837 * Routine: ipc_mqueue_destroy
839 * Destroy a message queue. Set any blocked senders running.
840 * Destroy the kmsgs in the queue.
843 * Receivers were removed when the receive right was "changed"
849 ipc_kmsg_queue_t kmqueue
;
857 * rouse all blocked senders
859 mqueue
->imq_fullwaiters
= FALSE
;
860 wait_queue_wakeup64_all_locked(
861 &mqueue
->imq_wait_queue
,
866 kmqueue
= &mqueue
->imq_messages
;
868 while ((kmsg
= ipc_kmsg_dequeue(kmqueue
)) != IKM_NULL
) {
872 ipc_kmsg_destroy_dest(kmsg
);
882 * Routine: ipc_mqueue_set_qlimit
884 * Changes a message queue limit; the maximum number
885 * of messages which may be queued.
891 ipc_mqueue_set_qlimit(
893 mach_port_msgcount_t qlimit
)
897 assert(qlimit
<= MACH_PORT_QLIMIT_MAX
);
899 /* wake up senders allowed by the new qlimit */
902 if (qlimit
> mqueue
->imq_qlimit
) {
903 mach_port_msgcount_t i
, wakeup
;
905 /* caution: wakeup, qlimit are unsigned */
906 wakeup
= qlimit
- mqueue
->imq_qlimit
;
908 for (i
= 0; i
< wakeup
; i
++) {
909 if (wait_queue_wakeup64_one_locked(
910 &mqueue
->imq_wait_queue
,
913 FALSE
) == KERN_NOT_WAITING
) {
914 mqueue
->imq_fullwaiters
= FALSE
;
917 mqueue
->imq_msgcount
++; /* give it to the awakened thread */
920 mqueue
->imq_qlimit
= qlimit
;
926 * Routine: ipc_mqueue_set_seqno
928 * Changes an mqueue's sequence number.
930 * Caller holds a reference to the queue's containing object.
933 ipc_mqueue_set_seqno(
935 mach_port_seqno_t seqno
)
941 mqueue
->imq_seqno
= seqno
;
948 * Routine: ipc_mqueue_copyin
950 * Convert a name in a space to a message queue.
952 * Nothing locked. If successful, the caller gets a ref for
953 * for the object. This ref ensures the continued existence of
956 * MACH_MSG_SUCCESS Found a message queue.
957 * MACH_RCV_INVALID_NAME The space is dead.
958 * MACH_RCV_INVALID_NAME The name doesn't denote a right.
959 * MACH_RCV_INVALID_NAME
960 * The denoted right is not receive or port set.
961 * MACH_RCV_IN_SET Receive right is a member of a set.
967 mach_port_name_t name
,
968 ipc_mqueue_t
*mqueuep
,
969 ipc_object_t
*objectp
)
976 if (!space
->is_active
) {
977 is_read_unlock(space
);
978 return MACH_RCV_INVALID_NAME
;
981 entry
= ipc_entry_lookup(space
, name
);
982 if (entry
== IE_NULL
) {
983 is_read_unlock(space
);
984 return MACH_RCV_INVALID_NAME
;
987 object
= entry
->ie_object
;
989 if (entry
->ie_bits
& MACH_PORT_TYPE_RECEIVE
) {
992 port
= (ipc_port_t
) object
;
993 assert(port
!= IP_NULL
);
996 assert(ip_active(port
));
997 assert(port
->ip_receiver_name
== name
);
998 assert(port
->ip_receiver
== space
);
999 is_read_unlock(space
);
1000 mqueue
= &port
->ip_messages
;
1002 } else if (entry
->ie_bits
& MACH_PORT_TYPE_PORT_SET
) {
1005 pset
= (ipc_pset_t
) object
;
1006 assert(pset
!= IPS_NULL
);
1009 assert(ips_active(pset
));
1010 assert(pset
->ips_local_name
== name
);
1011 is_read_unlock(space
);
1013 mqueue
= &pset
->ips_messages
;
1015 is_read_unlock(space
);
1016 return MACH_RCV_INVALID_NAME
;
1020 * At this point, the object is locked and active,
1021 * the space is unlocked, and mqueue is initialized.
1024 io_reference(object
);
1029 return MACH_MSG_SUCCESS
;