]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | /* | |
59 | * File: ipc/mach_debug.c | |
60 | * Author: Rich Draves | |
61 | * Date: 1989 | |
62 | * | |
63 | * Exported IPC debug calls. | |
64 | */ | |
65 | #include <mach_ipc_debug.h> | |
66 | ||
67 | #include <mach/vm_param.h> | |
68 | #include <mach/kern_return.h> | |
69 | #include <mach/machine/vm_types.h> | |
70 | #include <mach/mach_host_server.h> | |
71 | #include <mach/mach_port_server.h> | |
72 | #include <mach_debug/ipc_info.h> | |
73 | #include <mach_debug/hash_info.h> | |
74 | ||
75 | #if MACH_IPC_DEBUG | |
76 | #include <kern/host.h> | |
77 | #include <kern/misc_protos.h> | |
78 | #include <vm/vm_map.h> | |
79 | #include <vm/vm_kern.h> | |
91447636 A |
80 | #include <ipc/port.h> |
81 | #include <ipc/ipc_types.h> | |
1c79356b A |
82 | #include <ipc/ipc_space.h> |
83 | #include <ipc/ipc_port.h> | |
84 | #include <ipc/ipc_hash.h> | |
85 | #include <ipc/ipc_table.h> | |
86 | #include <ipc/ipc_right.h> | |
87 | #endif | |
88 | ||
89 | /* | |
90 | * Routine: mach_port_get_srights [kernel call] | |
91 | * Purpose: | |
92 | * Retrieve the number of extant send rights | |
93 | * that a receive right has. | |
94 | * Conditions: | |
95 | * Nothing locked. | |
96 | * Returns: | |
97 | * KERN_SUCCESS Retrieved number of send rights. | |
98 | * KERN_INVALID_TASK The space is null. | |
99 | * KERN_INVALID_TASK The space is dead. | |
100 | * KERN_INVALID_NAME The name doesn't denote a right. | |
101 | * KERN_INVALID_RIGHT Name doesn't denote receive rights. | |
102 | */ | |
103 | ||
91447636 A |
104 | #if !MACH_IPC_DEBUG |
105 | kern_return_t | |
106 | mach_port_get_srights( | |
107 | __unused ipc_space_t space, | |
108 | __unused mach_port_name_t name, | |
109 | __unused mach_port_rights_t *srightsp) | |
110 | { | |
111 | return KERN_FAILURE; | |
112 | } | |
113 | #else | |
1c79356b A |
114 | kern_return_t |
115 | mach_port_get_srights( | |
116 | ipc_space_t space, | |
117 | mach_port_name_t name, | |
118 | mach_port_rights_t *srightsp) | |
119 | { | |
1c79356b A |
120 | ipc_port_t port; |
121 | kern_return_t kr; | |
122 | mach_port_rights_t srights; | |
123 | ||
124 | if (space == IS_NULL) | |
125 | return KERN_INVALID_TASK; | |
126 | ||
127 | kr = ipc_port_translate_receive(space, name, &port); | |
128 | if (kr != KERN_SUCCESS) | |
129 | return kr; | |
130 | /* port is locked and active */ | |
131 | ||
132 | srights = port->ip_srights; | |
133 | ip_unlock(port); | |
134 | ||
135 | *srightsp = srights; | |
136 | return KERN_SUCCESS; | |
1c79356b | 137 | } |
91447636 | 138 | #endif /* MACH_IPC_DEBUG */ |
1c79356b A |
139 | |
140 | /* | |
141 | * Routine: host_ipc_hash_info | |
142 | * Purpose: | |
143 | * Return information about the global reverse hash table. | |
144 | * Conditions: | |
145 | * Nothing locked. Obeys CountInOut protocol. | |
146 | * Returns: | |
147 | * KERN_SUCCESS Returned information. | |
148 | * KERN_INVALID_HOST The host is null. | |
149 | * KERN_RESOURCE_SHORTAGE Couldn't allocate memory. | |
150 | */ | |
151 | ||
91447636 | 152 | #if !MACH_IPC_DEBUG |
1c79356b A |
153 | kern_return_t |
154 | host_ipc_hash_info( | |
91447636 A |
155 | __unused host_t host, |
156 | __unused hash_info_bucket_array_t *infop, | |
157 | __unused mach_msg_type_number_t *countp) | |
1c79356b | 158 | { |
1c79356b | 159 | return KERN_FAILURE; |
91447636 | 160 | } |
1c79356b | 161 | #else |
91447636 A |
162 | kern_return_t |
163 | host_ipc_hash_info( | |
164 | host_t host, | |
165 | hash_info_bucket_array_t *infop, | |
166 | mach_msg_type_number_t *countp) | |
167 | { | |
2d21ac55 | 168 | vm_map_copy_t copy; |
1c79356b | 169 | vm_offset_t addr; |
2d21ac55 | 170 | vm_size_t size; |
1c79356b | 171 | hash_info_bucket_t *info; |
2d21ac55 | 172 | natural_t count; |
1c79356b A |
173 | kern_return_t kr; |
174 | ||
175 | if (host == HOST_NULL) | |
176 | return KERN_INVALID_HOST; | |
177 | ||
178 | /* start with in-line data */ | |
179 | ||
2d21ac55 A |
180 | count = ipc_hash_size(); |
181 | size = round_page(count * sizeof(hash_info_bucket_t)); | |
182 | kr = kmem_alloc_pageable(ipc_kernel_map, &addr, size); | |
183 | if (kr != KERN_SUCCESS) | |
184 | return KERN_RESOURCE_SHORTAGE; | |
1c79356b | 185 | |
2d21ac55 A |
186 | info = (hash_info_bucket_t *) addr; |
187 | count = ipc_hash_info(info, count); | |
1c79356b | 188 | |
2d21ac55 A |
189 | if (size > count * sizeof(hash_info_bucket_t)) |
190 | bzero((char *)&info[count], size - count * sizeof(hash_info_bucket_t)); | |
1c79356b | 191 | |
2d21ac55 A |
192 | kr = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)addr, |
193 | (vm_map_size_t)size, TRUE, ©); | |
194 | assert(kr == KERN_SUCCESS); | |
1c79356b | 195 | |
2d21ac55 A |
196 | *infop = (hash_info_bucket_t *) copy; |
197 | *countp = count; | |
1c79356b | 198 | return KERN_SUCCESS; |
1c79356b | 199 | } |
91447636 | 200 | #endif /* MACH_IPC_DEBUG */ |
1c79356b A |
201 | |
202 | /* | |
203 | * Routine: mach_port_space_info | |
204 | * Purpose: | |
205 | * Returns information about an IPC space. | |
206 | * Conditions: | |
207 | * Nothing locked. Obeys CountInOut protocol. | |
208 | * Returns: | |
209 | * KERN_SUCCESS Returned information. | |
210 | * KERN_INVALID_TASK The space is null. | |
211 | * KERN_INVALID_TASK The space is dead. | |
212 | * KERN_RESOURCE_SHORTAGE Couldn't allocate memory. | |
213 | */ | |
214 | ||
91447636 | 215 | #if !MACH_IPC_DEBUG |
1c79356b A |
216 | kern_return_t |
217 | mach_port_space_info( | |
91447636 A |
218 | __unused ipc_space_t space, |
219 | __unused ipc_info_space_t *infop, | |
220 | __unused ipc_info_name_array_t *tablep, | |
221 | __unused mach_msg_type_number_t *tableCntp, | |
222 | __unused ipc_info_tree_name_array_t *treep, | |
223 | __unused mach_msg_type_number_t *treeCntp) | |
224 | { | |
225 | return KERN_FAILURE; | |
226 | } | |
227 | #else | |
228 | kern_return_t | |
229 | mach_port_space_info( | |
2d21ac55 A |
230 | ipc_space_t space, |
231 | ipc_info_space_t *infop, | |
1c79356b A |
232 | ipc_info_name_array_t *tablep, |
233 | mach_msg_type_number_t *tableCntp, | |
2d21ac55 | 234 | ipc_info_tree_name_array_t *treep, |
1c79356b A |
235 | mach_msg_type_number_t *treeCntp) |
236 | { | |
1c79356b | 237 | ipc_info_name_t *table_info; |
1c79356b | 238 | vm_offset_t table_addr; |
2d21ac55 | 239 | vm_size_t table_size, table_size_needed; |
1c79356b | 240 | ipc_info_tree_name_t *tree_info; |
1c79356b | 241 | vm_offset_t tree_addr; |
2d21ac55 | 242 | vm_size_t tree_size, tree_size_needed; |
1c79356b A |
243 | ipc_tree_entry_t tentry; |
244 | ipc_entry_t table; | |
245 | ipc_entry_num_t tsize; | |
246 | mach_port_index_t index; | |
247 | kern_return_t kr; | |
2d21ac55 A |
248 | vm_map_copy_t copy; |
249 | ||
1c79356b A |
250 | |
251 | if (space == IS_NULL) | |
252 | return KERN_INVALID_TASK; | |
253 | ||
254 | /* start with in-line memory */ | |
255 | ||
91447636 | 256 | table_size = 0; |
91447636 | 257 | tree_size = 0; |
1c79356b A |
258 | |
259 | for (;;) { | |
260 | is_read_lock(space); | |
261 | if (!space->is_active) { | |
262 | is_read_unlock(space); | |
2d21ac55 | 263 | if (table_size != 0) |
1c79356b A |
264 | kmem_free(ipc_kernel_map, |
265 | table_addr, table_size); | |
2d21ac55 | 266 | if (tree_size != 0) |
1c79356b A |
267 | kmem_free(ipc_kernel_map, |
268 | tree_addr, tree_size); | |
269 | return KERN_INVALID_TASK; | |
270 | } | |
271 | ||
2d21ac55 A |
272 | table_size_needed = round_page(space->is_table_size |
273 | * sizeof(ipc_info_name_t)); | |
274 | tree_size_needed = round_page(space->is_tree_total | |
275 | * sizeof(ipc_info_tree_name_t)); | |
1c79356b | 276 | |
2d21ac55 A |
277 | if ((table_size_needed == table_size) && |
278 | (tree_size_needed == tree_size)) | |
1c79356b A |
279 | break; |
280 | ||
281 | is_read_unlock(space); | |
282 | ||
2d21ac55 A |
283 | if (table_size != table_size_needed) { |
284 | if (table_size != 0) | |
285 | kmem_free(ipc_kernel_map, table_addr, table_size); | |
286 | kr = kmem_alloc(ipc_kernel_map, &table_addr, table_size_needed); | |
1c79356b | 287 | if (kr != KERN_SUCCESS) { |
2d21ac55 A |
288 | if (tree_size != 0) |
289 | kmem_free(ipc_kernel_map, tree_addr, tree_size); | |
1c79356b A |
290 | return KERN_RESOURCE_SHORTAGE; |
291 | } | |
2d21ac55 | 292 | table_size = table_size_needed; |
1c79356b | 293 | } |
2d21ac55 A |
294 | if (tree_size != tree_size_needed) { |
295 | if (tree_size != 0) | |
296 | kmem_free(ipc_kernel_map, tree_addr, tree_size); | |
297 | kr = kmem_alloc(ipc_kernel_map, &tree_addr, tree_size_needed); | |
1c79356b | 298 | if (kr != KERN_SUCCESS) { |
2d21ac55 A |
299 | if (table_size != 0) |
300 | kmem_free(ipc_kernel_map, table_addr, table_size); | |
1c79356b A |
301 | return KERN_RESOURCE_SHORTAGE; |
302 | } | |
2d21ac55 | 303 | tree_size = tree_size_needed; |
1c79356b A |
304 | } |
305 | } | |
306 | /* space is read-locked and active; we have enough wired memory */ | |
307 | ||
2d21ac55 | 308 | /* get the overall space info */ |
1c79356b A |
309 | infop->iis_genno_mask = MACH_PORT_NGEN(MACH_PORT_DEAD); |
310 | infop->iis_table_size = space->is_table_size; | |
311 | infop->iis_table_next = space->is_table_next->its_size; | |
312 | infop->iis_tree_size = space->is_tree_total; | |
313 | infop->iis_tree_small = space->is_tree_small; | |
314 | infop->iis_tree_hash = space->is_tree_hash; | |
315 | ||
2d21ac55 | 316 | /* walk the table for this space */ |
1c79356b A |
317 | table = space->is_table; |
318 | tsize = space->is_table_size; | |
2d21ac55 | 319 | table_info = (ipc_info_name_array_t)table_addr; |
1c79356b A |
320 | for (index = 0; index < tsize; index++) { |
321 | ipc_info_name_t *iin = &table_info[index]; | |
322 | ipc_entry_t entry = &table[index]; | |
323 | ipc_entry_bits_t bits; | |
324 | ||
325 | bits = entry->ie_bits; | |
326 | iin->iin_name = MACH_PORT_MAKE(index, IE_BITS_GEN(bits)); | |
327 | iin->iin_collision = (bits & IE_BITS_COLLISION) ? TRUE : FALSE; | |
328 | iin->iin_type = IE_BITS_TYPE(bits); | |
6d2010ae A |
329 | if ((entry->ie_bits & MACH_PORT_TYPE_PORT_RIGHTS) != MACH_PORT_TYPE_NONE && |
330 | entry->ie_request != IE_REQ_NONE) { | |
331 | ipc_port_t port = (ipc_port_t) entry->ie_object; | |
332 | ||
333 | assert(IP_VALID(port)); | |
334 | ip_lock(port); | |
335 | iin->iin_type |= ipc_port_request_type(port, iin->iin_name, entry->ie_request); | |
336 | ip_unlock(port); | |
337 | } | |
338 | ||
1c79356b | 339 | iin->iin_urefs = IE_BITS_UREFS(bits); |
b0d623f7 | 340 | iin->iin_object = (natural_t)(uintptr_t)entry->ie_object; |
1c79356b A |
341 | iin->iin_next = entry->ie_next; |
342 | iin->iin_hash = entry->ie_index; | |
343 | } | |
344 | ||
2d21ac55 A |
345 | /* walk the splay tree for this space */ |
346 | tree_info = (ipc_info_tree_name_array_t)tree_addr; | |
1c79356b A |
347 | for (tentry = ipc_splay_traverse_start(&space->is_tree), index = 0; |
348 | tentry != ITE_NULL; | |
349 | tentry = ipc_splay_traverse_next(&space->is_tree, FALSE)) { | |
350 | ipc_info_tree_name_t *iitn = &tree_info[index++]; | |
351 | ipc_info_name_t *iin = &iitn->iitn_name; | |
352 | ipc_entry_t entry = &tentry->ite_entry; | |
353 | ipc_entry_bits_t bits = entry->ie_bits; | |
354 | ||
355 | assert(IE_BITS_TYPE(bits) != MACH_PORT_TYPE_NONE); | |
356 | ||
357 | iin->iin_name = tentry->ite_name; | |
358 | iin->iin_collision = (bits & IE_BITS_COLLISION) ? TRUE : FALSE; | |
359 | iin->iin_type = IE_BITS_TYPE(bits); | |
6d2010ae A |
360 | if ((entry->ie_bits & MACH_PORT_TYPE_PORT_RIGHTS) != MACH_PORT_TYPE_NONE && |
361 | entry->ie_request != IE_REQ_NONE) { | |
362 | ipc_port_t port = (ipc_port_t) entry->ie_object; | |
363 | ||
364 | assert(IP_VALID(port)); | |
365 | ip_lock(port); | |
366 | iin->iin_type |= ipc_port_request_type(port, iin->iin_name, entry->ie_request); | |
367 | ip_unlock(port); | |
368 | } | |
369 | ||
1c79356b | 370 | iin->iin_urefs = IE_BITS_UREFS(bits); |
b0d623f7 | 371 | iin->iin_object = (natural_t)(uintptr_t)entry->ie_object; |
1c79356b A |
372 | iin->iin_next = entry->ie_next; |
373 | iin->iin_hash = entry->ie_index; | |
374 | ||
375 | if (tentry->ite_lchild == ITE_NULL) | |
376 | iitn->iitn_lchild = MACH_PORT_NULL; | |
377 | else | |
378 | iitn->iitn_lchild = tentry->ite_lchild->ite_name; | |
379 | ||
380 | if (tentry->ite_rchild == ITE_NULL) | |
381 | iitn->iitn_rchild = MACH_PORT_NULL; | |
382 | else | |
383 | iitn->iitn_rchild = tentry->ite_rchild->ite_name; | |
384 | ||
385 | } | |
386 | ipc_splay_traverse_finish(&space->is_tree); | |
387 | is_read_unlock(space); | |
388 | ||
2d21ac55 A |
389 | /* prepare the table out-of-line data for return */ |
390 | if (table_size > 0) { | |
391 | if (table_size > infop->iis_table_size * sizeof(ipc_info_name_t)) | |
392 | bzero((char *)&table_info[infop->iis_table_size], | |
393 | table_size - infop->iis_table_size * sizeof(ipc_info_name_t)); | |
1c79356b | 394 | |
91447636 | 395 | kr = vm_map_unwire(ipc_kernel_map, vm_map_trunc_page(table_addr), |
2d21ac55 | 396 | vm_map_round_page(table_addr + table_size), FALSE); |
1c79356b | 397 | assert(kr == KERN_SUCCESS); |
91447636 | 398 | kr = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)table_addr, |
2d21ac55 | 399 | (vm_map_size_t)table_size, TRUE, ©); |
1c79356b | 400 | assert(kr == KERN_SUCCESS); |
2d21ac55 A |
401 | *tablep = (ipc_info_name_t *)copy; |
402 | *tableCntp = infop->iis_table_size; | |
1c79356b | 403 | } else { |
2d21ac55 A |
404 | *tablep = (ipc_info_name_t *)0; |
405 | *tableCntp = 0; | |
406 | } | |
1c79356b | 407 | |
2d21ac55 A |
408 | /* prepare the tree out-of-line data for return */ |
409 | if (tree_size > 0) { | |
410 | if (tree_size > infop->iis_tree_size * sizeof(ipc_info_tree_name_t)) | |
411 | bzero((char *)&tree_info[infop->iis_tree_size], | |
412 | tree_size - infop->iis_tree_size * sizeof(ipc_info_tree_name_t)); | |
1c79356b | 413 | |
91447636 | 414 | kr = vm_map_unwire(ipc_kernel_map, vm_map_trunc_page(tree_addr), |
2d21ac55 | 415 | vm_map_round_page(tree_addr + tree_size), FALSE); |
1c79356b | 416 | assert(kr == KERN_SUCCESS); |
2d21ac55 A |
417 | kr = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)tree_addr, |
418 | (vm_map_size_t)tree_size, TRUE, ©); | |
1c79356b | 419 | assert(kr == KERN_SUCCESS); |
2d21ac55 A |
420 | *treep = (ipc_info_tree_name_t *)copy; |
421 | *treeCntp = infop->iis_tree_size; | |
422 | } else { | |
423 | *treep = (ipc_info_tree_name_t *)0; | |
424 | *treeCntp = 0; | |
1c79356b | 425 | } |
1c79356b | 426 | return KERN_SUCCESS; |
1c79356b | 427 | } |
91447636 | 428 | #endif /* MACH_IPC_DEBUG */ |
1c79356b A |
429 | |
430 | /* | |
431 | * Routine: mach_port_dnrequest_info | |
432 | * Purpose: | |
433 | * Returns information about the dead-name requests | |
434 | * registered with the named receive right. | |
435 | * Conditions: | |
436 | * Nothing locked. | |
437 | * Returns: | |
438 | * KERN_SUCCESS Retrieved information. | |
439 | * KERN_INVALID_TASK The space is null. | |
440 | * KERN_INVALID_TASK The space is dead. | |
441 | * KERN_INVALID_NAME The name doesn't denote a right. | |
442 | * KERN_INVALID_RIGHT Name doesn't denote receive rights. | |
443 | */ | |
444 | ||
91447636 | 445 | #if !MACH_IPC_DEBUG |
1c79356b A |
446 | kern_return_t |
447 | mach_port_dnrequest_info( | |
91447636 A |
448 | __unused ipc_space_t space, |
449 | __unused mach_port_name_t name, | |
450 | __unused unsigned int *totalp, | |
451 | __unused unsigned int *usedp) | |
1c79356b | 452 | { |
1c79356b | 453 | return KERN_FAILURE; |
91447636 | 454 | } |
1c79356b | 455 | #else |
91447636 A |
456 | kern_return_t |
457 | mach_port_dnrequest_info( | |
458 | ipc_space_t space, | |
459 | mach_port_name_t name, | |
460 | unsigned int *totalp, | |
461 | unsigned int *usedp) | |
462 | { | |
1c79356b A |
463 | unsigned int total, used; |
464 | ipc_port_t port; | |
465 | kern_return_t kr; | |
466 | ||
467 | if (space == IS_NULL) | |
468 | return KERN_INVALID_TASK; | |
469 | ||
470 | kr = ipc_port_translate_receive(space, name, &port); | |
471 | if (kr != KERN_SUCCESS) | |
472 | return kr; | |
473 | /* port is locked and active */ | |
474 | ||
6d2010ae | 475 | if (port->ip_requests == IPR_NULL) { |
1c79356b A |
476 | total = 0; |
477 | used = 0; | |
478 | } else { | |
6d2010ae | 479 | ipc_port_request_t requests = port->ip_requests; |
1c79356b A |
480 | ipc_port_request_index_t index; |
481 | ||
6d2010ae | 482 | total = requests->ipr_size->its_size; |
1c79356b A |
483 | |
484 | for (index = 1, used = 0; | |
485 | index < total; index++) { | |
6d2010ae | 486 | ipc_port_request_t ipr = &requests[index]; |
1c79356b A |
487 | |
488 | if (ipr->ipr_name != MACH_PORT_NULL) | |
489 | used++; | |
490 | } | |
491 | } | |
492 | ip_unlock(port); | |
493 | ||
494 | *totalp = total; | |
495 | *usedp = used; | |
496 | return KERN_SUCCESS; | |
1c79356b | 497 | } |
91447636 | 498 | #endif /* MACH_IPC_DEBUG */ |
1c79356b A |
499 | |
500 | /* | |
b0d623f7 | 501 | * Routine: mach_port_kobject [kernel call] |
1c79356b A |
502 | * Purpose: |
503 | * Retrieve the type and address of the kernel object | |
b0d623f7 A |
504 | * represented by a send or receive right. Returns |
505 | * the kernel address in a mach_vm_address_t to | |
506 | * mask potential differences in kernel address space | |
507 | * size. | |
1c79356b A |
508 | * Conditions: |
509 | * Nothing locked. | |
510 | * Returns: | |
511 | * KERN_SUCCESS Retrieved kernel object info. | |
512 | * KERN_INVALID_TASK The space is null. | |
513 | * KERN_INVALID_TASK The space is dead. | |
514 | * KERN_INVALID_NAME The name doesn't denote a right. | |
515 | * KERN_INVALID_RIGHT Name doesn't denote | |
516 | * send or receive rights. | |
517 | */ | |
518 | ||
91447636 | 519 | #if !MACH_IPC_DEBUG |
1c79356b | 520 | kern_return_t |
b0d623f7 | 521 | mach_port_kobject( |
91447636 A |
522 | __unused ipc_space_t space, |
523 | __unused mach_port_name_t name, | |
b0d623f7 A |
524 | __unused natural_t *typep, |
525 | __unused mach_vm_address_t *addrp) | |
1c79356b | 526 | { |
1c79356b | 527 | return KERN_FAILURE; |
91447636 | 528 | } |
1c79356b | 529 | #else |
91447636 | 530 | kern_return_t |
b0d623f7 | 531 | mach_port_kobject( |
91447636 A |
532 | ipc_space_t space, |
533 | mach_port_name_t name, | |
b0d623f7 A |
534 | natural_t *typep, |
535 | mach_vm_address_t *addrp) | |
91447636 | 536 | { |
1c79356b A |
537 | ipc_entry_t entry; |
538 | ipc_port_t port; | |
539 | kern_return_t kr; | |
540 | ||
2d21ac55 A |
541 | if (space == IS_NULL) |
542 | return KERN_INVALID_TASK; | |
543 | ||
1c79356b A |
544 | kr = ipc_right_lookup_read(space, name, &entry); |
545 | if (kr != KERN_SUCCESS) | |
546 | return kr; | |
547 | /* space is read-locked and active */ | |
548 | ||
549 | if ((entry->ie_bits & MACH_PORT_TYPE_SEND_RECEIVE) == 0) { | |
550 | is_read_unlock(space); | |
551 | return KERN_INVALID_RIGHT; | |
552 | } | |
553 | ||
554 | port = (ipc_port_t) entry->ie_object; | |
555 | assert(port != IP_NULL); | |
556 | ||
557 | ip_lock(port); | |
558 | is_read_unlock(space); | |
559 | ||
560 | if (!ip_active(port)) { | |
561 | ip_unlock(port); | |
562 | return KERN_INVALID_RIGHT; | |
563 | } | |
564 | ||
565 | *typep = (unsigned int) ip_kotype(port); | |
b0d623f7 | 566 | *addrp = (mach_vm_address_t)port->ip_kobject; |
1c79356b A |
567 | ip_unlock(port); |
568 | return KERN_SUCCESS; | |
569 | ||
1c79356b | 570 | } |
91447636 | 571 | #endif /* MACH_IPC_DEBUG */ |
b0d623f7 A |
572 | /* |
573 | * Routine: mach_port_kernel_object [Legacy kernel call] | |
574 | * Purpose: | |
575 | * Retrieve the type and address of the kernel object | |
576 | * represented by a send or receive right. Hard-coded | |
577 | * to return only the low-order 32-bits of the kernel | |
578 | * object. | |
579 | * Conditions: | |
580 | * Nothing locked. | |
581 | * Returns: | |
582 | * KERN_SUCCESS Retrieved kernel object info. | |
583 | * KERN_INVALID_TASK The space is null. | |
584 | * KERN_INVALID_TASK The space is dead. | |
585 | * KERN_INVALID_NAME The name doesn't denote a right. | |
586 | * KERN_INVALID_RIGHT Name doesn't denote | |
587 | * send or receive rights. | |
588 | */ | |
589 | ||
590 | #if !MACH_IPC_DEBUG | |
591 | kern_return_t | |
592 | mach_port_kernel_object( | |
593 | __unused ipc_space_t space, | |
594 | __unused mach_port_name_t name, | |
595 | __unused unsigned int *typep, | |
596 | __unused unsigned int *addrp) | |
597 | { | |
598 | return KERN_FAILURE; | |
599 | } | |
600 | #else | |
601 | kern_return_t | |
602 | mach_port_kernel_object( | |
603 | ipc_space_t space, | |
604 | mach_port_name_t name, | |
605 | unsigned int *typep, | |
606 | unsigned int *addrp) | |
607 | { | |
608 | mach_vm_address_t addr = 0; | |
609 | kern_return_t kr; | |
610 | ||
611 | kr = mach_port_kobject(space, name, typep, &addr); | |
612 | *addrp = (unsigned int) addr; | |
613 | return kr; | |
614 | } | |
615 | #endif /* MACH_IPC_DEBUG */ |