]>
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 * 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_pset.c
57 * Functions to manipulate IPC port sets.
60 #include <mach/port.h>
61 #include <mach/kern_return.h>
62 #include <mach/message.h>
63 #include <ipc/ipc_mqueue.h>
64 #include <ipc/ipc_object.h>
65 #include <ipc/ipc_pset.h>
66 #include <ipc/ipc_right.h>
67 #include <ipc/ipc_space.h>
68 #include <ipc/ipc_port.h>
69 #include <ipc/ipc_print.h>
72 * Routine: ipc_pset_alloc
74 * Allocate a port set.
76 * Nothing locked. If successful, the port set is returned
77 * locked. (The caller doesn't have a reference.)
79 * KERN_SUCCESS The port set is allocated.
80 * KERN_INVALID_TASK The space is dead.
81 * KERN_NO_SPACE No room for an entry in the space.
82 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
88 mach_port_name_t
*namep
,
92 mach_port_name_t name
;
95 kr
= ipc_object_alloc(space
, IOT_PORT_SET
,
96 MACH_PORT_TYPE_PORT_SET
, 0,
97 &name
, (ipc_object_t
*) &pset
);
98 if (kr
!= KERN_SUCCESS
)
102 pset
->ips_local_name
= name
;
103 ipc_mqueue_init(&pset
->ips_messages
, TRUE
/* set */);
111 * Routine: ipc_pset_alloc_name
113 * Allocate a port set, with a specific name.
115 * Nothing locked. If successful, the port set is returned
116 * locked. (The caller doesn't have a reference.)
118 * KERN_SUCCESS The port set is allocated.
119 * KERN_INVALID_TASK The space is dead.
120 * KERN_NAME_EXISTS The name already denotes a right.
121 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
127 mach_port_name_t name
,
134 kr
= ipc_object_alloc_name(space
, IOT_PORT_SET
,
135 MACH_PORT_TYPE_PORT_SET
, 0,
136 name
, (ipc_object_t
*) &pset
);
137 if (kr
!= KERN_SUCCESS
)
141 pset
->ips_local_name
= name
;
142 ipc_mqueue_init(&pset
->ips_messages
, TRUE
/* set */);
149 * Routine: ipc_pset_member
151 * Checks to see if a port is a member of a pset
153 * Both port and port set are locked.
154 * The port must be active.
161 assert(ip_active(port
));
163 return (ipc_mqueue_member(&port
->ip_messages
, &pset
->ips_messages
));
168 * Routine: ipc_pset_add
170 * Puts a port into a port set.
172 * Both port and port set are locked and active.
173 * The owner of the port set is also receiver for the port.
183 assert(ips_active(pset
));
184 assert(ip_active(port
));
186 kr
= ipc_mqueue_add(&port
->ip_messages
, &pset
->ips_messages
);
188 if (kr
== KERN_SUCCESS
)
189 port
->ip_pset_count
++;
197 * Routine: ipc_pset_remove
199 * Removes a port from a port set.
200 * The port set loses a reference.
202 * Both port and port set are locked.
203 * The port must be active.
213 assert(ip_active(port
));
215 if (port
->ip_pset_count
== 0)
216 return KERN_NOT_IN_SET
;
218 kr
= ipc_mqueue_remove(&port
->ip_messages
, &pset
->ips_messages
);
220 if (kr
== KERN_SUCCESS
)
221 port
->ip_pset_count
--;
227 * Routine: ipc_pset_remove_from_all
229 * Removes a port from all it's port sets.
231 * port is locked and active.
235 ipc_pset_remove_from_all(
240 assert(ip_active(port
));
242 if (port
->ip_pset_count
== 0)
243 return KERN_NOT_IN_SET
;
246 * Remove the port's mqueue from all sets
248 ipc_mqueue_remove_from_all(&port
->ip_messages
);
249 port
->ip_pset_count
= 0;
255 * Routine: ipc_pset_destroy
257 * Destroys a port_set.
259 * The port_set is locked and alive.
260 * The caller has a reference, which is consumed.
261 * Afterwards, the port_set is unlocked and dead.
270 assert(ips_active(pset
));
272 pset
->ips_object
.io_bits
&= ~IO_BITS_ACTIVE
;
275 * remove all the member message queues
277 ipc_mqueue_remove_all(&pset
->ips_messages
);
280 imq_lock(&pset
->ips_messages
);
281 ipc_mqueue_changed(&pset
->ips_messages
);
282 imq_unlock(&pset
->ips_messages
);
285 /* XXXX Perhaps ought to verify ips_thread_pool is empty */
287 ips_release(pset
); /* consume the ref our caller gave us */
288 ips_check_unlock(pset
);
291 #include <mach_kdb.h>
294 #include <ddb/db_output.h>
296 #define printf kdbprintf
300 struct ipc_kmsg
*base
)
302 register int count
= 0;
305 struct ipc_kmsg
*kmsg
= base
;
308 while (kmsg
&& kmsg
->ikm_next
!= base
309 && kmsg
->ikm_next
!= IKM_BOGUS
){
310 kmsg
= kmsg
->ikm_next
;
318 * Routine: ipc_pset_print
320 * Pretty-print a port set for kdb.
327 extern int db_indent
;
329 printf("pset 0x%x\n", pset
);
333 ipc_object_print(&pset
->ips_object
);
334 iprintf("local_name = 0x%x\n", pset
->ips_local_name
);
335 iprintf("%d kmsgs => 0x%x",
336 ipc_list_count(pset
->ips_messages
.imq_messages
.ikmq_base
),
337 pset
->ips_messages
.imq_messages
.ikmq_base
);
338 printf(",rcvrs queue= 0x%x\n", &pset
->ips_messages
.imq_wait_queue
);
343 #endif /* MACH_KDB */