]>
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@ |
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 |
108 | kern_return_t | |
109 | mach_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 |
117 | kern_return_t |
118 | mach_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 A |
160 | kern_return_t |
161 | mach_port_space_info( | |
0a7de745 A |
162 | __unused ipc_space_t space, |
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 A |
170 | } |
171 | #else | |
172 | kern_return_t | |
173 | mach_port_space_info( | |
0a7de745 A |
174 | ipc_space_t space, |
175 | ipc_info_space_t *infop, | |
176 | ipc_info_name_array_t *tablep, | |
177 | mach_msg_type_number_t *tableCntp, | |
178 | __unused ipc_info_tree_name_array_t *treep, | |
316670eb | 179 | __unused mach_msg_type_number_t *treeCntp) |
1c79356b | 180 | { |
1c79356b | 181 | ipc_info_name_t *table_info; |
1c79356b | 182 | vm_offset_t table_addr; |
2d21ac55 | 183 | vm_size_t table_size, table_size_needed; |
1c79356b A |
184 | ipc_entry_t table; |
185 | ipc_entry_num_t tsize; | |
186 | mach_port_index_t index; | |
187 | kern_return_t kr; | |
2d21ac55 A |
188 | vm_map_copy_t copy; |
189 | ||
1c79356b | 190 | |
0a7de745 | 191 | if (space == IS_NULL) { |
1c79356b | 192 | return KERN_INVALID_TASK; |
0a7de745 | 193 | } |
1c79356b | 194 | |
39037602 | 195 | #if !(DEVELOPMENT || DEBUG) && CONFIG_MACF |
3e170ce0 A |
196 | const boolean_t dbg_ok = (mac_task_check_expose_task(kernel_task) == 0); |
197 | #else | |
198 | const boolean_t dbg_ok = TRUE; | |
199 | #endif | |
200 | ||
1c79356b A |
201 | /* start with in-line memory */ |
202 | ||
91447636 | 203 | table_size = 0; |
1c79356b A |
204 | |
205 | for (;;) { | |
206 | is_read_lock(space); | |
316670eb | 207 | if (!is_active(space)) { |
1c79356b | 208 | is_read_unlock(space); |
0a7de745 | 209 | if (table_size != 0) { |
1c79356b | 210 | kmem_free(ipc_kernel_map, |
0a7de745 A |
211 | table_addr, table_size); |
212 | } | |
1c79356b A |
213 | return KERN_INVALID_TASK; |
214 | } | |
215 | ||
39236c6e | 216 | table_size_needed = |
0a7de745 A |
217 | vm_map_round_page((space->is_table_size |
218 | * sizeof(ipc_info_name_t)), | |
219 | VM_MAP_PAGE_MASK(ipc_kernel_map)); | |
1c79356b | 220 | |
0a7de745 | 221 | if (table_size_needed == table_size) { |
1c79356b | 222 | break; |
0a7de745 | 223 | } |
1c79356b A |
224 | |
225 | is_read_unlock(space); | |
226 | ||
2d21ac55 | 227 | if (table_size != table_size_needed) { |
0a7de745 | 228 | if (table_size != 0) { |
2d21ac55 | 229 | kmem_free(ipc_kernel_map, table_addr, table_size); |
0a7de745 A |
230 | } |
231 | kr = kmem_alloc(ipc_kernel_map, &table_addr, table_size_needed, VM_KERN_MEMORY_IPC); | |
1c79356b | 232 | if (kr != KERN_SUCCESS) { |
1c79356b A |
233 | return KERN_RESOURCE_SHORTAGE; |
234 | } | |
2d21ac55 | 235 | table_size = table_size_needed; |
1c79356b | 236 | } |
1c79356b A |
237 | } |
238 | /* space is read-locked and active; we have enough wired memory */ | |
239 | ||
2d21ac55 | 240 | /* get the overall space info */ |
1c79356b A |
241 | infop->iis_genno_mask = MACH_PORT_NGEN(MACH_PORT_DEAD); |
242 | infop->iis_table_size = space->is_table_size; | |
243 | infop->iis_table_next = space->is_table_next->its_size; | |
1c79356b | 244 | |
2d21ac55 | 245 | /* walk the table for this space */ |
1c79356b A |
246 | table = space->is_table; |
247 | tsize = space->is_table_size; | |
2d21ac55 | 248 | table_info = (ipc_info_name_array_t)table_addr; |
1c79356b A |
249 | for (index = 0; index < tsize; index++) { |
250 | ipc_info_name_t *iin = &table_info[index]; | |
251 | ipc_entry_t entry = &table[index]; | |
252 | ipc_entry_bits_t bits; | |
253 | ||
254 | bits = entry->ie_bits; | |
255 | iin->iin_name = MACH_PORT_MAKE(index, IE_BITS_GEN(bits)); | |
39236c6e | 256 | iin->iin_collision = 0; |
1c79356b | 257 | iin->iin_type = IE_BITS_TYPE(bits); |
6d2010ae A |
258 | if ((entry->ie_bits & MACH_PORT_TYPE_PORT_RIGHTS) != MACH_PORT_TYPE_NONE && |
259 | entry->ie_request != IE_REQ_NONE) { | |
cb323159 | 260 | ipc_port_t port = ip_object_to_port(entry->ie_object); |
6d2010ae A |
261 | |
262 | assert(IP_VALID(port)); | |
263 | ip_lock(port); | |
264 | iin->iin_type |= ipc_port_request_type(port, iin->iin_name, entry->ie_request); | |
265 | ip_unlock(port); | |
266 | } | |
267 | ||
1c79356b | 268 | iin->iin_urefs = IE_BITS_UREFS(bits); |
3e170ce0 | 269 | iin->iin_object = (dbg_ok) ? (natural_t)VM_KERNEL_ADDRPERM((uintptr_t)entry->ie_object) : 0; |
1c79356b A |
270 | iin->iin_next = entry->ie_next; |
271 | iin->iin_hash = entry->ie_index; | |
272 | } | |
273 | ||
1c79356b A |
274 | is_read_unlock(space); |
275 | ||
2d21ac55 A |
276 | /* prepare the table out-of-line data for return */ |
277 | if (table_size > 0) { | |
2dced7af A |
278 | vm_size_t used_table_size; |
279 | ||
280 | used_table_size = infop->iis_table_size * sizeof(ipc_info_name_t); | |
0a7de745 | 281 | if (table_size > used_table_size) { |
2d21ac55 | 282 | bzero((char *)&table_info[infop->iis_table_size], |
0a7de745 A |
283 | table_size - used_table_size); |
284 | } | |
1c79356b | 285 | |
39236c6e A |
286 | kr = vm_map_unwire( |
287 | ipc_kernel_map, | |
288 | vm_map_trunc_page(table_addr, | |
0a7de745 | 289 | VM_MAP_PAGE_MASK(ipc_kernel_map)), |
39236c6e | 290 | vm_map_round_page(table_addr + table_size, |
0a7de745 | 291 | VM_MAP_PAGE_MASK(ipc_kernel_map)), |
39236c6e | 292 | FALSE); |
1c79356b | 293 | assert(kr == KERN_SUCCESS); |
0a7de745 A |
294 | kr = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)table_addr, |
295 | (vm_map_size_t)used_table_size, TRUE, ©); | |
1c79356b | 296 | assert(kr == KERN_SUCCESS); |
2d21ac55 A |
297 | *tablep = (ipc_info_name_t *)copy; |
298 | *tableCntp = infop->iis_table_size; | |
1c79356b | 299 | } else { |
2d21ac55 A |
300 | *tablep = (ipc_info_name_t *)0; |
301 | *tableCntp = 0; | |
302 | } | |
1c79356b | 303 | |
316670eb A |
304 | /* splay tree is obsolete, no work to do... */ |
305 | *treep = (ipc_info_tree_name_t *)0; | |
306 | *treeCntp = 0; | |
1c79356b | 307 | return KERN_SUCCESS; |
1c79356b | 308 | } |
91447636 | 309 | #endif /* MACH_IPC_DEBUG */ |
1c79356b | 310 | |
fe8ab488 A |
311 | /* |
312 | * Routine: mach_port_space_basic_info | |
313 | * Purpose: | |
314 | * Returns basic information about an IPC space. | |
315 | * Conditions: | |
316 | * Nothing locked. | |
317 | * Returns: | |
318 | * KERN_SUCCESS Returned information. | |
319 | * KERN_FAILURE The call is not supported. | |
320 | * KERN_INVALID_TASK The space is dead. | |
321 | */ | |
322 | ||
323 | #if !MACH_IPC_DEBUG | |
324 | kern_return_t | |
325 | mach_port_space_basic_info( | |
0a7de745 A |
326 | __unused ipc_space_t space, |
327 | __unused ipc_info_space_basic_t *infop) | |
fe8ab488 | 328 | { |
0a7de745 | 329 | return KERN_FAILURE; |
fe8ab488 A |
330 | } |
331 | #else | |
332 | kern_return_t | |
333 | mach_port_space_basic_info( | |
0a7de745 A |
334 | ipc_space_t space, |
335 | ipc_info_space_basic_t *infop) | |
fe8ab488 | 336 | { |
0a7de745 | 337 | if (space == IS_NULL) { |
fe8ab488 | 338 | return KERN_INVALID_TASK; |
0a7de745 | 339 | } |
fe8ab488 | 340 | |
3e170ce0 | 341 | |
fe8ab488 A |
342 | is_read_lock(space); |
343 | if (!is_active(space)) { | |
344 | is_read_unlock(space); | |
345 | return KERN_INVALID_TASK; | |
346 | } | |
347 | ||
348 | /* get the basic space info */ | |
349 | infop->iisb_genno_mask = MACH_PORT_NGEN(MACH_PORT_DEAD); | |
350 | infop->iisb_table_size = space->is_table_size; | |
351 | infop->iisb_table_next = space->is_table_next->its_size; | |
352 | infop->iisb_table_inuse = space->is_table_size - space->is_table_free - 1; | |
353 | infop->iisb_reserved[0] = 0; | |
354 | infop->iisb_reserved[1] = 0; | |
355 | ||
356 | is_read_unlock(space); | |
357 | ||
358 | return KERN_SUCCESS; | |
359 | } | |
360 | #endif /* MACH_IPC_DEBUG */ | |
361 | ||
1c79356b A |
362 | /* |
363 | * Routine: mach_port_dnrequest_info | |
364 | * Purpose: | |
365 | * Returns information about the dead-name requests | |
366 | * registered with the named receive right. | |
367 | * Conditions: | |
368 | * Nothing locked. | |
369 | * Returns: | |
370 | * KERN_SUCCESS Retrieved information. | |
371 | * KERN_INVALID_TASK The space is null. | |
372 | * KERN_INVALID_TASK The space is dead. | |
373 | * KERN_INVALID_NAME The name doesn't denote a right. | |
374 | * KERN_INVALID_RIGHT Name doesn't denote receive rights. | |
375 | */ | |
376 | ||
91447636 | 377 | #if !MACH_IPC_DEBUG |
1c79356b A |
378 | kern_return_t |
379 | mach_port_dnrequest_info( | |
0a7de745 A |
380 | __unused ipc_space_t space, |
381 | __unused mach_port_name_t name, | |
382 | __unused unsigned int *totalp, | |
383 | __unused unsigned int *usedp) | |
1c79356b | 384 | { |
0a7de745 | 385 | return KERN_FAILURE; |
91447636 | 386 | } |
1c79356b | 387 | #else |
91447636 A |
388 | kern_return_t |
389 | mach_port_dnrequest_info( | |
0a7de745 A |
390 | ipc_space_t space, |
391 | mach_port_name_t name, | |
392 | unsigned int *totalp, | |
393 | unsigned int *usedp) | |
91447636 | 394 | { |
1c79356b A |
395 | unsigned int total, used; |
396 | ipc_port_t port; | |
397 | kern_return_t kr; | |
398 | ||
0a7de745 | 399 | if (space == IS_NULL) { |
1c79356b | 400 | return KERN_INVALID_TASK; |
0a7de745 | 401 | } |
1c79356b A |
402 | |
403 | kr = ipc_port_translate_receive(space, name, &port); | |
0a7de745 | 404 | if (kr != KERN_SUCCESS) { |
1c79356b | 405 | return kr; |
0a7de745 | 406 | } |
1c79356b A |
407 | /* port is locked and active */ |
408 | ||
6d2010ae | 409 | if (port->ip_requests == IPR_NULL) { |
1c79356b A |
410 | total = 0; |
411 | used = 0; | |
412 | } else { | |
6d2010ae | 413 | ipc_port_request_t requests = port->ip_requests; |
1c79356b A |
414 | ipc_port_request_index_t index; |
415 | ||
6d2010ae | 416 | total = requests->ipr_size->its_size; |
1c79356b A |
417 | |
418 | for (index = 1, used = 0; | |
0a7de745 | 419 | index < total; index++) { |
6d2010ae | 420 | ipc_port_request_t ipr = &requests[index]; |
1c79356b | 421 | |
0a7de745 | 422 | if (ipr->ipr_name != MACH_PORT_NULL) { |
1c79356b | 423 | used++; |
0a7de745 | 424 | } |
1c79356b A |
425 | } |
426 | } | |
427 | ip_unlock(port); | |
428 | ||
429 | *totalp = total; | |
430 | *usedp = used; | |
431 | return KERN_SUCCESS; | |
1c79356b | 432 | } |
91447636 | 433 | #endif /* MACH_IPC_DEBUG */ |
1c79356b A |
434 | |
435 | /* | |
b0d623f7 | 436 | * Routine: mach_port_kobject [kernel call] |
1c79356b A |
437 | * Purpose: |
438 | * Retrieve the type and address of the kernel object | |
b0d623f7 A |
439 | * represented by a send or receive right. Returns |
440 | * the kernel address in a mach_vm_address_t to | |
441 | * mask potential differences in kernel address space | |
442 | * size. | |
1c79356b A |
443 | * Conditions: |
444 | * Nothing locked. | |
445 | * Returns: | |
446 | * KERN_SUCCESS Retrieved kernel object info. | |
447 | * KERN_INVALID_TASK The space is null. | |
448 | * KERN_INVALID_TASK The space is dead. | |
449 | * KERN_INVALID_NAME The name doesn't denote a right. | |
450 | * KERN_INVALID_RIGHT Name doesn't denote | |
451 | * send or receive rights. | |
452 | */ | |
453 | ||
91447636 | 454 | #if !MACH_IPC_DEBUG |
1c79356b | 455 | kern_return_t |
ea3f0419 | 456 | mach_port_kobject_description( |
0a7de745 A |
457 | __unused ipc_space_t space, |
458 | __unused mach_port_name_t name, | |
459 | __unused natural_t *typep, | |
ea3f0419 A |
460 | __unused mach_vm_address_t *addrp, |
461 | __unused kobject_description_t desc) | |
1c79356b | 462 | { |
0a7de745 | 463 | return KERN_FAILURE; |
91447636 | 464 | } |
1c79356b | 465 | #else |
91447636 | 466 | kern_return_t |
ea3f0419 | 467 | mach_port_kobject_description( |
0a7de745 A |
468 | ipc_space_t space, |
469 | mach_port_name_t name, | |
470 | natural_t *typep, | |
ea3f0419 A |
471 | mach_vm_address_t *addrp, |
472 | kobject_description_t desc) | |
91447636 | 473 | { |
1c79356b A |
474 | ipc_entry_t entry; |
475 | ipc_port_t port; | |
476 | kern_return_t kr; | |
316670eb | 477 | mach_vm_address_t kaddr; |
1c79356b | 478 | |
0a7de745 | 479 | if (space == IS_NULL) { |
2d21ac55 | 480 | return KERN_INVALID_TASK; |
0a7de745 | 481 | } |
2d21ac55 | 482 | |
1c79356b | 483 | kr = ipc_right_lookup_read(space, name, &entry); |
0a7de745 | 484 | if (kr != KERN_SUCCESS) { |
1c79356b | 485 | return kr; |
0a7de745 | 486 | } |
1c79356b A |
487 | /* space is read-locked and active */ |
488 | ||
489 | if ((entry->ie_bits & MACH_PORT_TYPE_SEND_RECEIVE) == 0) { | |
490 | is_read_unlock(space); | |
491 | return KERN_INVALID_RIGHT; | |
492 | } | |
493 | ||
cb323159 | 494 | port = ip_object_to_port(entry->ie_object); |
1c79356b A |
495 | assert(port != IP_NULL); |
496 | ||
497 | ip_lock(port); | |
498 | is_read_unlock(space); | |
499 | ||
500 | if (!ip_active(port)) { | |
501 | ip_unlock(port); | |
502 | return KERN_INVALID_RIGHT; | |
503 | } | |
504 | ||
505 | *typep = (unsigned int) ip_kotype(port); | |
ea3f0419 | 506 | kaddr = (mach_vm_address_t)ip_get_kobject(port); |
cb323159 | 507 | *addrp = 0; |
3e170ce0 | 508 | #if (DEVELOPMENT || DEBUG) |
cb323159 | 509 | if (kaddr && ip_is_kobject(port)) { |
fe8ab488 | 510 | *addrp = VM_KERNEL_UNSLIDE_OR_PERM(kaddr); |
cb323159 | 511 | } |
c18c124e | 512 | #endif |
ea3f0419 A |
513 | |
514 | io_object_t obj = NULL; | |
515 | natural_t kotype = ip_kotype(port); | |
516 | if (desc) { | |
517 | *desc = '\0'; | |
518 | switch (kotype) { | |
519 | case IKOT_IOKIT_OBJECT: | |
520 | case IKOT_IOKIT_CONNECT: | |
521 | case IKOT_IOKIT_IDENT: | |
522 | case IKOT_UEXT_OBJECT: | |
523 | obj = (io_object_t) kaddr; | |
524 | iokit_add_reference(obj, IKOT_IOKIT_OBJECT); | |
525 | break; | |
526 | ||
527 | default: | |
528 | break; | |
529 | } | |
530 | } | |
531 | ||
cb323159 | 532 | ip_unlock(port); |
316670eb | 533 | |
ea3f0419 A |
534 | if (obj) { |
535 | iokit_port_object_description(obj, desc); | |
536 | iokit_remove_reference(obj); | |
537 | } | |
538 | ||
316670eb | 539 | return KERN_SUCCESS; |
1c79356b | 540 | } |
91447636 | 541 | #endif /* MACH_IPC_DEBUG */ |
cb323159 | 542 | |
ea3f0419 A |
543 | kern_return_t |
544 | mach_port_kobject( | |
545 | ipc_space_t space, | |
546 | mach_port_name_t name, | |
547 | natural_t *typep, | |
548 | mach_vm_address_t *addrp) | |
549 | { | |
550 | return mach_port_kobject_description(space, name, typep, addrp, NULL); | |
551 | } | |
552 | ||
b0d623f7 A |
553 | /* |
554 | * Routine: mach_port_kernel_object [Legacy kernel call] | |
555 | * Purpose: | |
556 | * Retrieve the type and address of the kernel object | |
557 | * represented by a send or receive right. Hard-coded | |
558 | * to return only the low-order 32-bits of the kernel | |
559 | * object. | |
560 | * Conditions: | |
561 | * Nothing locked. | |
562 | * Returns: | |
563 | * KERN_SUCCESS Retrieved kernel object info. | |
564 | * KERN_INVALID_TASK The space is null. | |
565 | * KERN_INVALID_TASK The space is dead. | |
566 | * KERN_INVALID_NAME The name doesn't denote a right. | |
567 | * KERN_INVALID_RIGHT Name doesn't denote | |
568 | * send or receive rights. | |
569 | */ | |
570 | ||
571 | #if !MACH_IPC_DEBUG | |
572 | kern_return_t | |
573 | mach_port_kernel_object( | |
0a7de745 A |
574 | __unused ipc_space_t space, |
575 | __unused mach_port_name_t name, | |
576 | __unused unsigned int *typep, | |
577 | __unused unsigned int *addrp) | |
b0d623f7 | 578 | { |
0a7de745 | 579 | return KERN_FAILURE; |
b0d623f7 A |
580 | } |
581 | #else | |
582 | kern_return_t | |
583 | mach_port_kernel_object( | |
0a7de745 A |
584 | ipc_space_t space, |
585 | mach_port_name_t name, | |
586 | unsigned int *typep, | |
587 | unsigned int *addrp) | |
b0d623f7 A |
588 | { |
589 | mach_vm_address_t addr = 0; | |
590 | kern_return_t kr; | |
591 | ||
592 | kr = mach_port_kobject(space, name, typep, &addr); | |
593 | *addrp = (unsigned int) addr; | |
594 | return kr; | |
595 | } | |
596 | #endif /* MACH_IPC_DEBUG */ | |
d9a64523 A |
597 | |
598 | #if (DEVELOPMENT || DEBUG) | |
599 | kern_return_t | |
600 | mach_port_special_reply_port_reset_link( | |
601 | ipc_space_t space, | |
602 | mach_port_name_t name, | |
0a7de745 | 603 | boolean_t *srp_lost_link) |
d9a64523 A |
604 | { |
605 | ipc_port_t port; | |
606 | kern_return_t kr; | |
607 | thread_t thread = current_thread(); | |
608 | ||
0a7de745 | 609 | if (space != current_space()) { |
d9a64523 | 610 | return KERN_INVALID_TASK; |
0a7de745 | 611 | } |
d9a64523 | 612 | |
0a7de745 | 613 | if (!MACH_PORT_VALID(name)) { |
d9a64523 | 614 | return KERN_INVALID_NAME; |
0a7de745 | 615 | } |
d9a64523 | 616 | |
0a7de745 | 617 | if (!IP_VALID(thread->ith_special_reply_port)) { |
d9a64523 | 618 | return KERN_INVALID_VALUE; |
0a7de745 | 619 | } |
d9a64523 A |
620 | |
621 | kr = ipc_port_translate_receive(space, name, &port); | |
0a7de745 | 622 | if (kr != KERN_SUCCESS) { |
d9a64523 | 623 | return kr; |
0a7de745 | 624 | } |
d9a64523 A |
625 | |
626 | if (thread->ith_special_reply_port != port) { | |
627 | ip_unlock(port); | |
628 | return KERN_INVALID_ARGUMENT; | |
629 | } | |
630 | ||
631 | imq_lock(&port->ip_messages); | |
632 | *srp_lost_link = (port->ip_srp_lost_link == 1)? TRUE : FALSE; | |
633 | port->ip_srp_lost_link = 0; | |
634 | imq_unlock(&port->ip_messages); | |
635 | ||
636 | ip_unlock(port); | |
637 | return KERN_SUCCESS; | |
638 | } | |
639 | #else | |
640 | kern_return_t | |
641 | mach_port_special_reply_port_reset_link( | |
0a7de745 A |
642 | __unused ipc_space_t space, |
643 | __unused mach_port_name_t name, | |
644 | __unused boolean_t *srp_lost_link) | |
d9a64523 A |
645 | { |
646 | return KERN_NOT_SUPPORTED; | |
647 | } | |
648 | #endif |