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