2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * File: ipc/ipc_object.c
57 * Functions to manipulate IPC objects.
62 #include <mach/boolean.h>
63 #include <mach/kern_return.h>
64 #include <mach/port.h>
65 #include <mach/message.h>
66 #include <kern/misc_protos.h>
68 #include <ipc/ipc_space.h>
69 #include <ipc/ipc_entry.h>
70 #include <ipc/ipc_object.h>
71 #include <ipc/ipc_hash.h>
72 #include <ipc/ipc_right.h>
73 #include <ipc/ipc_notify.h>
74 #include <ipc/ipc_pset.h>
76 zone_t ipc_object_zones
[IOT_NUMBER
];
79 * Routine: ipc_object_reference
81 * Take a reference to an object.
89 assert(object
->io_references
> 0);
95 * Routine: ipc_object_release
97 * Release a reference to an object.
105 assert(object
->io_references
> 0);
107 io_check_unlock(object
);
111 * Routine: ipc_object_translate
113 * Look up an object in a space.
115 * Nothing locked before. If successful, the object
116 * is returned locked. The caller doesn't get a ref.
118 * KERN_SUCCESS Object returned locked.
119 * KERN_INVALID_TASK The space is dead.
120 * KERN_INVALID_NAME The name doesn't denote a right.
121 * KERN_INVALID_RIGHT Name doesn't denote the correct right.
125 ipc_object_translate(
127 mach_port_name_t name
,
128 mach_port_right_t right
,
129 ipc_object_t
*objectp
)
135 kr
= ipc_right_lookup_read(space
, name
, &entry
);
136 if (kr
!= KERN_SUCCESS
)
138 /* space is read-locked and active */
140 if ((entry
->ie_bits
& MACH_PORT_TYPE(right
)) == MACH_PORT_TYPE_NONE
) {
141 is_read_unlock(space
);
142 return KERN_INVALID_RIGHT
;
145 object
= entry
->ie_object
;
146 assert(object
!= IO_NULL
);
149 is_read_unlock(space
);
156 * Routine: ipc_object_translate_two
158 * Look up two objects in a space.
160 * Nothing locked before. If successful, the objects
161 * are returned locked. The caller doesn't get a ref.
163 * KERN_SUCCESS Objects returned locked.
164 * KERN_INVALID_TASK The space is dead.
165 * KERN_INVALID_NAME A name doesn't denote a right.
166 * KERN_INVALID_RIGHT A name doesn't denote the correct right.
170 ipc_object_translate_two(
172 mach_port_name_t name1
,
173 mach_port_right_t right1
,
174 ipc_object_t
*objectp1
,
175 mach_port_name_t name2
,
176 mach_port_right_t right2
,
177 ipc_object_t
*objectp2
)
184 kr
= ipc_right_lookup_two_read(space
, name1
, &entry1
, name2
, &entry2
);
185 if (kr
!= KERN_SUCCESS
)
187 /* space is read-locked and active */
189 if ((entry1
->ie_bits
& MACH_PORT_TYPE(right1
)) == MACH_PORT_TYPE_NONE
) {
190 is_read_unlock(space
);
191 return KERN_INVALID_RIGHT
;
194 if ((entry2
->ie_bits
& MACH_PORT_TYPE(right2
)) == MACH_PORT_TYPE_NONE
) {
195 is_read_unlock(space
);
196 return KERN_INVALID_RIGHT
;
199 object
= entry1
->ie_object
;
200 assert(object
!= IO_NULL
);
204 object
= entry2
->ie_object
;
205 assert(object
!= IO_NULL
);
209 is_read_unlock(space
);
214 * Routine: ipc_object_alloc_dead
216 * Allocate a dead-name entry.
220 * KERN_SUCCESS The dead name is allocated.
221 * KERN_INVALID_TASK The space is dead.
222 * KERN_NO_SPACE No room for an entry in the space.
223 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
227 ipc_object_alloc_dead(
229 mach_port_name_t
*namep
)
237 kr
= ipc_entry_alloc(space
, namep
, &entry
);
238 if (kr
!= KERN_SUCCESS
)
240 /* space is write-locked */
242 /* null object, MACH_PORT_TYPE_DEAD_NAME, 1 uref */
244 assert(entry
->ie_object
== IO_NULL
);
245 entry
->ie_bits
|= MACH_PORT_TYPE_DEAD_NAME
| 1;
247 is_write_unlock(space
);
252 * Routine: ipc_object_alloc_dead_name
254 * Allocate a dead-name entry, with a specific name.
258 * KERN_SUCCESS The dead name is allocated.
259 * KERN_INVALID_TASK The space is dead.
260 * KERN_NAME_EXISTS The name already denotes a right.
261 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
265 ipc_object_alloc_dead_name(
267 mach_port_name_t name
)
275 kr
= ipc_entry_alloc_name(space
, name
, &entry
);
276 if (kr
!= KERN_SUCCESS
)
278 /* space is write-locked */
280 if (ipc_right_inuse(space
, name
, entry
))
281 return KERN_NAME_EXISTS
;
283 /* null object, MACH_PORT_TYPE_DEAD_NAME, 1 uref */
285 assert(entry
->ie_object
== IO_NULL
);
286 entry
->ie_bits
|= MACH_PORT_TYPE_DEAD_NAME
| 1;
288 is_write_unlock(space
);
293 * Routine: ipc_object_alloc
295 * Allocate an object.
297 * Nothing locked. If successful, the object is returned locked.
298 * The caller doesn't get a reference for the object.
300 * KERN_SUCCESS The object is allocated.
301 * KERN_INVALID_TASK The space is dead.
302 * KERN_NO_SPACE No room for an entry in the space.
303 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
309 ipc_object_type_t otype
,
310 mach_port_type_t type
,
311 mach_port_urefs_t urefs
,
312 mach_port_name_t
*namep
,
313 ipc_object_t
*objectp
)
319 assert(otype
< IOT_NUMBER
);
320 assert((type
& MACH_PORT_TYPE_ALL_RIGHTS
) == type
);
321 assert(type
!= MACH_PORT_TYPE_NONE
);
322 assert(urefs
<= MACH_PORT_UREFS_MAX
);
324 object
= io_alloc(otype
);
325 if (object
== IO_NULL
)
326 return KERN_RESOURCE_SHORTAGE
;
328 if (otype
== IOT_PORT
) {
329 ipc_port_t port
= (ipc_port_t
)object
;
331 bzero((char *)port
, sizeof(*port
));
332 } else if (otype
== IOT_PORT_SET
) {
333 ipc_pset_t pset
= (ipc_pset_t
)object
;
335 bzero((char *)pset
, sizeof(*pset
));
338 io_lock_init(object
);
339 *namep
= (mach_port_name_t
)object
;
340 kr
= ipc_entry_alloc(space
, namep
, &entry
);
341 if (kr
!= KERN_SUCCESS
) {
342 io_free(otype
, object
);
345 /* space is write-locked */
347 entry
->ie_bits
|= type
| urefs
;
348 entry
->ie_object
= object
;
351 is_write_unlock(space
);
353 object
->io_references
= 1; /* for entry, not caller */
354 object
->io_bits
= io_makebits(TRUE
, otype
, 0);
361 * Routine: ipc_object_alloc_name
363 * Allocate an object, with a specific name.
365 * Nothing locked. If successful, the object is returned locked.
366 * The caller doesn't get a reference for the object.
368 * KERN_SUCCESS The object is allocated.
369 * KERN_INVALID_TASK The space is dead.
370 * KERN_NAME_EXISTS The name already denotes a right.
371 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
375 ipc_object_alloc_name(
377 ipc_object_type_t otype
,
378 mach_port_type_t type
,
379 mach_port_urefs_t urefs
,
380 mach_port_name_t name
,
381 ipc_object_t
*objectp
)
387 assert(otype
< IOT_NUMBER
);
388 assert((type
& MACH_PORT_TYPE_ALL_RIGHTS
) == type
);
389 assert(type
!= MACH_PORT_TYPE_NONE
);
390 assert(urefs
<= MACH_PORT_UREFS_MAX
);
392 object
= io_alloc(otype
);
393 if (object
== IO_NULL
)
394 return KERN_RESOURCE_SHORTAGE
;
396 if (otype
== IOT_PORT
) {
397 ipc_port_t port
= (ipc_port_t
)object
;
399 bzero((char *)port
, sizeof(*port
));
400 } else if (otype
== IOT_PORT_SET
) {
401 ipc_pset_t pset
= (ipc_pset_t
)object
;
403 bzero((char *)pset
, sizeof(*pset
));
406 io_lock_init(object
);
407 kr
= ipc_entry_alloc_name(space
, name
, &entry
);
408 if (kr
!= KERN_SUCCESS
) {
409 io_free(otype
, object
);
412 /* space is write-locked */
414 if (ipc_right_inuse(space
, name
, entry
)) {
415 io_free(otype
, object
);
416 return KERN_NAME_EXISTS
;
419 entry
->ie_bits
|= type
| urefs
;
420 entry
->ie_object
= object
;
423 is_write_unlock(space
);
425 object
->io_references
= 1; /* for entry, not caller */
426 object
->io_bits
= io_makebits(TRUE
, otype
, 0);
433 * Routine: ipc_object_copyin_type
435 * Convert a send type name to a received type name.
439 ipc_object_copyin_type(
440 mach_msg_type_name_t msgt_name
)
444 case MACH_MSG_TYPE_MOVE_RECEIVE
:
445 case MACH_MSG_TYPE_COPY_RECEIVE
:
446 return MACH_MSG_TYPE_PORT_RECEIVE
;
448 case MACH_MSG_TYPE_MOVE_SEND_ONCE
:
449 case MACH_MSG_TYPE_MAKE_SEND_ONCE
:
450 return MACH_MSG_TYPE_PORT_SEND_ONCE
;
452 case MACH_MSG_TYPE_MOVE_SEND
:
453 case MACH_MSG_TYPE_MAKE_SEND
:
454 case MACH_MSG_TYPE_COPY_SEND
:
455 return MACH_MSG_TYPE_PORT_SEND
;
458 return MACH_MSG_TYPE_PORT_NONE
;
463 * Routine: ipc_object_copyin
465 * Copyin a capability from a space.
466 * If successful, the caller gets a ref
467 * for the resulting object, unless it is IO_DEAD.
471 * KERN_SUCCESS Acquired an object, possibly IO_DEAD.
472 * KERN_INVALID_TASK The space is dead.
473 * KERN_INVALID_NAME Name doesn't exist in space.
474 * KERN_INVALID_RIGHT Name doesn't denote correct right.
480 mach_port_name_t name
,
481 mach_msg_type_name_t msgt_name
,
482 ipc_object_t
*objectp
)
491 * Could first try a read lock when doing
492 * MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND,
493 * and MACH_MSG_TYPE_MAKE_SEND_ONCE.
496 kr
= ipc_right_lookup_write(space
, name
, &entry
);
497 if (kr
!= KERN_SUCCESS
)
499 /* space is write-locked and active */
501 kr
= ipc_right_copyin(space
, name
, entry
,
504 if (IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
)
505 ipc_entry_dealloc(space
, name
, entry
);
506 is_write_unlock(space
);
508 if ((kr
== KERN_SUCCESS
) && (soright
!= IP_NULL
))
509 ipc_notify_port_deleted(soright
, name
);
515 * Routine: ipc_object_copyin_from_kernel
517 * Copyin a naked capability from the kernel.
519 * MACH_MSG_TYPE_MOVE_RECEIVE
520 * The receiver must be ipc_space_kernel.
521 * Consumes the naked receive right.
522 * MACH_MSG_TYPE_COPY_SEND
523 * A naked send right must be supplied.
524 * The port gains a reference, and a send right
525 * if the port is still active.
526 * MACH_MSG_TYPE_MAKE_SEND
527 * The receiver must be ipc_space_kernel.
528 * The port gains a reference and a send right.
529 * MACH_MSG_TYPE_MOVE_SEND
530 * Consumes a naked send right.
531 * MACH_MSG_TYPE_MAKE_SEND_ONCE
532 * The port gains a reference and a send-once right.
533 * Receiver also be the caller of device subsystem,
535 * MACH_MSG_TYPE_MOVE_SEND_ONCE
536 * Consumes a naked send-once right.
542 ipc_object_copyin_from_kernel(
544 mach_msg_type_name_t msgt_name
)
546 assert(IO_VALID(object
));
549 case MACH_MSG_TYPE_MOVE_RECEIVE
: {
550 ipc_port_t port
= (ipc_port_t
) object
;
553 assert(ip_active(port
));
554 assert(port
->ip_receiver_name
!= MACH_PORT_NULL
);
555 assert(port
->ip_receiver
== ipc_space_kernel
);
557 /* relevant part of ipc_port_clear_receiver */
558 ipc_port_set_mscount(port
, 0);
560 port
->ip_receiver_name
= MACH_PORT_NULL
;
561 port
->ip_destination
= IP_NULL
;
566 case MACH_MSG_TYPE_COPY_SEND
: {
567 ipc_port_t port
= (ipc_port_t
) object
;
570 if (ip_active(port
)) {
571 assert(port
->ip_srights
> 0);
579 case MACH_MSG_TYPE_MAKE_SEND
: {
580 ipc_port_t port
= (ipc_port_t
) object
;
583 assert(ip_active(port
));
584 assert(port
->ip_receiver_name
!= MACH_PORT_NULL
);
585 assert(port
->ip_receiver
== ipc_space_kernel
);
594 case MACH_MSG_TYPE_MOVE_SEND
:
595 /* move naked send right into the message */
598 case MACH_MSG_TYPE_MAKE_SEND_ONCE
: {
599 ipc_port_t port
= (ipc_port_t
) object
;
602 assert(ip_active(port
));
603 assert(port
->ip_receiver_name
!= MACH_PORT_NULL
);
611 case MACH_MSG_TYPE_MOVE_SEND_ONCE
:
612 /* move naked send-once right into the message */
616 panic("ipc_object_copyin_from_kernel: strange rights");
621 * Routine: ipc_object_destroy
623 * Destroys a naked capability.
624 * Consumes a ref for the object.
626 * A receive right should be in limbo or in transit.
634 mach_msg_type_name_t msgt_name
)
636 assert(IO_VALID(object
));
637 assert(io_otype(object
) == IOT_PORT
);
640 case MACH_MSG_TYPE_PORT_SEND
:
641 ipc_port_release_send((ipc_port_t
) object
);
644 case MACH_MSG_TYPE_PORT_SEND_ONCE
:
645 ipc_notify_send_once((ipc_port_t
) object
);
648 case MACH_MSG_TYPE_PORT_RECEIVE
:
649 ipc_port_release_receive((ipc_port_t
) object
);
653 panic("ipc_object_destroy: strange rights");
658 * Routine: ipc_object_copyout
660 * Copyout a capability, placing it into a space.
661 * If successful, consumes a ref for the object.
665 * KERN_SUCCESS Copied out object, consumed ref.
666 * KERN_INVALID_TASK The space is dead.
667 * KERN_INVALID_CAPABILITY The object is dead.
668 * KERN_NO_SPACE No room in space for another right.
669 * KERN_RESOURCE_SHORTAGE No memory available.
670 * KERN_UREFS_OVERFLOW Urefs limit exceeded
671 * and overflow wasn't specified.
678 mach_msg_type_name_t msgt_name
,
680 mach_port_name_t
*namep
)
682 mach_port_name_t name
;
686 assert(IO_VALID(object
));
687 assert(io_otype(object
) == IOT_PORT
);
689 is_write_lock(space
);
692 if (!space
->is_active
) {
693 is_write_unlock(space
);
694 return KERN_INVALID_TASK
;
697 if ((msgt_name
!= MACH_MSG_TYPE_PORT_SEND_ONCE
) &&
698 ipc_right_reverse(space
, object
, &name
, &entry
)) {
699 /* object is locked and active */
701 assert(entry
->ie_bits
& MACH_PORT_TYPE_SEND_RECEIVE
);
705 name
= (mach_port_name_t
)object
;
706 kr
= ipc_entry_get(space
, &name
, &entry
);
707 if (kr
!= KERN_SUCCESS
) {
708 /* unlocks/locks space, so must start again */
710 kr
= ipc_entry_grow_table(space
, ITS_SIZE_NONE
);
711 if (kr
!= KERN_SUCCESS
)
712 return kr
; /* space is unlocked */
717 assert(IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
);
718 assert(entry
->ie_object
== IO_NULL
);
721 if (!io_active(object
)) {
723 ipc_entry_dealloc(space
, name
, entry
);
724 is_write_unlock(space
);
725 return KERN_INVALID_CAPABILITY
;
728 entry
->ie_object
= object
;
732 /* space is write-locked and active, object is locked and active */
734 kr
= ipc_right_copyout(space
, name
, entry
,
735 msgt_name
, overflow
, object
);
736 /* object is unlocked */
737 is_write_unlock(space
);
739 if (kr
== KERN_SUCCESS
)
745 * Routine: ipc_object_copyout_name
747 * Copyout a capability, placing it into a space.
748 * The specified name is used for the capability.
749 * If successful, consumes a ref for the object.
753 * KERN_SUCCESS Copied out object, consumed ref.
754 * KERN_INVALID_TASK The space is dead.
755 * KERN_INVALID_CAPABILITY The object is dead.
756 * KERN_RESOURCE_SHORTAGE No memory available.
757 * KERN_UREFS_OVERFLOW Urefs limit exceeded
758 * and overflow wasn't specified.
759 * KERN_RIGHT_EXISTS Space has rights under another name.
760 * KERN_NAME_EXISTS Name is already used.
764 ipc_object_copyout_name(
767 mach_msg_type_name_t msgt_name
,
769 mach_port_name_t name
)
771 mach_port_name_t oname
;
778 assert(IO_VALID(object
));
779 assert(io_otype(object
) == IOT_PORT
);
781 kr
= ipc_entry_alloc_name(space
, name
, &entry
);
782 if (kr
!= KERN_SUCCESS
)
784 /* space is write-locked and active */
786 if ((msgt_name
!= MACH_MSG_TYPE_PORT_SEND_ONCE
) &&
787 ipc_right_reverse(space
, object
, &oname
, &oentry
)) {
788 /* object is locked and active */
793 if (IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
)
794 ipc_entry_dealloc(space
, name
, entry
);
796 is_write_unlock(space
);
797 return KERN_RIGHT_EXISTS
;
800 assert(entry
== oentry
);
801 assert(entry
->ie_bits
& MACH_PORT_TYPE_SEND_RECEIVE
);
803 if (ipc_right_inuse(space
, name
, entry
))
804 return KERN_NAME_EXISTS
;
806 assert(IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
);
807 assert(entry
->ie_object
== IO_NULL
);
810 if (!io_active(object
)) {
812 ipc_entry_dealloc(space
, name
, entry
);
813 is_write_unlock(space
);
814 return KERN_INVALID_CAPABILITY
;
817 entry
->ie_object
= object
;
820 /* space is write-locked and active, object is locked and active */
822 kr
= ipc_right_copyout(space
, name
, entry
,
823 msgt_name
, overflow
, object
);
824 /* object is unlocked */
825 is_write_unlock(space
);
830 * Routine: ipc_object_copyout_dest
832 * Translates/consumes the destination right of a message.
833 * This is unlike normal copyout because the right is consumed
834 * in a funny way instead of being given to the receiving space.
835 * The receiver gets his name for the port, if he has receive
836 * rights, otherwise MACH_PORT_NULL.
838 * The object is locked and active. Nothing else locked.
839 * The object is unlocked and loses a reference.
843 ipc_object_copyout_dest(
846 mach_msg_type_name_t msgt_name
,
847 mach_port_name_t
*namep
)
849 mach_port_name_t name
;
851 assert(IO_VALID(object
));
852 assert(io_active(object
));
857 * If the space is the receiver/owner of the object,
858 * then we quietly consume the right and return
859 * the space's name for the object. Otherwise
860 * we destroy the right and return MACH_PORT_NULL.
864 case MACH_MSG_TYPE_PORT_SEND
: {
865 ipc_port_t port
= (ipc_port_t
) object
;
866 ipc_port_t nsrequest
= IP_NULL
;
867 mach_port_mscount_t mscount
;
869 if (port
->ip_receiver
== space
)
870 name
= port
->ip_receiver_name
;
872 name
= MACH_PORT_NULL
;
874 assert(port
->ip_srights
> 0);
875 if (--port
->ip_srights
== 0 &&
876 port
->ip_nsrequest
!= IP_NULL
) {
877 nsrequest
= port
->ip_nsrequest
;
878 port
->ip_nsrequest
= IP_NULL
;
879 mscount
= port
->ip_mscount
;
881 ipc_notify_no_senders(nsrequest
, mscount
);
887 case MACH_MSG_TYPE_PORT_SEND_ONCE
: {
888 ipc_port_t port
= (ipc_port_t
) object
;
890 assert(port
->ip_sorights
> 0);
892 if (port
->ip_receiver
== space
) {
893 /* quietly consume the send-once right */
896 name
= port
->ip_receiver_name
;
900 * A very bizarre case. The message
901 * was received, but before this copyout
902 * happened the space lost receive rights.
903 * We can't quietly consume the soright
904 * out from underneath some other task,
905 * so generate a send-once notification.
908 ip_reference(port
); /* restore ref */
911 ipc_notify_send_once(port
);
912 name
= MACH_PORT_NULL
;
919 panic("ipc_object_copyout_dest: strange rights");
926 * Routine: ipc_object_rename
928 * Rename an entry in a space.
932 * KERN_SUCCESS Renamed the entry.
933 * KERN_INVALID_TASK The space was dead.
934 * KERN_INVALID_NAME oname didn't denote an entry.
935 * KERN_NAME_EXISTS nname already denoted an entry.
936 * KERN_RESOURCE_SHORTAGE Couldn't allocate new entry.
942 mach_port_name_t oname
,
943 mach_port_name_t nname
)
945 ipc_entry_t oentry
, nentry
;
950 kr
= ipc_entry_alloc_name(space
, nname
, &nentry
);
951 if (kr
!= KERN_SUCCESS
)
954 /* space is write-locked and active */
956 if (ipc_right_inuse(space
, nname
, nentry
)) {
957 /* space is unlocked */
958 return KERN_NAME_EXISTS
;
961 /* don't let ipc_entry_lookup see the uninitialized new entry */
963 if ((oname
== nname
) ||
964 ((oentry
= ipc_entry_lookup(space
, oname
)) == IE_NULL
)) {
965 ipc_entry_dealloc(space
, nname
, nentry
);
966 is_write_unlock(space
);
967 return KERN_INVALID_NAME
;
970 kr
= ipc_right_rename(space
, oname
, oentry
, nname
, nentry
);
971 /* space is unlocked */
977 * Check whether the object is a port if so, free it. But
978 * keep track of that fact.
987 if (otype
== IOT_PORT
) {
988 port
= (ipc_port_t
) object
;
990 ipc_port_track_dealloc(port
);
991 #endif /* MACH_ASSERT */
993 zfree(ipc_object_zones
[otype
], (vm_offset_t
) object
);
995 #endif /* MACH_ASSERT */
997 #include <mach_kdb.h>
1000 #include <ddb/db_output.h>
1002 #define printf kdbprintf
1005 * Routine: ipc_object_print
1007 * Pretty-print an object for kdb.
1010 char *ikot_print_array
[IKOT_MAX_TYPE
] = {
1021 "(DEVICE) ", /* 10 */
1031 "(ACTIVATION) ", /* 20 */
1037 "(CLOCK_CTRL) ", /* 26 */
1038 "(IOKIT_SPARE) ", /* 27 */
1039 "(NAMED_MEM_ENTRY) ", /* 28 */
1041 "(IOKIT_OBJECT) ", /* 30 */
1043 /* << new entries here */
1044 "(UNKNOWN) " /* magic catchall */
1046 /* Please keep in sync with kern/ipc_kobject.h */
1050 ipc_object_t object
)
1054 iprintf("%s", io_active(object
) ? "active" : "dead");
1055 printf(", refs=%d", object
->io_references
);
1056 printf(", otype=%d", io_otype(object
));
1057 kotype
= io_kotype(object
);
1058 if (kotype
>= 0 && kotype
< IKOT_MAX_TYPE
)
1059 printf(", kotype=%d %s\n", io_kotype(object
),
1060 ikot_print_array
[kotype
]);
1062 printf(", kotype=0x%x %s\n", io_kotype(object
),
1063 ikot_print_array
[IKOT_UNKNOWN
]);
1066 #endif /* MACH_KDB */