]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
8f6c56a5 A |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | * | |
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. | |
14 | * | |
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 | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989,1988 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 | /* | |
60 | * host.c | |
61 | * | |
62 | * Non-ipc host functions. | |
63 | */ | |
64 | ||
1c79356b A |
65 | #include <mach_host.h> |
66 | ||
91447636 | 67 | #include <mach/mach_types.h> |
1c79356b | 68 | #include <mach/boolean.h> |
1c79356b | 69 | #include <mach/host_info.h> |
55e303ae | 70 | #include <mach/host_special_ports.h> |
1c79356b A |
71 | #include <mach/kern_return.h> |
72 | #include <mach/machine.h> | |
73 | #include <mach/port.h> | |
1c79356b A |
74 | #include <mach/processor_info.h> |
75 | #include <mach/vm_param.h> | |
91447636 | 76 | #include <mach/processor.h> |
1c79356b | 77 | #include <mach/mach_host_server.h> |
91447636 A |
78 | #include <mach/host_priv_server.h> |
79 | #include <mach/vm_map.h> | |
80 | ||
81 | #include <kern/kern_types.h> | |
82 | #include <kern/assert.h> | |
83 | #include <kern/kalloc.h> | |
84 | #include <kern/host.h> | |
85 | #include <kern/host_statistics.h> | |
86 | #include <kern/ipc_host.h> | |
87 | #include <kern/misc_protos.h> | |
88 | #include <kern/sched.h> | |
89 | #include <kern/processor.h> | |
90 | ||
91 | #include <vm/vm_map.h> | |
92 | ||
1c79356b A |
93 | #if DIPC |
94 | #include <dipc/dipc_funcs.h> | |
95 | #include <dipc/special_ports.h> | |
96 | #endif | |
97 | ||
1c79356b A |
98 | host_data_t realhost; |
99 | ||
100 | kern_return_t | |
101 | host_processors( | |
91447636 A |
102 | host_priv_t host_priv, |
103 | processor_array_t *out_array, | |
1c79356b A |
104 | mach_msg_type_number_t *countp) |
105 | { | |
91447636 A |
106 | register processor_t processor, *tp; |
107 | void *addr; | |
108 | unsigned int count, i; | |
1c79356b A |
109 | |
110 | if (host_priv == HOST_PRIV_NULL) | |
91447636 | 111 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
112 | |
113 | assert(host_priv == &realhost); | |
114 | ||
91447636 A |
115 | count = processor_count; |
116 | assert(count != 0); | |
1c79356b A |
117 | |
118 | addr = kalloc((vm_size_t) (count * sizeof(mach_port_t))); | |
119 | if (addr == 0) | |
91447636 | 120 | return (KERN_RESOURCE_SHORTAGE); |
1c79356b A |
121 | |
122 | tp = (processor_t *) addr; | |
91447636 A |
123 | *tp++ = processor = processor_list; |
124 | ||
125 | if (count > 1) { | |
126 | simple_lock(&processor_list_lock); | |
127 | ||
128 | for (i = 1; i < count; i++) | |
129 | *tp++ = processor = processor->processor_list; | |
130 | ||
131 | simple_unlock(&processor_list_lock); | |
132 | } | |
1c79356b A |
133 | |
134 | *countp = count; | |
91447636 | 135 | *out_array = (processor_array_t)addr; |
1c79356b A |
136 | |
137 | /* do the conversion that Mig should handle */ | |
138 | ||
139 | tp = (processor_t *) addr; | |
140 | for (i = 0; i < count; i++) | |
141 | ((mach_port_t *) tp)[i] = | |
142 | (mach_port_t)convert_processor_to_port(tp[i]); | |
143 | ||
91447636 | 144 | return (KERN_SUCCESS); |
1c79356b A |
145 | } |
146 | ||
147 | kern_return_t | |
148 | host_info( | |
149 | host_t host, | |
150 | host_flavor_t flavor, | |
151 | host_info_t info, | |
152 | mach_msg_type_number_t *count) | |
153 | { | |
154 | ||
155 | if (host == HOST_NULL) | |
91447636 | 156 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 157 | |
91447636 | 158 | switch (flavor) { |
1c79356b A |
159 | |
160 | case HOST_BASIC_INFO: | |
161 | { | |
162 | register host_basic_info_t basic_info; | |
91447636 | 163 | register int master_slot; |
1c79356b A |
164 | |
165 | /* | |
166 | * Basic information about this host. | |
167 | */ | |
91447636 A |
168 | if (*count < HOST_BASIC_INFO_OLD_COUNT) |
169 | return (KERN_FAILURE); | |
1c79356b A |
170 | |
171 | basic_info = (host_basic_info_t) info; | |
172 | ||
173 | basic_info->max_cpus = machine_info.max_cpus; | |
174 | basic_info->avail_cpus = machine_info.avail_cpus; | |
175 | basic_info->memory_size = machine_info.memory_size; | |
91447636 A |
176 | master_slot = PROCESSOR_DATA(master_processor, slot_num); |
177 | basic_info->cpu_type = slot_type(master_slot); | |
178 | basic_info->cpu_subtype = slot_subtype(master_slot); | |
179 | ||
180 | if (*count >= HOST_BASIC_INFO_COUNT) { | |
181 | basic_info->cpu_threadtype = slot_threadtype(master_slot); | |
182 | basic_info->physical_cpu = machine_info.physical_cpu; | |
183 | basic_info->physical_cpu_max = machine_info.physical_cpu_max; | |
184 | basic_info->logical_cpu = machine_info.logical_cpu; | |
185 | basic_info->logical_cpu_max = machine_info.logical_cpu_max; | |
186 | basic_info->max_mem = machine_info.max_mem; | |
187 | ||
188 | *count = HOST_BASIC_INFO_COUNT; | |
189 | } else { | |
190 | *count = HOST_BASIC_INFO_OLD_COUNT; | |
191 | } | |
1c79356b | 192 | |
91447636 | 193 | return (KERN_SUCCESS); |
1c79356b A |
194 | } |
195 | ||
196 | case HOST_SCHED_INFO: | |
197 | { | |
198 | register host_sched_info_t sched_info; | |
1c79356b A |
199 | |
200 | /* | |
201 | * Return scheduler information. | |
202 | */ | |
203 | if (*count < HOST_SCHED_INFO_COUNT) | |
91447636 | 204 | return (KERN_FAILURE); |
1c79356b A |
205 | |
206 | sched_info = (host_sched_info_t) info; | |
207 | ||
91447636 A |
208 | sched_info->min_timeout = |
209 | sched_info->min_quantum = std_quantum_us / 1000; | |
1c79356b A |
210 | |
211 | *count = HOST_SCHED_INFO_COUNT; | |
212 | ||
91447636 | 213 | return (KERN_SUCCESS); |
1c79356b A |
214 | } |
215 | ||
216 | case HOST_RESOURCE_SIZES: | |
217 | { | |
218 | /* | |
219 | * Return sizes of kernel data structures | |
220 | */ | |
221 | if (*count < HOST_RESOURCE_SIZES_COUNT) | |
91447636 | 222 | return (KERN_FAILURE); |
1c79356b A |
223 | |
224 | /* XXX Fail until ledgers are implemented */ | |
91447636 | 225 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
226 | } |
227 | ||
228 | case HOST_PRIORITY_INFO: | |
229 | { | |
230 | register host_priority_info_t priority_info; | |
231 | ||
232 | if (*count < HOST_PRIORITY_INFO_COUNT) | |
91447636 | 233 | return (KERN_FAILURE); |
1c79356b A |
234 | |
235 | priority_info = (host_priority_info_t) info; | |
236 | ||
0b4e3aa0 A |
237 | priority_info->kernel_priority = MINPRI_KERNEL; |
238 | priority_info->system_priority = MINPRI_KERNEL; | |
91447636 | 239 | priority_info->server_priority = MINPRI_RESERVED; |
1c79356b A |
240 | priority_info->user_priority = BASEPRI_DEFAULT; |
241 | priority_info->depress_priority = DEPRESSPRI; | |
242 | priority_info->idle_priority = IDLEPRI; | |
91447636 A |
243 | priority_info->minimum_priority = MINPRI_USER; |
244 | priority_info->maximum_priority = MAXPRI_RESERVED; | |
1c79356b A |
245 | |
246 | *count = HOST_PRIORITY_INFO_COUNT; | |
247 | ||
91447636 | 248 | return (KERN_SUCCESS); |
1c79356b A |
249 | } |
250 | ||
251 | /* | |
9bccf70c | 252 | * Gestalt for various trap facilities. |
1c79356b | 253 | */ |
9bccf70c | 254 | case HOST_MACH_MSG_TRAP: |
1c79356b A |
255 | case HOST_SEMAPHORE_TRAPS: |
256 | { | |
257 | *count = 0; | |
91447636 | 258 | return (KERN_SUCCESS); |
1c79356b A |
259 | } |
260 | ||
261 | default: | |
91447636 | 262 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
263 | } |
264 | } | |
265 | ||
266 | kern_return_t | |
267 | host_statistics( | |
91447636 A |
268 | host_t host, |
269 | host_flavor_t flavor, | |
270 | host_info_t info, | |
1c79356b A |
271 | mach_msg_type_number_t *count) |
272 | { | |
273 | ||
274 | if (host == HOST_NULL) | |
91447636 | 275 | return (KERN_INVALID_HOST); |
1c79356b A |
276 | |
277 | switch(flavor) { | |
278 | ||
91447636 A |
279 | case HOST_LOAD_INFO: |
280 | { | |
281 | host_load_info_t load_info; | |
1c79356b A |
282 | |
283 | if (*count < HOST_LOAD_INFO_COUNT) | |
91447636 | 284 | return (KERN_FAILURE); |
1c79356b A |
285 | |
286 | load_info = (host_load_info_t) info; | |
287 | ||
288 | bcopy((char *) avenrun, | |
91447636 | 289 | (char *) load_info->avenrun, sizeof avenrun); |
1c79356b | 290 | bcopy((char *) mach_factor, |
91447636 | 291 | (char *) load_info->mach_factor, sizeof mach_factor); |
1c79356b A |
292 | |
293 | *count = HOST_LOAD_INFO_COUNT; | |
91447636 A |
294 | return (KERN_SUCCESS); |
295 | } | |
296 | ||
297 | case HOST_VM_INFO: | |
298 | { | |
299 | register processor_t processor; | |
300 | register vm_statistics_t stat; | |
301 | vm_statistics_data_t host_vm_stat; | |
1c79356b | 302 | |
91447636 A |
303 | if (*count < HOST_VM_INFO_REV0_COUNT) |
304 | return (KERN_FAILURE); | |
1c79356b | 305 | |
91447636 A |
306 | processor = processor_list; |
307 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
1c79356b | 308 | host_vm_stat = *stat; |
91447636 A |
309 | |
310 | if (processor_count > 1) { | |
311 | simple_lock(&processor_list_lock); | |
312 | ||
313 | while ((processor = processor->processor_list) != NULL) { | |
314 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
315 | ||
316 | host_vm_stat.zero_fill_count += stat->zero_fill_count; | |
317 | host_vm_stat.reactivations += stat->reactivations; | |
1c79356b A |
318 | host_vm_stat.pageins += stat->pageins; |
319 | host_vm_stat.pageouts += stat->pageouts; | |
320 | host_vm_stat.faults += stat->faults; | |
321 | host_vm_stat.cow_faults += stat->cow_faults; | |
322 | host_vm_stat.lookups += stat->lookups; | |
323 | host_vm_stat.hits += stat->hits; | |
324 | } | |
91447636 A |
325 | |
326 | simple_unlock(&processor_list_lock); | |
1c79356b | 327 | } |
1c79356b A |
328 | |
329 | stat = (vm_statistics_t) info; | |
330 | ||
91447636 A |
331 | stat->free_count = vm_page_free_count; |
332 | stat->active_count = vm_page_active_count; | |
333 | stat->inactive_count = vm_page_inactive_count; | |
334 | stat->wire_count = vm_page_wire_count; | |
335 | stat->zero_fill_count = host_vm_stat.zero_fill_count; | |
336 | stat->reactivations = host_vm_stat.reactivations; | |
337 | stat->pageins = host_vm_stat.pageins; | |
338 | stat->pageouts = host_vm_stat.pageouts; | |
339 | stat->faults = host_vm_stat.faults; | |
340 | stat->cow_faults = host_vm_stat.cow_faults; | |
341 | stat->lookups = host_vm_stat.lookups; | |
342 | stat->hits = host_vm_stat.hits; | |
343 | ||
344 | if (*count >= HOST_VM_INFO_COUNT) { | |
345 | /* info that was not in revision 0 of that interface */ | |
346 | stat->purgeable_count = vm_page_purgeable_count; | |
347 | stat->purges = vm_page_purged_count; | |
348 | *count = HOST_VM_INFO_COUNT; | |
349 | } else { | |
350 | *count = HOST_VM_INFO_REV0_COUNT; | |
351 | } | |
352 | ||
353 | return (KERN_SUCCESS); | |
354 | } | |
1c79356b | 355 | |
91447636 A |
356 | case HOST_CPU_LOAD_INFO: |
357 | { | |
358 | register processor_t processor; | |
1c79356b | 359 | host_cpu_load_info_t cpu_load_info; |
91447636 | 360 | unsigned long ticks_value1, ticks_value2; |
1c79356b A |
361 | |
362 | if (*count < HOST_CPU_LOAD_INFO_COUNT) | |
91447636 A |
363 | return (KERN_FAILURE); |
364 | ||
365 | #define GET_TICKS_VALUE(processor, state) \ | |
366 | MACRO_BEGIN \ | |
367 | do { \ | |
368 | ticks_value1 = *(volatile integer_t *) \ | |
369 | &PROCESSOR_DATA((processor), cpu_ticks[(state)]); \ | |
370 | ticks_value2 = *(volatile integer_t *) \ | |
371 | &PROCESSOR_DATA((processor), cpu_ticks[(state)]); \ | |
372 | } while (ticks_value1 != ticks_value2); \ | |
373 | \ | |
374 | cpu_load_info->cpu_ticks[(state)] += ticks_value1; \ | |
375 | MACRO_END | |
1c79356b | 376 | |
91447636 | 377 | cpu_load_info = (host_cpu_load_info_t)info; |
1c79356b A |
378 | cpu_load_info->cpu_ticks[CPU_STATE_USER] = 0; |
379 | cpu_load_info->cpu_ticks[CPU_STATE_NICE] = 0; | |
380 | cpu_load_info->cpu_ticks[CPU_STATE_SYSTEM] = 0; | |
381 | cpu_load_info->cpu_ticks[CPU_STATE_IDLE] = 0; | |
91447636 A |
382 | |
383 | processor = processor_list; | |
384 | GET_TICKS_VALUE(processor, CPU_STATE_USER); | |
385 | GET_TICKS_VALUE(processor, CPU_STATE_NICE); | |
386 | GET_TICKS_VALUE(processor, CPU_STATE_SYSTEM); | |
387 | GET_TICKS_VALUE(processor, CPU_STATE_IDLE); | |
388 | ||
389 | if (processor_count > 1) { | |
390 | simple_lock(&processor_list_lock); | |
391 | ||
392 | while ((processor = processor->processor_list) != NULL) { | |
393 | GET_TICKS_VALUE(processor, CPU_STATE_USER); | |
394 | GET_TICKS_VALUE(processor, CPU_STATE_NICE); | |
395 | GET_TICKS_VALUE(processor, CPU_STATE_SYSTEM); | |
396 | GET_TICKS_VALUE(processor, CPU_STATE_IDLE); | |
397 | } | |
398 | ||
399 | simple_unlock(&processor_list_lock); | |
1c79356b A |
400 | } |
401 | ||
402 | *count = HOST_CPU_LOAD_INFO_COUNT; | |
91447636 A |
403 | |
404 | return (KERN_SUCCESS); | |
405 | } | |
1c79356b A |
406 | |
407 | default: | |
91447636 | 408 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
409 | } |
410 | } | |
411 | ||
412 | /* | |
413 | * Get host statistics that require privilege. | |
414 | * None for now, just call the un-privileged version. | |
415 | */ | |
416 | kern_return_t | |
417 | host_priv_statistics( | |
418 | host_priv_t host_priv, | |
419 | host_flavor_t flavor, | |
420 | host_info_t info, | |
421 | mach_msg_type_number_t *count) | |
422 | { | |
423 | return(host_statistics((host_t)host_priv, flavor, info, count)); | |
424 | } | |
425 | ||
426 | ||
427 | kern_return_t | |
428 | host_page_size( | |
429 | host_t host, | |
430 | vm_size_t *out_page_size) | |
431 | { | |
432 | if (host == HOST_NULL) | |
433 | return(KERN_INVALID_ARGUMENT); | |
434 | ||
435 | *out_page_size = PAGE_SIZE; | |
436 | ||
437 | return(KERN_SUCCESS); | |
438 | } | |
439 | ||
440 | /* | |
441 | * Return kernel version string (more than you ever | |
442 | * wanted to know about what version of the kernel this is). | |
443 | */ | |
91447636 | 444 | extern char version[]; |
1c79356b A |
445 | |
446 | kern_return_t | |
447 | host_kernel_version( | |
448 | host_t host, | |
449 | kernel_version_t out_version) | |
450 | { | |
1c79356b A |
451 | |
452 | if (host == HOST_NULL) | |
453 | return(KERN_INVALID_ARGUMENT); | |
454 | ||
455 | (void) strncpy(out_version, version, sizeof(kernel_version_t)); | |
456 | ||
457 | return(KERN_SUCCESS); | |
458 | } | |
459 | ||
460 | /* | |
461 | * host_processor_sets: | |
462 | * | |
463 | * List all processor sets on the host. | |
464 | */ | |
465 | kern_return_t | |
466 | host_processor_sets( | |
467 | host_priv_t host_priv, | |
468 | processor_set_name_array_t *pset_list, | |
469 | mach_msg_type_number_t *count) | |
470 | { | |
91447636 | 471 | void *addr; |
1c79356b A |
472 | |
473 | if (host_priv == HOST_PRIV_NULL) | |
474 | return KERN_INVALID_ARGUMENT; | |
475 | ||
476 | /* | |
477 | * Allocate memory. Can be pageable because it won't be | |
478 | * touched while holding a lock. | |
479 | */ | |
480 | ||
481 | addr = kalloc((vm_size_t) sizeof(mach_port_t)); | |
482 | if (addr == 0) | |
483 | return KERN_RESOURCE_SHORTAGE; | |
484 | ||
485 | /* take ref for convert_pset_name_to_port */ | |
486 | pset_reference(&default_pset); | |
487 | /* do the conversion that Mig should handle */ | |
488 | *((ipc_port_t *) addr) = convert_pset_name_to_port(&default_pset); | |
489 | ||
490 | *pset_list = (processor_set_array_t)addr; | |
491 | *count = 1; | |
492 | ||
493 | return KERN_SUCCESS; | |
494 | } | |
495 | ||
496 | /* | |
497 | * host_processor_set_priv: | |
498 | * | |
499 | * Return control port for given processor set. | |
500 | */ | |
501 | kern_return_t | |
502 | host_processor_set_priv( | |
503 | host_priv_t host_priv, | |
504 | processor_set_t pset_name, | |
505 | processor_set_t *pset) | |
506 | { | |
507 | if ((host_priv == HOST_PRIV_NULL) || (pset_name == PROCESSOR_SET_NULL)) { | |
508 | *pset = PROCESSOR_SET_NULL; | |
509 | return(KERN_INVALID_ARGUMENT); | |
510 | } | |
511 | ||
512 | *pset = pset_name; | |
513 | pset_reference(*pset); | |
514 | return(KERN_SUCCESS); | |
515 | } | |
516 | ||
517 | /* | |
518 | * host_processor_info | |
519 | * | |
520 | * Return info about the processors on this host. It will return | |
521 | * the number of processors, and the specific type of info requested | |
522 | * in an OOL array. | |
523 | */ | |
524 | kern_return_t | |
525 | host_processor_info( | |
91447636 A |
526 | host_t host, |
527 | processor_flavor_t flavor, | |
528 | natural_t *out_pcount, | |
529 | processor_info_array_t *out_array, | |
530 | mach_msg_type_number_t *out_array_count) | |
1c79356b | 531 | { |
91447636 A |
532 | kern_return_t result; |
533 | processor_t processor; | |
534 | host_t thost; | |
535 | processor_info_t info; | |
536 | unsigned int icount, tcount; | |
537 | unsigned int pcount, i; | |
538 | vm_offset_t addr; | |
539 | vm_size_t size; | |
540 | vm_map_copy_t copy; | |
1c79356b A |
541 | |
542 | if (host == HOST_NULL) | |
91447636 | 543 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 544 | |
91447636 A |
545 | result = processor_info_count(flavor, &icount); |
546 | if (result != KERN_SUCCESS) | |
547 | return (result); | |
1c79356b | 548 | |
91447636 A |
549 | pcount = processor_count; |
550 | assert(pcount != 0); | |
1c79356b | 551 | |
91447636 A |
552 | size = round_page(pcount * icount * sizeof(natural_t)); |
553 | result = kmem_alloc(ipc_kernel_map, &addr, size); | |
554 | if (result != KERN_SUCCESS) | |
555 | return (KERN_RESOURCE_SHORTAGE); | |
556 | ||
557 | info = (processor_info_t) addr; | |
558 | processor = processor_list; | |
559 | tcount = icount; | |
1c79356b | 560 | |
91447636 A |
561 | result = processor_info(processor, flavor, &thost, info, &tcount); |
562 | if (result != KERN_SUCCESS) { | |
1c79356b | 563 | kmem_free(ipc_kernel_map, addr, size); |
91447636 | 564 | return (result); |
1c79356b A |
565 | } |
566 | ||
91447636 A |
567 | if (pcount > 1) { |
568 | for (i = 1; i < pcount; i++) { | |
569 | simple_lock(&processor_list_lock); | |
570 | processor = processor->processor_list; | |
571 | simple_unlock(&processor_list_lock); | |
572 | ||
573 | info += icount; | |
574 | tcount = icount; | |
575 | result = processor_info(processor, flavor, &thost, info, &tcount); | |
576 | if (result != KERN_SUCCESS) { | |
1c79356b | 577 | kmem_free(ipc_kernel_map, addr, size); |
91447636 | 578 | return (result); |
1c79356b | 579 | } |
1c79356b A |
580 | } |
581 | } | |
582 | ||
91447636 A |
583 | result = vm_map_unwire(ipc_kernel_map, vm_map_trunc_page(addr), |
584 | vm_map_round_page(addr + size), FALSE); | |
585 | assert(result == KERN_SUCCESS); | |
586 | result = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)addr, | |
587 | (vm_map_size_t)size, TRUE, ©); | |
588 | assert(result == KERN_SUCCESS); | |
1c79356b | 589 | |
91447636 A |
590 | *out_pcount = pcount; |
591 | *out_array = (processor_info_array_t) copy; | |
592 | *out_array_count = pcount * icount; | |
593 | ||
594 | return (KERN_SUCCESS); | |
1c79356b A |
595 | } |
596 | ||
1c79356b | 597 | /* |
55e303ae | 598 | * Kernel interface for setting a special port. |
1c79356b A |
599 | */ |
600 | kern_return_t | |
55e303ae A |
601 | kernel_set_special_port( |
602 | host_priv_t host_priv, | |
603 | int id, | |
604 | ipc_port_t port) | |
1c79356b | 605 | { |
55e303ae A |
606 | ipc_port_t old_port; |
607 | ||
608 | host_lock(host_priv); | |
609 | old_port = host_priv->special[id]; | |
610 | host_priv->special[id] = port; | |
611 | host_unlock(host_priv); | |
612 | if (IP_VALID(old_port)) | |
613 | ipc_port_release_send(old_port); | |
614 | return KERN_SUCCESS; | |
1c79356b A |
615 | } |
616 | ||
617 | /* | |
618 | * User interface for setting a special port. | |
619 | * | |
620 | * Only permits the user to set a user-owned special port | |
621 | * ID, rejecting a kernel-owned special port ID. | |
622 | * | |
623 | * A special kernel port cannot be set up using this | |
624 | * routine; use kernel_set_special_port() instead. | |
625 | */ | |
626 | kern_return_t | |
627 | host_set_special_port( | |
628 | host_priv_t host_priv, | |
629 | int id, | |
630 | ipc_port_t port) | |
631 | { | |
55e303ae A |
632 | if (host_priv == HOST_PRIV_NULL || |
633 | id <= HOST_MAX_SPECIAL_KERNEL_PORT || id > HOST_MAX_SPECIAL_PORT ) { | |
634 | if (IP_VALID(port)) | |
635 | ipc_port_release_send(port); | |
636 | return KERN_INVALID_ARGUMENT; | |
637 | } | |
638 | ||
639 | return kernel_set_special_port(host_priv, id, port); | |
1c79356b A |
640 | } |
641 | ||
642 | ||
643 | /* | |
644 | * User interface for retrieving a special port. | |
645 | * | |
1c79356b A |
646 | * Note that there is nothing to prevent a user special |
647 | * port from disappearing after it has been discovered by | |
648 | * the caller; thus, using a special port can always result | |
649 | * in a "port not valid" error. | |
650 | */ | |
651 | ||
652 | kern_return_t | |
653 | host_get_special_port( | |
654 | host_priv_t host_priv, | |
91447636 | 655 | __unused int node, |
1c79356b A |
656 | int id, |
657 | ipc_port_t *portp) | |
658 | { | |
55e303ae A |
659 | ipc_port_t port; |
660 | ||
661 | if (host_priv == HOST_PRIV_NULL || | |
91447636 | 662 | id == HOST_SECURITY_PORT || id > HOST_MAX_SPECIAL_PORT ) |
55e303ae A |
663 | return KERN_INVALID_ARGUMENT; |
664 | ||
1c79356b | 665 | #if DIPC |
55e303ae A |
666 | if (node != HOST_LOCAL_NODE) |
667 | return norma_get_special_port(host_priv, node, id, portp); | |
1c79356b | 668 | #endif |
55e303ae A |
669 | |
670 | host_lock(host_priv); | |
671 | port = realhost.special[id]; | |
672 | *portp = ipc_port_copy_send(port); | |
673 | host_unlock(host_priv); | |
674 | ||
675 | return KERN_SUCCESS; | |
676 | } | |
677 | ||
678 | ||
679 | /* | |
680 | * host_get_io_master | |
681 | * | |
682 | * Return the IO master access port for this host. | |
683 | */ | |
684 | kern_return_t | |
685 | host_get_io_master( | |
686 | host_t host, | |
687 | io_master_t *io_masterp) | |
688 | { | |
689 | if (host == HOST_NULL) | |
690 | return KERN_INVALID_ARGUMENT; | |
691 | ||
692 | return (host_get_io_master_port(host_priv_self(), io_masterp)); | |
1c79356b A |
693 | } |
694 | ||
695 | host_t | |
696 | host_self(void) | |
697 | { | |
698 | return &realhost; | |
699 | } | |
700 | ||
701 | host_priv_t | |
702 | host_priv_self(void) | |
703 | { | |
704 | return &realhost; | |
705 | } | |
706 | ||
707 | host_security_t | |
708 | host_security_self(void) | |
709 | { | |
710 | return &realhost; | |
711 | } | |
712 |