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