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@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * November 9, 2000 Allan Nathanson <ajn@apple.com>
33 #include <SystemConfiguration/SystemConfiguration.h>
34 #include <SystemConfiguration/SCPrivate.h>
36 #include <mach/mach.h>
37 #include <mach/notify.h>
38 #include <mach/mach_error.h>
42 __showMachPortStatus()
45 /* print status of in-use mach ports */
48 mach_port_name_array_t ports
;
49 mach_port_type_array_t types
;
51 CFMutableStringRef str
;
53 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("----------"));
55 /* report on ALL mach ports associated with this task */
56 status
= mach_port_names(mach_task_self(), &ports
, &pn
, &types
, &tn
);
57 if (status
== MACH_MSG_SUCCESS
) {
58 str
= CFStringCreateMutable(NULL
, 0);
59 for (pi
=0; pi
< pn
; pi
++) {
60 char rights
[16], *rp
= &rights
[0];
62 if (types
[pi
] != MACH_PORT_TYPE_NONE
) {
65 if (types
[pi
] & MACH_PORT_TYPE_SEND
)
67 if (types
[pi
] & MACH_PORT_TYPE_RECEIVE
)
69 if (types
[pi
] & MACH_PORT_TYPE_SEND_ONCE
)
71 if (types
[pi
] & MACH_PORT_TYPE_PORT_SET
)
73 if (types
[pi
] & MACH_PORT_TYPE_DEAD_NAME
)
78 CFStringAppendFormat(str
, NULL
, CFSTR(" %d%s"), ports
[pi
], rights
);
80 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("Task ports (n=%d):%@"), pn
, str
);
83 /* log (but ignore) errors */
84 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("mach_port_names(): %s"), mach_error_string(status
));
93 __showMachPortReferences(mach_port_t port
)
97 mach_port_urefs_t refs_send
= 0;
98 mach_port_urefs_t refs_recv
= 0;
99 mach_port_urefs_t refs_once
= 0;
100 mach_port_urefs_t refs_pset
= 0;
101 mach_port_urefs_t refs_dead
= 0;
103 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("user references for mach port %d"), port
);
105 status
= mach_port_get_refs(mach_task_self(), port
, MACH_PORT_RIGHT_SEND
, &refs_send
);
106 if (status
!= KERN_SUCCESS
) {
107 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_SEND): %s"), mach_error_string(status
));
111 status
= mach_port_get_refs(mach_task_self(), port
, MACH_PORT_RIGHT_RECEIVE
, &refs_recv
);
112 if (status
!= KERN_SUCCESS
) {
113 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_RECEIVE): %s"), mach_error_string(status
));
117 status
= mach_port_get_refs(mach_task_self(), port
, MACH_PORT_RIGHT_SEND_ONCE
, &refs_once
);
118 if (status
!= KERN_SUCCESS
) {
119 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_SEND_ONCE): %s"), mach_error_string(status
));
123 status
= mach_port_get_refs(mach_task_self(), port
, MACH_PORT_RIGHT_PORT_SET
, &refs_pset
);
124 if (status
!= KERN_SUCCESS
) {
125 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_PORT_SET): %s"), mach_error_string(status
));
129 status
= mach_port_get_refs(mach_task_self(), port
, MACH_PORT_RIGHT_DEAD_NAME
, &refs_dead
);
130 if (status
!= KERN_SUCCESS
) {
131 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" mach_port_get_refs(MACH_PORT_RIGHT_DEAD_NAME): %s"), mach_error_string(status
));
135 SCLog(_sc_verbose
, LOG_DEBUG
,
136 CFSTR(" send = %d, receive = %d, send once = %d, port set = %d, dead name = %d"),