2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_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.
56 * File: ipc/ipc_object.c
60 * Functions to manipulate IPC objects.
65 #include <mach/boolean.h>
66 #include <mach/kern_return.h>
67 #include <mach/port.h>
68 #include <mach/message.h>
69 #include <kern/misc_protos.h>
71 #include <ipc/ipc_space.h>
72 #include <ipc/ipc_entry.h>
73 #include <ipc/ipc_object.h>
74 #include <ipc/ipc_hash.h>
75 #include <ipc/ipc_right.h>
76 #include <ipc/ipc_notify.h>
77 #include <ipc/ipc_pset.h>
79 zone_t ipc_object_zones
[IOT_NUMBER
];
82 * Routine: ipc_object_reference
84 * Take a reference to an object.
92 assert(object
->io_references
> 0);
98 * Routine: ipc_object_release
100 * Release a reference to an object.
108 assert(object
->io_references
> 0);
110 io_check_unlock(object
);
114 * Routine: ipc_object_translate
116 * Look up an object in a space.
118 * Nothing locked before. If successful, the object
119 * is returned locked. The caller doesn't get a ref.
121 * KERN_SUCCESS Object returned locked.
122 * KERN_INVALID_TASK The space is dead.
123 * KERN_INVALID_NAME The name doesn't denote a right.
124 * KERN_INVALID_RIGHT Name doesn't denote the correct right.
128 ipc_object_translate(
130 mach_port_name_t name
,
131 mach_port_right_t right
,
132 ipc_object_t
*objectp
)
138 kr
= ipc_right_lookup_read(space
, name
, &entry
);
139 if (kr
!= KERN_SUCCESS
)
141 /* space is read-locked and active */
143 if ((entry
->ie_bits
& MACH_PORT_TYPE(right
)) == MACH_PORT_TYPE_NONE
) {
144 is_read_unlock(space
);
145 return KERN_INVALID_RIGHT
;
148 object
= entry
->ie_object
;
149 assert(object
!= IO_NULL
);
152 is_read_unlock(space
);
159 * Routine: ipc_object_translate_two
161 * Look up two objects in a space.
163 * Nothing locked before. If successful, the objects
164 * are returned locked. The caller doesn't get a ref.
166 * KERN_SUCCESS Objects returned locked.
167 * KERN_INVALID_TASK The space is dead.
168 * KERN_INVALID_NAME A name doesn't denote a right.
169 * KERN_INVALID_RIGHT A name doesn't denote the correct right.
173 ipc_object_translate_two(
175 mach_port_name_t name1
,
176 mach_port_right_t right1
,
177 ipc_object_t
*objectp1
,
178 mach_port_name_t name2
,
179 mach_port_right_t right2
,
180 ipc_object_t
*objectp2
)
187 kr
= ipc_right_lookup_two_read(space
, name1
, &entry1
, name2
, &entry2
);
188 if (kr
!= KERN_SUCCESS
)
190 /* space is read-locked and active */
192 if ((entry1
->ie_bits
& MACH_PORT_TYPE(right1
)) == MACH_PORT_TYPE_NONE
) {
193 is_read_unlock(space
);
194 return KERN_INVALID_RIGHT
;
197 if ((entry2
->ie_bits
& MACH_PORT_TYPE(right2
)) == MACH_PORT_TYPE_NONE
) {
198 is_read_unlock(space
);
199 return KERN_INVALID_RIGHT
;
202 object
= entry1
->ie_object
;
203 assert(object
!= IO_NULL
);
207 object
= entry2
->ie_object
;
208 assert(object
!= IO_NULL
);
212 is_read_unlock(space
);
217 * Routine: ipc_object_alloc_dead
219 * Allocate a dead-name entry.
223 * KERN_SUCCESS The dead name is allocated.
224 * KERN_INVALID_TASK The space is dead.
225 * KERN_NO_SPACE No room for an entry in the space.
226 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
230 ipc_object_alloc_dead(
232 mach_port_name_t
*namep
)
240 kr
= ipc_entry_alloc(space
, namep
, &entry
);
241 if (kr
!= KERN_SUCCESS
)
243 /* space is write-locked */
245 /* null object, MACH_PORT_TYPE_DEAD_NAME, 1 uref */
247 assert(entry
->ie_object
== IO_NULL
);
248 entry
->ie_bits
|= MACH_PORT_TYPE_DEAD_NAME
| 1;
250 is_write_unlock(space
);
255 * Routine: ipc_object_alloc_dead_name
257 * Allocate a dead-name entry, with a specific name.
261 * KERN_SUCCESS The dead name is allocated.
262 * KERN_INVALID_TASK The space is dead.
263 * KERN_NAME_EXISTS The name already denotes a right.
264 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
268 ipc_object_alloc_dead_name(
270 mach_port_name_t name
)
278 kr
= ipc_entry_alloc_name(space
, name
, &entry
);
279 if (kr
!= KERN_SUCCESS
)
281 /* space is write-locked */
283 if (ipc_right_inuse(space
, name
, entry
))
284 return KERN_NAME_EXISTS
;
286 /* null object, MACH_PORT_TYPE_DEAD_NAME, 1 uref */
288 assert(entry
->ie_object
== IO_NULL
);
289 entry
->ie_bits
|= MACH_PORT_TYPE_DEAD_NAME
| 1;
291 is_write_unlock(space
);
296 * Routine: ipc_object_alloc
298 * Allocate an object.
300 * Nothing locked. If successful, the object is returned locked.
301 * The caller doesn't get a reference for the object.
303 * KERN_SUCCESS The object is allocated.
304 * KERN_INVALID_TASK The space is dead.
305 * KERN_NO_SPACE No room for an entry in the space.
306 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
312 ipc_object_type_t otype
,
313 mach_port_type_t type
,
314 mach_port_urefs_t urefs
,
315 mach_port_name_t
*namep
,
316 ipc_object_t
*objectp
)
322 assert(otype
< IOT_NUMBER
);
323 assert((type
& MACH_PORT_TYPE_ALL_RIGHTS
) == type
);
324 assert(type
!= MACH_PORT_TYPE_NONE
);
325 assert(urefs
<= MACH_PORT_UREFS_MAX
);
327 object
= io_alloc(otype
);
328 if (object
== IO_NULL
)
329 return KERN_RESOURCE_SHORTAGE
;
331 if (otype
== IOT_PORT
) {
332 ipc_port_t port
= (ipc_port_t
)object
;
334 bzero((char *)port
, sizeof(*port
));
335 } else if (otype
== IOT_PORT_SET
) {
336 ipc_pset_t pset
= (ipc_pset_t
)object
;
338 bzero((char *)pset
, sizeof(*pset
));
341 io_lock_init(object
);
342 *namep
= (mach_port_name_t
)object
;
343 kr
= ipc_entry_alloc(space
, namep
, &entry
);
344 if (kr
!= KERN_SUCCESS
) {
345 io_free(otype
, object
);
348 /* space is write-locked */
350 entry
->ie_bits
|= type
| urefs
;
351 entry
->ie_object
= object
;
354 is_write_unlock(space
);
356 object
->io_references
= 1; /* for entry, not caller */
357 object
->io_bits
= io_makebits(TRUE
, otype
, 0);
364 * Routine: ipc_object_alloc_name
366 * Allocate an object, with a specific name.
368 * Nothing locked. If successful, the object is returned locked.
369 * The caller doesn't get a reference for the object.
371 * KERN_SUCCESS The object is allocated.
372 * KERN_INVALID_TASK The space is dead.
373 * KERN_NAME_EXISTS The name already denotes a right.
374 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
378 ipc_object_alloc_name(
380 ipc_object_type_t otype
,
381 mach_port_type_t type
,
382 mach_port_urefs_t urefs
,
383 mach_port_name_t name
,
384 ipc_object_t
*objectp
)
390 assert(otype
< IOT_NUMBER
);
391 assert((type
& MACH_PORT_TYPE_ALL_RIGHTS
) == type
);
392 assert(type
!= MACH_PORT_TYPE_NONE
);
393 assert(urefs
<= MACH_PORT_UREFS_MAX
);
395 object
= io_alloc(otype
);
396 if (object
== IO_NULL
)
397 return KERN_RESOURCE_SHORTAGE
;
399 if (otype
== IOT_PORT
) {
400 ipc_port_t port
= (ipc_port_t
)object
;
402 bzero((char *)port
, sizeof(*port
));
403 } else if (otype
== IOT_PORT_SET
) {
404 ipc_pset_t pset
= (ipc_pset_t
)object
;
406 bzero((char *)pset
, sizeof(*pset
));
409 io_lock_init(object
);
410 kr
= ipc_entry_alloc_name(space
, name
, &entry
);
411 if (kr
!= KERN_SUCCESS
) {
412 io_free(otype
, object
);
415 /* space is write-locked */
417 if (ipc_right_inuse(space
, name
, entry
)) {
418 io_free(otype
, object
);
419 return KERN_NAME_EXISTS
;
422 entry
->ie_bits
|= type
| urefs
;
423 entry
->ie_object
= object
;
426 is_write_unlock(space
);
428 object
->io_references
= 1; /* for entry, not caller */
429 object
->io_bits
= io_makebits(TRUE
, otype
, 0);
436 * Routine: ipc_object_copyin_type
438 * Convert a send type name to a received type name.
442 ipc_object_copyin_type(
443 mach_msg_type_name_t msgt_name
)
447 case MACH_MSG_TYPE_MOVE_RECEIVE
:
448 case MACH_MSG_TYPE_COPY_RECEIVE
:
449 return MACH_MSG_TYPE_PORT_RECEIVE
;
451 case MACH_MSG_TYPE_MOVE_SEND_ONCE
:
452 case MACH_MSG_TYPE_MAKE_SEND_ONCE
:
453 return MACH_MSG_TYPE_PORT_SEND_ONCE
;
455 case MACH_MSG_TYPE_MOVE_SEND
:
456 case MACH_MSG_TYPE_MAKE_SEND
:
457 case MACH_MSG_TYPE_COPY_SEND
:
458 return MACH_MSG_TYPE_PORT_SEND
;
461 return MACH_MSG_TYPE_PORT_NONE
;
466 * Routine: ipc_object_copyin
468 * Copyin a capability from a space.
469 * If successful, the caller gets a ref
470 * for the resulting object, unless it is IO_DEAD.
474 * KERN_SUCCESS Acquired an object, possibly IO_DEAD.
475 * KERN_INVALID_TASK The space is dead.
476 * KERN_INVALID_NAME Name doesn't exist in space.
477 * KERN_INVALID_RIGHT Name doesn't denote correct right.
483 mach_port_name_t name
,
484 mach_msg_type_name_t msgt_name
,
485 ipc_object_t
*objectp
)
494 * Could first try a read lock when doing
495 * MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND,
496 * and MACH_MSG_TYPE_MAKE_SEND_ONCE.
499 kr
= ipc_right_lookup_write(space
, name
, &entry
);
500 if (kr
!= KERN_SUCCESS
)
502 /* space is write-locked and active */
504 kr
= ipc_right_copyin(space
, name
, entry
,
507 if (IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
)
508 ipc_entry_dealloc(space
, name
, entry
);
509 is_write_unlock(space
);
511 if ((kr
== KERN_SUCCESS
) && (soright
!= IP_NULL
))
512 ipc_notify_port_deleted(soright
, name
);
518 * Routine: ipc_object_copyin_from_kernel
520 * Copyin a naked capability from the kernel.
522 * MACH_MSG_TYPE_MOVE_RECEIVE
523 * The receiver must be ipc_space_kernel.
524 * Consumes the naked receive right.
525 * MACH_MSG_TYPE_COPY_SEND
526 * A naked send right must be supplied.
527 * The port gains a reference, and a send right
528 * if the port is still active.
529 * MACH_MSG_TYPE_MAKE_SEND
530 * The receiver must be ipc_space_kernel.
531 * The port gains a reference and a send right.
532 * MACH_MSG_TYPE_MOVE_SEND
533 * Consumes a naked send right.
534 * MACH_MSG_TYPE_MAKE_SEND_ONCE
535 * The port gains a reference and a send-once right.
536 * Receiver also be the caller of device subsystem,
538 * MACH_MSG_TYPE_MOVE_SEND_ONCE
539 * Consumes a naked send-once right.
545 ipc_object_copyin_from_kernel(
547 mach_msg_type_name_t msgt_name
)
549 assert(IO_VALID(object
));
552 case MACH_MSG_TYPE_MOVE_RECEIVE
: {
553 ipc_port_t port
= (ipc_port_t
) object
;
556 assert(ip_active(port
));
557 assert(port
->ip_receiver_name
!= MACH_PORT_NULL
);
558 assert(port
->ip_receiver
== ipc_space_kernel
);
560 /* relevant part of ipc_port_clear_receiver */
561 ipc_port_set_mscount(port
, 0);
563 port
->ip_receiver_name
= MACH_PORT_NULL
;
564 port
->ip_destination
= IP_NULL
;
569 case MACH_MSG_TYPE_COPY_SEND
: {
570 ipc_port_t port
= (ipc_port_t
) object
;
573 if (ip_active(port
)) {
574 assert(port
->ip_srights
> 0);
582 case MACH_MSG_TYPE_MAKE_SEND
: {
583 ipc_port_t port
= (ipc_port_t
) object
;
586 assert(ip_active(port
));
587 assert(port
->ip_receiver_name
!= MACH_PORT_NULL
);
588 assert(port
->ip_receiver
== ipc_space_kernel
);
597 case MACH_MSG_TYPE_MOVE_SEND
:
598 /* move naked send right into the message */
601 case MACH_MSG_TYPE_MAKE_SEND_ONCE
: {
602 ipc_port_t port
= (ipc_port_t
) object
;
605 assert(ip_active(port
));
606 assert(port
->ip_receiver_name
!= MACH_PORT_NULL
);
614 case MACH_MSG_TYPE_MOVE_SEND_ONCE
:
615 /* move naked send-once right into the message */
619 panic("ipc_object_copyin_from_kernel: strange rights");
624 * Routine: ipc_object_destroy
626 * Destroys a naked capability.
627 * Consumes a ref for the object.
629 * A receive right should be in limbo or in transit.
637 mach_msg_type_name_t msgt_name
)
639 assert(IO_VALID(object
));
640 assert(io_otype(object
) == IOT_PORT
);
643 case MACH_MSG_TYPE_PORT_SEND
:
644 ipc_port_release_send((ipc_port_t
) object
);
647 case MACH_MSG_TYPE_PORT_SEND_ONCE
:
648 ipc_notify_send_once((ipc_port_t
) object
);
651 case MACH_MSG_TYPE_PORT_RECEIVE
:
652 ipc_port_release_receive((ipc_port_t
) object
);
656 panic("ipc_object_destroy: strange rights");
661 * Routine: ipc_object_copyout
663 * Copyout a capability, placing it into a space.
664 * If successful, consumes a ref for the object.
668 * KERN_SUCCESS Copied out object, consumed ref.
669 * KERN_INVALID_TASK The space is dead.
670 * KERN_INVALID_CAPABILITY The object is dead.
671 * KERN_NO_SPACE No room in space for another right.
672 * KERN_RESOURCE_SHORTAGE No memory available.
673 * KERN_UREFS_OVERFLOW Urefs limit exceeded
674 * and overflow wasn't specified.
681 mach_msg_type_name_t msgt_name
,
683 mach_port_name_t
*namep
)
685 mach_port_name_t name
;
689 assert(IO_VALID(object
));
690 assert(io_otype(object
) == IOT_PORT
);
692 is_write_lock(space
);
695 if (!space
->is_active
) {
696 is_write_unlock(space
);
697 return KERN_INVALID_TASK
;
700 if ((msgt_name
!= MACH_MSG_TYPE_PORT_SEND_ONCE
) &&
701 ipc_right_reverse(space
, object
, &name
, &entry
)) {
702 /* object is locked and active */
704 assert(entry
->ie_bits
& MACH_PORT_TYPE_SEND_RECEIVE
);
708 name
= (mach_port_name_t
)object
;
709 kr
= ipc_entry_get(space
, &name
, &entry
);
710 if (kr
!= KERN_SUCCESS
) {
711 /* unlocks/locks space, so must start again */
713 kr
= ipc_entry_grow_table(space
, ITS_SIZE_NONE
);
714 if (kr
!= KERN_SUCCESS
)
715 return kr
; /* space is unlocked */
720 assert(IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
);
721 assert(entry
->ie_object
== IO_NULL
);
724 if (!io_active(object
)) {
726 ipc_entry_dealloc(space
, name
, entry
);
727 is_write_unlock(space
);
728 return KERN_INVALID_CAPABILITY
;
731 entry
->ie_object
= object
;
735 /* space is write-locked and active, object is locked and active */
737 kr
= ipc_right_copyout(space
, name
, entry
,
738 msgt_name
, overflow
, object
);
739 /* object is unlocked */
740 is_write_unlock(space
);
742 if (kr
== KERN_SUCCESS
)
748 * Routine: ipc_object_copyout_name
750 * Copyout a capability, placing it into a space.
751 * The specified name is used for the capability.
752 * If successful, consumes a ref for the object.
756 * KERN_SUCCESS Copied out object, consumed ref.
757 * KERN_INVALID_TASK The space is dead.
758 * KERN_INVALID_CAPABILITY The object is dead.
759 * KERN_RESOURCE_SHORTAGE No memory available.
760 * KERN_UREFS_OVERFLOW Urefs limit exceeded
761 * and overflow wasn't specified.
762 * KERN_RIGHT_EXISTS Space has rights under another name.
763 * KERN_NAME_EXISTS Name is already used.
767 ipc_object_copyout_name(
770 mach_msg_type_name_t msgt_name
,
772 mach_port_name_t name
)
774 mach_port_name_t oname
;
781 assert(IO_VALID(object
));
782 assert(io_otype(object
) == IOT_PORT
);
784 kr
= ipc_entry_alloc_name(space
, name
, &entry
);
785 if (kr
!= KERN_SUCCESS
)
787 /* space is write-locked and active */
789 if ((msgt_name
!= MACH_MSG_TYPE_PORT_SEND_ONCE
) &&
790 ipc_right_reverse(space
, object
, &oname
, &oentry
)) {
791 /* object is locked and active */
796 if (IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
)
797 ipc_entry_dealloc(space
, name
, entry
);
799 is_write_unlock(space
);
800 return KERN_RIGHT_EXISTS
;
803 assert(entry
== oentry
);
804 assert(entry
->ie_bits
& MACH_PORT_TYPE_SEND_RECEIVE
);
806 if (ipc_right_inuse(space
, name
, entry
))
807 return KERN_NAME_EXISTS
;
809 assert(IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
);
810 assert(entry
->ie_object
== IO_NULL
);
813 if (!io_active(object
)) {
815 ipc_entry_dealloc(space
, name
, entry
);
816 is_write_unlock(space
);
817 return KERN_INVALID_CAPABILITY
;
820 entry
->ie_object
= object
;
823 /* space is write-locked and active, object is locked and active */
825 kr
= ipc_right_copyout(space
, name
, entry
,
826 msgt_name
, overflow
, object
);
827 /* object is unlocked */
828 is_write_unlock(space
);
833 * Routine: ipc_object_copyout_dest
835 * Translates/consumes the destination right of a message.
836 * This is unlike normal copyout because the right is consumed
837 * in a funny way instead of being given to the receiving space.
838 * The receiver gets his name for the port, if he has receive
839 * rights, otherwise MACH_PORT_NULL.
841 * The object is locked and active. Nothing else locked.
842 * The object is unlocked and loses a reference.
846 ipc_object_copyout_dest(
849 mach_msg_type_name_t msgt_name
,
850 mach_port_name_t
*namep
)
852 mach_port_name_t name
;
854 assert(IO_VALID(object
));
855 assert(io_active(object
));
860 * If the space is the receiver/owner of the object,
861 * then we quietly consume the right and return
862 * the space's name for the object. Otherwise
863 * we destroy the right and return MACH_PORT_NULL.
867 case MACH_MSG_TYPE_PORT_SEND
: {
868 ipc_port_t port
= (ipc_port_t
) object
;
869 ipc_port_t nsrequest
= IP_NULL
;
870 mach_port_mscount_t mscount
;
872 if (port
->ip_receiver
== space
)
873 name
= port
->ip_receiver_name
;
875 name
= MACH_PORT_NULL
;
877 assert(port
->ip_srights
> 0);
878 if (--port
->ip_srights
== 0 &&
879 port
->ip_nsrequest
!= IP_NULL
) {
880 nsrequest
= port
->ip_nsrequest
;
881 port
->ip_nsrequest
= IP_NULL
;
882 mscount
= port
->ip_mscount
;
884 ipc_notify_no_senders(nsrequest
, mscount
);
890 case MACH_MSG_TYPE_PORT_SEND_ONCE
: {
891 ipc_port_t port
= (ipc_port_t
) object
;
893 assert(port
->ip_sorights
> 0);
895 if (port
->ip_receiver
== space
) {
896 /* quietly consume the send-once right */
899 name
= port
->ip_receiver_name
;
903 * A very bizarre case. The message
904 * was received, but before this copyout
905 * happened the space lost receive rights.
906 * We can't quietly consume the soright
907 * out from underneath some other task,
908 * so generate a send-once notification.
911 ip_reference(port
); /* restore ref */
914 ipc_notify_send_once(port
);
915 name
= MACH_PORT_NULL
;
922 panic("ipc_object_copyout_dest: strange rights");
929 * Routine: ipc_object_rename
931 * Rename an entry in a space.
935 * KERN_SUCCESS Renamed the entry.
936 * KERN_INVALID_TASK The space was dead.
937 * KERN_INVALID_NAME oname didn't denote an entry.
938 * KERN_NAME_EXISTS nname already denoted an entry.
939 * KERN_RESOURCE_SHORTAGE Couldn't allocate new entry.
945 mach_port_name_t oname
,
946 mach_port_name_t nname
)
948 ipc_entry_t oentry
, nentry
;
953 kr
= ipc_entry_alloc_name(space
, nname
, &nentry
);
954 if (kr
!= KERN_SUCCESS
)
957 /* space is write-locked and active */
959 if (ipc_right_inuse(space
, nname
, nentry
)) {
960 /* space is unlocked */
961 return KERN_NAME_EXISTS
;
964 /* don't let ipc_entry_lookup see the uninitialized new entry */
966 if ((oname
== nname
) ||
967 ((oentry
= ipc_entry_lookup(space
, oname
)) == IE_NULL
)) {
968 ipc_entry_dealloc(space
, nname
, nentry
);
969 is_write_unlock(space
);
970 return KERN_INVALID_NAME
;
973 kr
= ipc_right_rename(space
, oname
, oentry
, nname
, nentry
);
974 /* space is unlocked */
980 * Check whether the object is a port if so, free it. But
981 * keep track of that fact.
990 if (otype
== IOT_PORT
) {
991 port
= (ipc_port_t
) object
;
993 ipc_port_track_dealloc(port
);
994 #endif /* MACH_ASSERT */
996 zfree(ipc_object_zones
[otype
], (vm_offset_t
) object
);
998 #endif /* MACH_ASSERT */
1000 #include <mach_kdb.h>
1003 #include <ddb/db_output.h>
1005 #define printf kdbprintf
1008 * Routine: ipc_object_print
1010 * Pretty-print an object for kdb.
1013 char *ikot_print_array
[IKOT_MAX_TYPE
] = {
1024 "(DEVICE) ", /* 10 */
1034 "(ACTIVATION) ", /* 20 */
1040 "(CLOCK_CTRL) ", /* 26 */
1041 "(IOKIT_SPARE) ", /* 27 */
1042 "(NAMED_MEM_ENTRY) ", /* 28 */
1044 "(IOKIT_OBJECT) ", /* 30 */
1046 /* << new entries here */
1047 "(UNKNOWN) " /* magic catchall */
1049 /* Please keep in sync with kern/ipc_kobject.h */
1053 ipc_object_t object
)
1057 iprintf("%s", io_active(object
) ? "active" : "dead");
1058 printf(", refs=%d", object
->io_references
);
1059 printf(", otype=%d", io_otype(object
));
1060 kotype
= io_kotype(object
);
1061 if (kotype
>= 0 && kotype
< IKOT_MAX_TYPE
)
1062 printf(", kotype=%d %s\n", io_kotype(object
),
1063 ikot_print_array
[kotype
]);
1065 printf(", kotype=0x%x %s\n", io_kotype(object
),
1066 ikot_print_array
[IKOT_UNKNOWN
]);
1069 #endif /* MACH_KDB */