]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ipc/mach_debug.c
xnu-7195.81.3.tar.gz
[apple/xnu.git] / osfmk / ipc / mach_debug.c
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 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.
0a7de745 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.
0a7de745 17 *
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
0a7de745 31/*
1c79356b
A
32 * Mach Operating System
33 * Copyright (c) 1991,1990 Carnegie Mellon University
34 * All Rights Reserved.
0a7de745 35 *
1c79356b
A
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.
0a7de745 41 *
1c79356b
A
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.
0a7de745 45 *
1c79356b 46 * Carnegie Mellon requests users of this software to return to
0a7de745 47 *
1c79356b
A
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
0a7de745 52 *
1c79356b
A
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>
3e170ce0
A
87
88#include <security/mac_mach_internal.h>
ea3f0419 89#include <device/device_types.h>
1c79356b
A
90#endif
91
92/*
93 * Routine: mach_port_get_srights [kernel call]
94 * Purpose:
95 * Retrieve the number of extant send rights
96 * that a receive right has.
97 * Conditions:
98 * Nothing locked.
99 * Returns:
100 * KERN_SUCCESS Retrieved number of send rights.
101 * KERN_INVALID_TASK The space is null.
102 * KERN_INVALID_TASK The space is dead.
103 * KERN_INVALID_NAME The name doesn't denote a right.
104 * KERN_INVALID_RIGHT Name doesn't denote receive rights.
105 */
106
91447636
A
107#if !MACH_IPC_DEBUG
108kern_return_t
109mach_port_get_srights(
0a7de745
A
110 __unused ipc_space_t space,
111 __unused mach_port_name_t name,
112 __unused mach_port_rights_t *srightsp)
91447636 113{
0a7de745 114 return KERN_FAILURE;
91447636
A
115}
116#else
1c79356b
A
117kern_return_t
118mach_port_get_srights(
0a7de745
A
119 ipc_space_t space,
120 mach_port_name_t name,
121 mach_port_rights_t *srightsp)
1c79356b 122{
1c79356b
A
123 ipc_port_t port;
124 kern_return_t kr;
125 mach_port_rights_t srights;
126
0a7de745 127 if (space == IS_NULL) {
1c79356b 128 return KERN_INVALID_TASK;
0a7de745 129 }
1c79356b
A
130
131 kr = ipc_port_translate_receive(space, name, &port);
0a7de745 132 if (kr != KERN_SUCCESS) {
1c79356b 133 return kr;
0a7de745 134 }
1c79356b
A
135 /* port is locked and active */
136
137 srights = port->ip_srights;
138 ip_unlock(port);
139
140 *srightsp = srights;
141 return KERN_SUCCESS;
1c79356b 142}
91447636 143#endif /* MACH_IPC_DEBUG */
1c79356b 144
1c79356b
A
145
146/*
147 * Routine: mach_port_space_info
148 * Purpose:
149 * Returns information about an IPC space.
150 * Conditions:
151 * Nothing locked. Obeys CountInOut protocol.
152 * Returns:
153 * KERN_SUCCESS Returned information.
154 * KERN_INVALID_TASK The space is null.
155 * KERN_INVALID_TASK The space is dead.
156 * KERN_RESOURCE_SHORTAGE Couldn't allocate memory.
157 */
158
91447636 159#if !MACH_IPC_DEBUG
1c79356b 160kern_return_t
f427ee49
A
161mach_port_space_info_from_user(
162 __unused mach_port_t port,
0a7de745
A
163 __unused ipc_info_space_t *infop,
164 __unused ipc_info_name_array_t *tablep,
165 __unused mach_msg_type_number_t *tableCntp,
91447636 166 __unused ipc_info_tree_name_array_t *treep,
0a7de745 167 __unused mach_msg_type_number_t *treeCntp)
91447636 168{
0a7de745 169 return KERN_FAILURE;
91447636 170}
f427ee49 171
91447636 172#else
f427ee49
A
173kern_return_t
174mach_port_space_info(
175 ipc_space_t space,
176 ipc_info_space_t *infop,
177 ipc_info_name_array_t *tablep,
178 mach_msg_type_number_t *tableCntp,
179 __unused ipc_info_tree_name_array_t *treep,
180 __unused mach_msg_type_number_t *treeCntp);
181
91447636
A
182kern_return_t
183mach_port_space_info(
0a7de745
A
184 ipc_space_t space,
185 ipc_info_space_t *infop,
186 ipc_info_name_array_t *tablep,
187 mach_msg_type_number_t *tableCntp,
188 __unused ipc_info_tree_name_array_t *treep,
316670eb 189 __unused mach_msg_type_number_t *treeCntp)
1c79356b 190{
1c79356b 191 ipc_info_name_t *table_info;
1c79356b 192 vm_offset_t table_addr;
2d21ac55 193 vm_size_t table_size, table_size_needed;
1c79356b
A
194 ipc_entry_t table;
195 ipc_entry_num_t tsize;
196 mach_port_index_t index;
197 kern_return_t kr;
2d21ac55
A
198 vm_map_copy_t copy;
199
1c79356b 200
0a7de745 201 if (space == IS_NULL) {
1c79356b 202 return KERN_INVALID_TASK;
0a7de745 203 }
1c79356b 204
39037602 205#if !(DEVELOPMENT || DEBUG) && CONFIG_MACF
3e170ce0
A
206 const boolean_t dbg_ok = (mac_task_check_expose_task(kernel_task) == 0);
207#else
208 const boolean_t dbg_ok = TRUE;
209#endif
210
1c79356b
A
211 /* start with in-line memory */
212
91447636 213 table_size = 0;
1c79356b
A
214
215 for (;;) {
216 is_read_lock(space);
316670eb 217 if (!is_active(space)) {
1c79356b 218 is_read_unlock(space);
0a7de745 219 if (table_size != 0) {
1c79356b 220 kmem_free(ipc_kernel_map,
0a7de745
A
221 table_addr, table_size);
222 }
1c79356b
A
223 return KERN_INVALID_TASK;
224 }
225
39236c6e 226 table_size_needed =
0a7de745
A
227 vm_map_round_page((space->is_table_size
228 * sizeof(ipc_info_name_t)),
229 VM_MAP_PAGE_MASK(ipc_kernel_map));
1c79356b 230
0a7de745 231 if (table_size_needed == table_size) {
1c79356b 232 break;
0a7de745 233 }
1c79356b
A
234
235 is_read_unlock(space);
236
2d21ac55 237 if (table_size != table_size_needed) {
0a7de745 238 if (table_size != 0) {
2d21ac55 239 kmem_free(ipc_kernel_map, table_addr, table_size);
0a7de745
A
240 }
241 kr = kmem_alloc(ipc_kernel_map, &table_addr, table_size_needed, VM_KERN_MEMORY_IPC);
1c79356b 242 if (kr != KERN_SUCCESS) {
1c79356b
A
243 return KERN_RESOURCE_SHORTAGE;
244 }
2d21ac55 245 table_size = table_size_needed;
1c79356b 246 }
1c79356b
A
247 }
248 /* space is read-locked and active; we have enough wired memory */
249
2d21ac55 250 /* get the overall space info */
1c79356b
A
251 infop->iis_genno_mask = MACH_PORT_NGEN(MACH_PORT_DEAD);
252 infop->iis_table_size = space->is_table_size;
253 infop->iis_table_next = space->is_table_next->its_size;
1c79356b 254
2d21ac55 255 /* walk the table for this space */
1c79356b
A
256 table = space->is_table;
257 tsize = space->is_table_size;
2d21ac55 258 table_info = (ipc_info_name_array_t)table_addr;
1c79356b
A
259 for (index = 0; index < tsize; index++) {
260 ipc_info_name_t *iin = &table_info[index];
261 ipc_entry_t entry = &table[index];
262 ipc_entry_bits_t bits;
263
264 bits = entry->ie_bits;
265 iin->iin_name = MACH_PORT_MAKE(index, IE_BITS_GEN(bits));
39236c6e 266 iin->iin_collision = 0;
1c79356b 267 iin->iin_type = IE_BITS_TYPE(bits);
6d2010ae
A
268 if ((entry->ie_bits & MACH_PORT_TYPE_PORT_RIGHTS) != MACH_PORT_TYPE_NONE &&
269 entry->ie_request != IE_REQ_NONE) {
cb323159 270 ipc_port_t port = ip_object_to_port(entry->ie_object);
6d2010ae
A
271
272 assert(IP_VALID(port));
273 ip_lock(port);
274 iin->iin_type |= ipc_port_request_type(port, iin->iin_name, entry->ie_request);
275 ip_unlock(port);
276 }
277
1c79356b 278 iin->iin_urefs = IE_BITS_UREFS(bits);
3e170ce0 279 iin->iin_object = (dbg_ok) ? (natural_t)VM_KERNEL_ADDRPERM((uintptr_t)entry->ie_object) : 0;
1c79356b
A
280 iin->iin_next = entry->ie_next;
281 iin->iin_hash = entry->ie_index;
282 }
283
1c79356b
A
284 is_read_unlock(space);
285
2d21ac55
A
286 /* prepare the table out-of-line data for return */
287 if (table_size > 0) {
2dced7af
A
288 vm_size_t used_table_size;
289
290 used_table_size = infop->iis_table_size * sizeof(ipc_info_name_t);
0a7de745 291 if (table_size > used_table_size) {
2d21ac55 292 bzero((char *)&table_info[infop->iis_table_size],
0a7de745
A
293 table_size - used_table_size);
294 }
1c79356b 295
39236c6e
A
296 kr = vm_map_unwire(
297 ipc_kernel_map,
298 vm_map_trunc_page(table_addr,
0a7de745 299 VM_MAP_PAGE_MASK(ipc_kernel_map)),
39236c6e 300 vm_map_round_page(table_addr + table_size,
0a7de745 301 VM_MAP_PAGE_MASK(ipc_kernel_map)),
39236c6e 302 FALSE);
1c79356b 303 assert(kr == KERN_SUCCESS);
0a7de745
A
304 kr = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)table_addr,
305 (vm_map_size_t)used_table_size, TRUE, &copy);
1c79356b 306 assert(kr == KERN_SUCCESS);
2d21ac55
A
307 *tablep = (ipc_info_name_t *)copy;
308 *tableCntp = infop->iis_table_size;
1c79356b 309 } else {
2d21ac55
A
310 *tablep = (ipc_info_name_t *)0;
311 *tableCntp = 0;
312 }
1c79356b 313
316670eb
A
314 /* splay tree is obsolete, no work to do... */
315 *treep = (ipc_info_tree_name_t *)0;
316 *treeCntp = 0;
1c79356b 317 return KERN_SUCCESS;
1c79356b 318}
f427ee49
A
319
320kern_return_t
321mach_port_space_info_from_user(
322 mach_port_t port,
323 ipc_info_space_t *infop,
324 ipc_info_name_array_t *tablep,
325 mach_msg_type_number_t *tableCntp,
326 __unused ipc_info_tree_name_array_t *treep,
327 __unused mach_msg_type_number_t *treeCntp)
328{
329 kern_return_t kr;
330
331 ipc_space_t space = convert_port_to_space_check_type(port, NULL, TASK_FLAVOR_READ, FALSE);
332
333 if (space == IPC_SPACE_NULL) {
334 return KERN_INVALID_ARGUMENT;
335 }
336
337 kr = mach_port_space_info(space, infop, tablep, tableCntp, treep, treeCntp);
338
339 ipc_space_release(space);
340 return kr;
341}
91447636 342#endif /* MACH_IPC_DEBUG */
1c79356b 343
fe8ab488
A
344/*
345 * Routine: mach_port_space_basic_info
346 * Purpose:
347 * Returns basic information about an IPC space.
348 * Conditions:
349 * Nothing locked.
350 * Returns:
351 * KERN_SUCCESS Returned information.
352 * KERN_FAILURE The call is not supported.
353 * KERN_INVALID_TASK The space is dead.
354 */
355
356#if !MACH_IPC_DEBUG
357kern_return_t
358mach_port_space_basic_info(
0a7de745
A
359 __unused ipc_space_t space,
360 __unused ipc_info_space_basic_t *infop)
fe8ab488 361{
0a7de745 362 return KERN_FAILURE;
fe8ab488
A
363}
364#else
365kern_return_t
366mach_port_space_basic_info(
0a7de745
A
367 ipc_space_t space,
368 ipc_info_space_basic_t *infop)
fe8ab488 369{
0a7de745 370 if (space == IS_NULL) {
fe8ab488 371 return KERN_INVALID_TASK;
0a7de745 372 }
fe8ab488 373
3e170ce0 374
fe8ab488
A
375 is_read_lock(space);
376 if (!is_active(space)) {
377 is_read_unlock(space);
378 return KERN_INVALID_TASK;
379 }
380
381 /* get the basic space info */
382 infop->iisb_genno_mask = MACH_PORT_NGEN(MACH_PORT_DEAD);
383 infop->iisb_table_size = space->is_table_size;
384 infop->iisb_table_next = space->is_table_next->its_size;
385 infop->iisb_table_inuse = space->is_table_size - space->is_table_free - 1;
386 infop->iisb_reserved[0] = 0;
387 infop->iisb_reserved[1] = 0;
388
389 is_read_unlock(space);
390
391 return KERN_SUCCESS;
392}
393#endif /* MACH_IPC_DEBUG */
394
1c79356b
A
395/*
396 * Routine: mach_port_dnrequest_info
397 * Purpose:
398 * Returns information about the dead-name requests
399 * registered with the named receive right.
400 * Conditions:
401 * Nothing locked.
402 * Returns:
403 * KERN_SUCCESS Retrieved information.
404 * KERN_INVALID_TASK The space is null.
405 * KERN_INVALID_TASK The space is dead.
406 * KERN_INVALID_NAME The name doesn't denote a right.
407 * KERN_INVALID_RIGHT Name doesn't denote receive rights.
408 */
409
91447636 410#if !MACH_IPC_DEBUG
1c79356b
A
411kern_return_t
412mach_port_dnrequest_info(
0a7de745
A
413 __unused ipc_space_t space,
414 __unused mach_port_name_t name,
415 __unused unsigned int *totalp,
416 __unused unsigned int *usedp)
1c79356b 417{
0a7de745 418 return KERN_FAILURE;
91447636 419}
1c79356b 420#else
91447636
A
421kern_return_t
422mach_port_dnrequest_info(
0a7de745
A
423 ipc_space_t space,
424 mach_port_name_t name,
425 unsigned int *totalp,
426 unsigned int *usedp)
91447636 427{
1c79356b
A
428 unsigned int total, used;
429 ipc_port_t port;
430 kern_return_t kr;
431
0a7de745 432 if (space == IS_NULL) {
1c79356b 433 return KERN_INVALID_TASK;
0a7de745 434 }
1c79356b
A
435
436 kr = ipc_port_translate_receive(space, name, &port);
0a7de745 437 if (kr != KERN_SUCCESS) {
1c79356b 438 return kr;
0a7de745 439 }
1c79356b
A
440 /* port is locked and active */
441
6d2010ae 442 if (port->ip_requests == IPR_NULL) {
1c79356b
A
443 total = 0;
444 used = 0;
445 } else {
6d2010ae 446 ipc_port_request_t requests = port->ip_requests;
1c79356b
A
447 ipc_port_request_index_t index;
448
6d2010ae 449 total = requests->ipr_size->its_size;
1c79356b
A
450
451 for (index = 1, used = 0;
0a7de745 452 index < total; index++) {
6d2010ae 453 ipc_port_request_t ipr = &requests[index];
1c79356b 454
0a7de745 455 if (ipr->ipr_name != MACH_PORT_NULL) {
1c79356b 456 used++;
0a7de745 457 }
1c79356b
A
458 }
459 }
460 ip_unlock(port);
461
462 *totalp = total;
463 *usedp = used;
464 return KERN_SUCCESS;
1c79356b 465}
91447636 466#endif /* MACH_IPC_DEBUG */
1c79356b
A
467
468/*
b0d623f7 469 * Routine: mach_port_kobject [kernel call]
1c79356b
A
470 * Purpose:
471 * Retrieve the type and address of the kernel object
b0d623f7
A
472 * represented by a send or receive right. Returns
473 * the kernel address in a mach_vm_address_t to
474 * mask potential differences in kernel address space
475 * size.
1c79356b
A
476 * Conditions:
477 * Nothing locked.
478 * Returns:
479 * KERN_SUCCESS Retrieved kernel object info.
480 * KERN_INVALID_TASK The space is null.
481 * KERN_INVALID_TASK The space is dead.
482 * KERN_INVALID_NAME The name doesn't denote a right.
483 * KERN_INVALID_RIGHT Name doesn't denote
484 * send or receive rights.
485 */
486
91447636 487#if !MACH_IPC_DEBUG
1c79356b 488kern_return_t
f427ee49
A
489mach_port_kobject_from_user(
490 __unused mach_port_t port,
491 __unused mach_port_name_t name,
492 __unused natural_t *typep,
493 __unused mach_vm_address_t *addrp)
494{
495 return KERN_FAILURE;
496}
497
498kern_return_t
499mach_port_kobject_description_from_user(
500 __unused mach_port_t port,
0a7de745
A
501 __unused mach_port_name_t name,
502 __unused natural_t *typep,
ea3f0419 503 __unused mach_vm_address_t *addrp,
f427ee49 504 __unused kobject_description_t des)
1c79356b 505{
0a7de745 506 return KERN_FAILURE;
91447636 507}
1c79356b 508#else
f427ee49
A
509kern_return_t
510mach_port_kobject_description(
511 ipc_space_t space,
512 mach_port_name_t name,
513 natural_t *typep,
514 mach_vm_address_t *addrp,
515 kobject_description_t desc);
516
91447636 517kern_return_t
ea3f0419 518mach_port_kobject_description(
0a7de745
A
519 ipc_space_t space,
520 mach_port_name_t name,
521 natural_t *typep,
ea3f0419
A
522 mach_vm_address_t *addrp,
523 kobject_description_t desc)
91447636 524{
1c79356b
A
525 ipc_entry_t entry;
526 ipc_port_t port;
527 kern_return_t kr;
316670eb 528 mach_vm_address_t kaddr;
f427ee49 529 io_object_t obj = NULL;
1c79356b 530
0a7de745 531 if (space == IS_NULL) {
2d21ac55 532 return KERN_INVALID_TASK;
0a7de745 533 }
2d21ac55 534
1c79356b 535 kr = ipc_right_lookup_read(space, name, &entry);
0a7de745 536 if (kr != KERN_SUCCESS) {
1c79356b 537 return kr;
0a7de745 538 }
1c79356b
A
539 /* space is read-locked and active */
540
541 if ((entry->ie_bits & MACH_PORT_TYPE_SEND_RECEIVE) == 0) {
542 is_read_unlock(space);
543 return KERN_INVALID_RIGHT;
544 }
545
cb323159 546 port = ip_object_to_port(entry->ie_object);
1c79356b
A
547 assert(port != IP_NULL);
548
549 ip_lock(port);
550 is_read_unlock(space);
551
552 if (!ip_active(port)) {
553 ip_unlock(port);
554 return KERN_INVALID_RIGHT;
555 }
556
557 *typep = (unsigned int) ip_kotype(port);
ea3f0419 558 kaddr = (mach_vm_address_t)ip_get_kobject(port);
cb323159 559 *addrp = 0;
ea3f0419 560
ea3f0419
A
561 if (desc) {
562 *desc = '\0';
f427ee49 563 switch (ip_kotype(port)) {
ea3f0419
A
564 case IKOT_IOKIT_OBJECT:
565 case IKOT_IOKIT_CONNECT:
566 case IKOT_IOKIT_IDENT:
567 case IKOT_UEXT_OBJECT:
568 obj = (io_object_t) kaddr;
569 iokit_add_reference(obj, IKOT_IOKIT_OBJECT);
570 break;
571
572 default:
573 break;
574 }
575 }
f427ee49
A
576#if (DEVELOPMENT || DEBUG)
577 *addrp = VM_KERNEL_UNSLIDE_OR_PERM(kaddr);
578#endif
ea3f0419 579
cb323159 580 ip_unlock(port);
316670eb 581
ea3f0419
A
582 if (obj) {
583 iokit_port_object_description(obj, desc);
584 iokit_remove_reference(obj);
585 }
586
316670eb 587 return KERN_SUCCESS;
1c79356b 588}
f427ee49
A
589
590kern_return_t
591mach_port_kobject(
592 ipc_space_t space,
593 mach_port_name_t name,
594 natural_t *typep,
595 mach_vm_address_t *addrp);
cb323159 596
ea3f0419
A
597kern_return_t
598mach_port_kobject(
599 ipc_space_t space,
600 mach_port_name_t name,
601 natural_t *typep,
602 mach_vm_address_t *addrp)
603{
604 return mach_port_kobject_description(space, name, typep, addrp, NULL);
605}
606
f427ee49
A
607kern_return_t
608mach_port_kobject_description_from_user(
609 mach_port_t port,
610 mach_port_name_t name,
611 natural_t *typep,
612 mach_vm_address_t *addrp,
613 kobject_description_t desc)
614{
615 kern_return_t kr;
616
617 ipc_space_t space = convert_port_to_space_check_type(port, NULL, TASK_FLAVOR_READ, FALSE);
618
619 if (space == IPC_SPACE_NULL) {
620 return KERN_INVALID_ARGUMENT;
621 }
622
623 kr = mach_port_kobject_description(space, name, typep, addrp, desc);
624
625 ipc_space_release(space);
626 return kr;
627}
628
629kern_return_t
630mach_port_kobject_from_user(
631 mach_port_t port,
632 mach_port_name_t name,
633 natural_t *typep,
634 mach_vm_address_t *addrp)
635{
636 return mach_port_kobject_description_from_user(port, name, typep, addrp, NULL);
637}
638
639#endif /* MACH_IPC_DEBUG */
640
b0d623f7
A
641/*
642 * Routine: mach_port_kernel_object [Legacy kernel call]
643 * Purpose:
644 * Retrieve the type and address of the kernel object
645 * represented by a send or receive right. Hard-coded
646 * to return only the low-order 32-bits of the kernel
647 * object.
648 * Conditions:
649 * Nothing locked.
650 * Returns:
651 * KERN_SUCCESS Retrieved kernel object info.
652 * KERN_INVALID_TASK The space is null.
653 * KERN_INVALID_TASK The space is dead.
654 * KERN_INVALID_NAME The name doesn't denote a right.
655 * KERN_INVALID_RIGHT Name doesn't denote
656 * send or receive rights.
657 */
658
659#if !MACH_IPC_DEBUG
660kern_return_t
f427ee49
A
661mach_port_kernel_object_from_user(
662 __unused mach_port_t port,
0a7de745
A
663 __unused mach_port_name_t name,
664 __unused unsigned int *typep,
665 __unused unsigned int *addrp)
b0d623f7 666{
0a7de745 667 return KERN_FAILURE;
b0d623f7
A
668}
669#else
f427ee49
A
670kern_return_t
671mach_port_kernel_object(
672 ipc_space_t space,
673 mach_port_name_t name,
674 unsigned int *typep,
675 unsigned int *addrp);
676
b0d623f7
A
677kern_return_t
678mach_port_kernel_object(
0a7de745
A
679 ipc_space_t space,
680 mach_port_name_t name,
681 unsigned int *typep,
682 unsigned int *addrp)
b0d623f7
A
683{
684 mach_vm_address_t addr = 0;
685 kern_return_t kr;
686
687 kr = mach_port_kobject(space, name, typep, &addr);
688 *addrp = (unsigned int) addr;
689 return kr;
690}
f427ee49
A
691
692kern_return_t
693mach_port_kernel_object_from_user(
694 mach_port_t port,
695 mach_port_name_t name,
696 unsigned int *typep,
697 unsigned int *addrp)
698{
699 kern_return_t kr;
700
701 ipc_space_t space = convert_port_to_space_check_type(port, NULL, TASK_FLAVOR_READ, FALSE);
702
703 if (space == IPC_SPACE_NULL) {
704 return KERN_INVALID_ARGUMENT;
705 }
706
707 kr = mach_port_kernel_object(space, name, typep, addrp);
708
709 ipc_space_release(space);
710 return kr;
711}
b0d623f7 712#endif /* MACH_IPC_DEBUG */
d9a64523
A
713
714#if (DEVELOPMENT || DEBUG)
715kern_return_t
716mach_port_special_reply_port_reset_link(
717 ipc_space_t space,
718 mach_port_name_t name,
0a7de745 719 boolean_t *srp_lost_link)
d9a64523
A
720{
721 ipc_port_t port;
722 kern_return_t kr;
723 thread_t thread = current_thread();
724
0a7de745 725 if (space != current_space()) {
d9a64523 726 return KERN_INVALID_TASK;
0a7de745 727 }
d9a64523 728
0a7de745 729 if (!MACH_PORT_VALID(name)) {
d9a64523 730 return KERN_INVALID_NAME;
0a7de745 731 }
d9a64523 732
0a7de745 733 if (!IP_VALID(thread->ith_special_reply_port)) {
d9a64523 734 return KERN_INVALID_VALUE;
0a7de745 735 }
d9a64523
A
736
737 kr = ipc_port_translate_receive(space, name, &port);
0a7de745 738 if (kr != KERN_SUCCESS) {
d9a64523 739 return kr;
0a7de745 740 }
d9a64523
A
741
742 if (thread->ith_special_reply_port != port) {
743 ip_unlock(port);
744 return KERN_INVALID_ARGUMENT;
745 }
746
747 imq_lock(&port->ip_messages);
748 *srp_lost_link = (port->ip_srp_lost_link == 1)? TRUE : FALSE;
749 port->ip_srp_lost_link = 0;
750 imq_unlock(&port->ip_messages);
751
752 ip_unlock(port);
753 return KERN_SUCCESS;
754}
755#else
756kern_return_t
757mach_port_special_reply_port_reset_link(
0a7de745
A
758 __unused ipc_space_t space,
759 __unused mach_port_name_t name,
760 __unused boolean_t *srp_lost_link)
d9a64523
A
761{
762 return KERN_NOT_SUPPORTED;
763}
764#endif