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 * or the receive right must already be in limbo.
525 * Consumes the naked receive right.
526 * MACH_MSG_TYPE_COPY_SEND
527 * A naked send right must be supplied.
528 * The port gains a reference, and a send right
529 * if the port is still active.
530 * MACH_MSG_TYPE_MAKE_SEND
531 * The receiver must be ipc_space_kernel.
532 * The port gains a reference and a send right.
533 * MACH_MSG_TYPE_MOVE_SEND
534 * Consumes a naked send right.
535 * MACH_MSG_TYPE_MAKE_SEND_ONCE
536 * The port gains a reference and a send-once right.
537 * Receiver also be the caller of device subsystem,
539 * MACH_MSG_TYPE_MOVE_SEND_ONCE
540 * Consumes a naked send-once right.
546 ipc_object_copyin_from_kernel(
548 mach_msg_type_name_t msgt_name
)
550 assert(IO_VALID(object
));
553 case MACH_MSG_TYPE_MOVE_RECEIVE
: {
554 ipc_port_t port
= (ipc_port_t
) object
;
557 assert(ip_active(port
));
558 if (port
->ip_destination
!= IP_NULL
) {
559 assert(port
->ip_receiver
== ipc_space_kernel
);
561 /* relevant part of ipc_port_clear_receiver */
562 ipc_port_set_mscount(port
, 0);
564 port
->ip_receiver_name
= MACH_PORT_NULL
;
565 port
->ip_destination
= IP_NULL
;
571 case MACH_MSG_TYPE_COPY_SEND
: {
572 ipc_port_t port
= (ipc_port_t
) object
;
575 if (ip_active(port
)) {
576 assert(port
->ip_srights
> 0);
584 case MACH_MSG_TYPE_MAKE_SEND
: {
585 ipc_port_t port
= (ipc_port_t
) object
;
588 assert(ip_active(port
));
589 assert(port
->ip_receiver_name
!= MACH_PORT_NULL
);
590 assert(port
->ip_receiver
== ipc_space_kernel
);
599 case MACH_MSG_TYPE_MOVE_SEND
: {
600 /* move naked send right into the message */
601 ipc_port_t port
= (ipc_port_t
) object
;
602 assert(port
->ip_srights
);
606 case MACH_MSG_TYPE_MAKE_SEND_ONCE
: {
607 ipc_port_t port
= (ipc_port_t
) object
;
610 assert(ip_active(port
));
611 assert(port
->ip_receiver_name
!= MACH_PORT_NULL
);
619 case MACH_MSG_TYPE_MOVE_SEND_ONCE
: {
620 /* move naked send-once right into the message */
621 ipc_port_t port
= (ipc_port_t
) object
;
622 assert(port
->ip_sorights
);
627 panic("ipc_object_copyin_from_kernel: strange rights");
632 * Routine: ipc_object_destroy
634 * Destroys a naked capability.
635 * Consumes a ref for the object.
637 * A receive right should be in limbo or in transit.
645 mach_msg_type_name_t msgt_name
)
647 assert(IO_VALID(object
));
648 assert(io_otype(object
) == IOT_PORT
);
651 case MACH_MSG_TYPE_PORT_SEND
:
652 ipc_port_release_send((ipc_port_t
) object
);
655 case MACH_MSG_TYPE_PORT_SEND_ONCE
:
656 ipc_notify_send_once((ipc_port_t
) object
);
659 case MACH_MSG_TYPE_PORT_RECEIVE
:
660 ipc_port_release_receive((ipc_port_t
) object
);
664 panic("ipc_object_destroy: strange rights");
669 * Routine: ipc_object_copyout
671 * Copyout a capability, placing it into a space.
672 * If successful, consumes a ref for the object.
676 * KERN_SUCCESS Copied out object, consumed ref.
677 * KERN_INVALID_TASK The space is dead.
678 * KERN_INVALID_CAPABILITY The object is dead.
679 * KERN_NO_SPACE No room in space for another right.
680 * KERN_RESOURCE_SHORTAGE No memory available.
681 * KERN_UREFS_OVERFLOW Urefs limit exceeded
682 * and overflow wasn't specified.
689 mach_msg_type_name_t msgt_name
,
691 mach_port_name_t
*namep
)
693 mach_port_name_t name
;
697 assert(IO_VALID(object
));
698 assert(io_otype(object
) == IOT_PORT
);
700 is_write_lock(space
);
703 if (!space
->is_active
) {
704 is_write_unlock(space
);
705 return KERN_INVALID_TASK
;
708 if ((msgt_name
!= MACH_MSG_TYPE_PORT_SEND_ONCE
) &&
709 ipc_right_reverse(space
, object
, &name
, &entry
)) {
710 /* object is locked and active */
712 assert(entry
->ie_bits
& MACH_PORT_TYPE_SEND_RECEIVE
);
716 name
= (mach_port_name_t
)object
;
717 kr
= ipc_entry_get(space
, &name
, &entry
);
718 if (kr
!= KERN_SUCCESS
) {
719 /* unlocks/locks space, so must start again */
721 kr
= ipc_entry_grow_table(space
, ITS_SIZE_NONE
);
722 if (kr
!= KERN_SUCCESS
)
723 return kr
; /* space is unlocked */
728 assert(IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
);
729 assert(entry
->ie_object
== IO_NULL
);
732 if (!io_active(object
)) {
734 ipc_entry_dealloc(space
, name
, entry
);
735 is_write_unlock(space
);
736 return KERN_INVALID_CAPABILITY
;
739 entry
->ie_object
= object
;
743 /* space is write-locked and active, object is locked and active */
745 kr
= ipc_right_copyout(space
, name
, entry
,
746 msgt_name
, overflow
, object
);
747 /* object is unlocked */
748 is_write_unlock(space
);
750 if (kr
== KERN_SUCCESS
)
756 * Routine: ipc_object_copyout_name
758 * Copyout a capability, placing it into a space.
759 * The specified name is used for the capability.
760 * If successful, consumes a ref for the object.
764 * KERN_SUCCESS Copied out object, consumed ref.
765 * KERN_INVALID_TASK The space is dead.
766 * KERN_INVALID_CAPABILITY The object is dead.
767 * KERN_RESOURCE_SHORTAGE No memory available.
768 * KERN_UREFS_OVERFLOW Urefs limit exceeded
769 * and overflow wasn't specified.
770 * KERN_RIGHT_EXISTS Space has rights under another name.
771 * KERN_NAME_EXISTS Name is already used.
775 ipc_object_copyout_name(
778 mach_msg_type_name_t msgt_name
,
780 mach_port_name_t name
)
782 mach_port_name_t oname
;
789 assert(IO_VALID(object
));
790 assert(io_otype(object
) == IOT_PORT
);
792 kr
= ipc_entry_alloc_name(space
, name
, &entry
);
793 if (kr
!= KERN_SUCCESS
)
795 /* space is write-locked and active */
797 if ((msgt_name
!= MACH_MSG_TYPE_PORT_SEND_ONCE
) &&
798 ipc_right_reverse(space
, object
, &oname
, &oentry
)) {
799 /* object is locked and active */
804 if (IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
)
805 ipc_entry_dealloc(space
, name
, entry
);
807 is_write_unlock(space
);
808 return KERN_RIGHT_EXISTS
;
811 assert(entry
== oentry
);
812 assert(entry
->ie_bits
& MACH_PORT_TYPE_SEND_RECEIVE
);
814 if (ipc_right_inuse(space
, name
, entry
))
815 return KERN_NAME_EXISTS
;
817 assert(IE_BITS_TYPE(entry
->ie_bits
) == MACH_PORT_TYPE_NONE
);
818 assert(entry
->ie_object
== IO_NULL
);
821 if (!io_active(object
)) {
823 ipc_entry_dealloc(space
, name
, entry
);
824 is_write_unlock(space
);
825 return KERN_INVALID_CAPABILITY
;
828 entry
->ie_object
= object
;
831 /* space is write-locked and active, object is locked and active */
833 kr
= ipc_right_copyout(space
, name
, entry
,
834 msgt_name
, overflow
, object
);
835 /* object is unlocked */
836 is_write_unlock(space
);
841 * Routine: ipc_object_copyout_dest
843 * Translates/consumes the destination right of a message.
844 * This is unlike normal copyout because the right is consumed
845 * in a funny way instead of being given to the receiving space.
846 * The receiver gets his name for the port, if he has receive
847 * rights, otherwise MACH_PORT_NULL.
849 * The object is locked and active. Nothing else locked.
850 * The object is unlocked and loses a reference.
854 ipc_object_copyout_dest(
857 mach_msg_type_name_t msgt_name
,
858 mach_port_name_t
*namep
)
860 mach_port_name_t name
;
862 assert(IO_VALID(object
));
863 assert(io_active(object
));
868 * If the space is the receiver/owner of the object,
869 * then we quietly consume the right and return
870 * the space's name for the object. Otherwise
871 * we destroy the right and return MACH_PORT_NULL.
875 case MACH_MSG_TYPE_PORT_SEND
: {
876 ipc_port_t port
= (ipc_port_t
) object
;
877 ipc_port_t nsrequest
= IP_NULL
;
878 mach_port_mscount_t mscount
;
880 if (port
->ip_receiver
== space
)
881 name
= port
->ip_receiver_name
;
883 name
= MACH_PORT_NULL
;
885 assert(port
->ip_srights
> 0);
886 if (--port
->ip_srights
== 0 &&
887 port
->ip_nsrequest
!= IP_NULL
) {
888 nsrequest
= port
->ip_nsrequest
;
889 port
->ip_nsrequest
= IP_NULL
;
890 mscount
= port
->ip_mscount
;
892 ipc_notify_no_senders(nsrequest
, mscount
);
898 case MACH_MSG_TYPE_PORT_SEND_ONCE
: {
899 ipc_port_t port
= (ipc_port_t
) object
;
901 assert(port
->ip_sorights
> 0);
903 if (port
->ip_receiver
== space
) {
904 /* quietly consume the send-once right */
907 name
= port
->ip_receiver_name
;
911 * A very bizarre case. The message
912 * was received, but before this copyout
913 * happened the space lost receive rights.
914 * We can't quietly consume the soright
915 * out from underneath some other task,
916 * so generate a send-once notification.
919 ip_reference(port
); /* restore ref */
922 ipc_notify_send_once(port
);
923 name
= MACH_PORT_NULL
;
930 panic("ipc_object_copyout_dest: strange rights");
937 * Routine: ipc_object_rename
939 * Rename an entry in a space.
943 * KERN_SUCCESS Renamed the entry.
944 * KERN_INVALID_TASK The space was dead.
945 * KERN_INVALID_NAME oname didn't denote an entry.
946 * KERN_NAME_EXISTS nname already denoted an entry.
947 * KERN_RESOURCE_SHORTAGE Couldn't allocate new entry.
953 mach_port_name_t oname
,
954 mach_port_name_t nname
)
956 ipc_entry_t oentry
, nentry
;
961 kr
= ipc_entry_alloc_name(space
, nname
, &nentry
);
962 if (kr
!= KERN_SUCCESS
)
965 /* space is write-locked and active */
967 if (ipc_right_inuse(space
, nname
, nentry
)) {
968 /* space is unlocked */
969 return KERN_NAME_EXISTS
;
972 /* don't let ipc_entry_lookup see the uninitialized new entry */
974 if ((oname
== nname
) ||
975 ((oentry
= ipc_entry_lookup(space
, oname
)) == IE_NULL
)) {
976 ipc_entry_dealloc(space
, nname
, nentry
);
977 is_write_unlock(space
);
978 return KERN_INVALID_NAME
;
981 kr
= ipc_right_rename(space
, oname
, oentry
, nname
, nentry
);
982 /* space is unlocked */
988 * Check whether the object is a port if so, free it. But
989 * keep track of that fact.
998 if (otype
== IOT_PORT
) {
999 port
= (ipc_port_t
) object
;
1001 ipc_port_track_dealloc(port
);
1002 #endif /* MACH_ASSERT */
1004 zfree(ipc_object_zones
[otype
], (vm_offset_t
) object
);
1006 #endif /* MACH_ASSERT */
1008 #include <mach_kdb.h>
1011 #include <ddb/db_output.h>
1013 #define printf kdbprintf
1016 * Routine: ipc_object_print
1018 * Pretty-print an object for kdb.
1021 char *ikot_print_array
[IKOT_MAX_TYPE
] = {
1032 "(DEVICE) ", /* 10 */
1042 "(ACTIVATION) ", /* 20 */
1048 "(CLOCK_CTRL) ", /* 26 */
1049 "(IOKIT_SPARE) ", /* 27 */
1050 "(NAMED_MEM_ENTRY) ", /* 28 */
1052 "(IOKIT_OBJECT) ", /* 30 */
1054 /* << new entries here */
1055 "(UNKNOWN) " /* magic catchall */
1057 /* Please keep in sync with kern/ipc_kobject.h */
1061 ipc_object_t object
)
1065 iprintf("%s", io_active(object
) ? "active" : "dead");
1066 printf(", refs=%d", object
->io_references
);
1067 printf(", otype=%d", io_otype(object
));
1068 kotype
= io_kotype(object
);
1069 if (kotype
>= 0 && kotype
< IKOT_MAX_TYPE
)
1070 printf(", kotype=%d %s\n", io_kotype(object
),
1071 ikot_print_array
[kotype
]);
1073 printf(", kotype=0x%x %s\n", io_kotype(object
),
1074 ikot_print_array
[IKOT_UNKNOWN
]);
1077 #endif /* MACH_KDB */