]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_pset.c
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_pset.c
60 * Functions to manipulate IPC port sets.
63 #include <mach/port.h>
64 #include <mach/kern_return.h>
65 #include <mach/message.h>
66 #include <ipc/ipc_mqueue.h>
67 #include <ipc/ipc_object.h>
68 #include <ipc/ipc_pset.h>
69 #include <ipc/ipc_right.h>
70 #include <ipc/ipc_space.h>
71 #include <ipc/ipc_port.h>
72 #include <ipc/ipc_print.h>
75 * Routine: ipc_pset_alloc
77 * Allocate a port set.
79 * Nothing locked. If successful, the port set is returned
80 * locked. (The caller doesn't have a reference.)
82 * KERN_SUCCESS The port set is allocated.
83 * KERN_INVALID_TASK The space is dead.
84 * KERN_NO_SPACE No room for an entry in the space.
85 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
91 mach_port_name_t
*namep
,
95 mach_port_name_t name
;
98 kr
= ipc_object_alloc(space
, IOT_PORT_SET
,
99 MACH_PORT_TYPE_PORT_SET
, 0,
100 &name
, (ipc_object_t
*) &pset
);
101 if (kr
!= KERN_SUCCESS
)
105 pset
->ips_local_name
= name
;
106 ipc_mqueue_init(&pset
->ips_messages
, TRUE
/* set */);
114 * Routine: ipc_pset_alloc_name
116 * Allocate a port set, with a specific name.
118 * Nothing locked. If successful, the port set is returned
119 * locked. (The caller doesn't have a reference.)
121 * KERN_SUCCESS The port set is allocated.
122 * KERN_INVALID_TASK The space is dead.
123 * KERN_NAME_EXISTS The name already denotes a right.
124 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
130 mach_port_name_t name
,
137 kr
= ipc_object_alloc_name(space
, IOT_PORT_SET
,
138 MACH_PORT_TYPE_PORT_SET
, 0,
139 name
, (ipc_object_t
*) &pset
);
140 if (kr
!= KERN_SUCCESS
)
144 pset
->ips_local_name
= name
;
145 ipc_mqueue_init(&pset
->ips_messages
, TRUE
/* set */);
152 * Routine: ipc_pset_member
154 * Checks to see if a port is a member of a pset
156 * Both port and port set are locked.
157 * The port must be active.
164 assert(ip_active(port
));
166 return (ipc_mqueue_member(&port
->ip_messages
, &pset
->ips_messages
));
171 * Routine: ipc_pset_add
173 * Puts a port into a port set.
175 * Both port and port set are locked and active.
176 * The owner of the port set is also receiver for the port.
186 assert(ips_active(pset
));
187 assert(ip_active(port
));
189 kr
= ipc_mqueue_add(&port
->ip_messages
, &pset
->ips_messages
);
191 if (kr
== KERN_SUCCESS
)
192 port
->ip_pset_count
++;
200 * Routine: ipc_pset_remove
202 * Removes a port from a port set.
203 * The port set loses a reference.
205 * Both port and port set are locked.
206 * The port must be active.
216 assert(ip_active(port
));
218 if (port
->ip_pset_count
== 0)
219 return KERN_NOT_IN_SET
;
221 kr
= ipc_mqueue_remove(&port
->ip_messages
, &pset
->ips_messages
);
223 if (kr
== KERN_SUCCESS
)
224 port
->ip_pset_count
--;
230 * Routine: ipc_pset_remove_from_all
232 * Removes a port from all it's port sets.
234 * port is locked and active.
238 ipc_pset_remove_from_all(
243 assert(ip_active(port
));
245 if (port
->ip_pset_count
== 0)
246 return KERN_NOT_IN_SET
;
249 * Remove the port's mqueue from all sets
251 ipc_mqueue_remove_from_all(&port
->ip_messages
);
252 port
->ip_pset_count
= 0;
258 * Routine: ipc_pset_destroy
260 * Destroys a port_set.
262 * The port_set is locked and alive.
263 * The caller has a reference, which is consumed.
264 * Afterwards, the port_set is unlocked and dead.
273 assert(ips_active(pset
));
275 pset
->ips_object
.io_bits
&= ~IO_BITS_ACTIVE
;
278 * remove all the member message queues
280 ipc_mqueue_remove_all(&pset
->ips_messages
);
283 imq_lock(&pset
->ips_messages
);
284 ipc_mqueue_changed(&pset
->ips_messages
);
285 imq_unlock(&pset
->ips_messages
);
288 /* XXXX Perhaps ought to verify ips_thread_pool is empty */
290 ips_release(pset
); /* consume the ref our caller gave us */
291 ips_check_unlock(pset
);
294 #include <mach_kdb.h>
297 #include <ddb/db_output.h>
299 #define printf kdbprintf
303 struct ipc_kmsg
*base
)
305 register int count
= 0;
308 struct ipc_kmsg
*kmsg
= base
;
311 while (kmsg
&& kmsg
->ikm_next
!= base
312 && kmsg
->ikm_next
!= IKM_BOGUS
){
313 kmsg
= kmsg
->ikm_next
;
321 * Routine: ipc_pset_print
323 * Pretty-print a port set for kdb.
330 extern int db_indent
;
332 printf("pset 0x%x\n", pset
);
336 ipc_object_print(&pset
->ips_object
);
337 iprintf("local_name = 0x%x\n", pset
->ips_local_name
);
338 iprintf("%d kmsgs => 0x%x",
339 ipc_list_count(pset
->ips_messages
.imq_messages
.ikmq_base
),
340 pset
->ips_messages
.imq_messages
.ikmq_base
);
341 printf(",rcvrs queue= 0x%x\n", &pset
->ips_messages
.imq_wait_queue
);
346 #endif /* MACH_KDB */