]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/host.c
xnu-1504.9.17.tar.gz
[apple/xnu.git] / osfmk / kern / host.c
1 /*
2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
3 *
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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
65 #include <mach/mach_types.h>
66 #include <mach/boolean.h>
67 #include <mach/host_info.h>
68 #include <mach/host_special_ports.h>
69 #include <mach/kern_return.h>
70 #include <mach/machine.h>
71 #include <mach/port.h>
72 #include <mach/processor_info.h>
73 #include <mach/vm_param.h>
74 #include <mach/processor.h>
75 #include <mach/mach_host_server.h>
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
91 host_data_t realhost;
92
93 kern_return_t
94 host_processors(
95 host_priv_t host_priv,
96 processor_array_t *out_array,
97 mach_msg_type_number_t *countp)
98 {
99 register processor_t processor, *tp;
100 void *addr;
101 unsigned int count, i;
102
103 if (host_priv == HOST_PRIV_NULL)
104 return (KERN_INVALID_ARGUMENT);
105
106 assert(host_priv == &realhost);
107
108 count = processor_count;
109 assert(count != 0);
110
111 addr = kalloc((vm_size_t) (count * sizeof(mach_port_t)));
112 if (addr == 0)
113 return (KERN_RESOURCE_SHORTAGE);
114
115 tp = (processor_t *) addr;
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 }
126
127 *countp = count;
128 *out_array = (processor_array_t)addr;
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
137 return (KERN_SUCCESS);
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)
149 return (KERN_INVALID_ARGUMENT);
150
151 switch (flavor) {
152
153 case HOST_BASIC_INFO:
154 {
155 register host_basic_info_t basic_info;
156 register int master_id;
157
158 /*
159 * Basic information about this host.
160 */
161 if (*count < HOST_BASIC_INFO_OLD_COUNT)
162 return (KERN_FAILURE);
163
164 basic_info = (host_basic_info_t) info;
165
166 basic_info->memory_size = machine_info.memory_size;
167 basic_info->max_cpus = machine_info.max_cpus;
168 basic_info->avail_cpus = processor_avail_count;
169 master_id = master_processor->cpu_id;
170 basic_info->cpu_type = slot_type(master_id);
171 basic_info->cpu_subtype = slot_subtype(master_id);
172
173 if (*count >= HOST_BASIC_INFO_COUNT) {
174 basic_info->cpu_threadtype = slot_threadtype(master_id);
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 }
185
186 return (KERN_SUCCESS);
187 }
188
189 case HOST_SCHED_INFO:
190 {
191 register host_sched_info_t sched_info;
192
193 /*
194 * Return scheduler information.
195 */
196 if (*count < HOST_SCHED_INFO_COUNT)
197 return (KERN_FAILURE);
198
199 sched_info = (host_sched_info_t) info;
200
201 sched_info->min_timeout =
202 sched_info->min_quantum = std_quantum_us / 1000;
203
204 *count = HOST_SCHED_INFO_COUNT;
205
206 return (KERN_SUCCESS);
207 }
208
209 case HOST_RESOURCE_SIZES:
210 {
211 /*
212 * Return sizes of kernel data structures
213 */
214 if (*count < HOST_RESOURCE_SIZES_COUNT)
215 return (KERN_FAILURE);
216
217 /* XXX Fail until ledgers are implemented */
218 return (KERN_INVALID_ARGUMENT);
219 }
220
221 case HOST_PRIORITY_INFO:
222 {
223 register host_priority_info_t priority_info;
224
225 if (*count < HOST_PRIORITY_INFO_COUNT)
226 return (KERN_FAILURE);
227
228 priority_info = (host_priority_info_t) info;
229
230 priority_info->kernel_priority = MINPRI_KERNEL;
231 priority_info->system_priority = MINPRI_KERNEL;
232 priority_info->server_priority = MINPRI_RESERVED;
233 priority_info->user_priority = BASEPRI_DEFAULT;
234 priority_info->depress_priority = DEPRESSPRI;
235 priority_info->idle_priority = IDLEPRI;
236 priority_info->minimum_priority = MINPRI_USER;
237 priority_info->maximum_priority = MAXPRI_RESERVED;
238
239 *count = HOST_PRIORITY_INFO_COUNT;
240
241 return (KERN_SUCCESS);
242 }
243
244 /*
245 * Gestalt for various trap facilities.
246 */
247 case HOST_MACH_MSG_TRAP:
248 case HOST_SEMAPHORE_TRAPS:
249 {
250 *count = 0;
251 return (KERN_SUCCESS);
252 }
253
254 default:
255 return (KERN_INVALID_ARGUMENT);
256 }
257 }
258
259 kern_return_t
260 host_statistics(
261 host_t host,
262 host_flavor_t flavor,
263 host_info_t info,
264 mach_msg_type_number_t *count)
265 {
266 uint32_t i;
267
268 if (host == HOST_NULL)
269 return (KERN_INVALID_HOST);
270
271 switch(flavor) {
272
273 case HOST_LOAD_INFO:
274 {
275 host_load_info_t load_info;
276
277 if (*count < HOST_LOAD_INFO_COUNT)
278 return (KERN_FAILURE);
279
280 load_info = (host_load_info_t) info;
281
282 bcopy((char *) avenrun,
283 (char *) load_info->avenrun, sizeof avenrun);
284 bcopy((char *) mach_factor,
285 (char *) load_info->mach_factor, sizeof mach_factor);
286
287 *count = HOST_LOAD_INFO_COUNT;
288 return (KERN_SUCCESS);
289 }
290
291 case HOST_VM_INFO:
292 {
293 register processor_t processor;
294 register vm_statistics64_t stat;
295 vm_statistics64_data_t host_vm_stat;
296 vm_statistics_t stat32;
297 mach_msg_type_number_t original_count;
298
299 if (*count < HOST_VM_INFO_REV0_COUNT)
300 return (KERN_FAILURE);
301
302 processor = processor_list;
303 stat = &PROCESSOR_DATA(processor, vm_stat);
304 host_vm_stat = *stat;
305
306 if (processor_count > 1) {
307 simple_lock(&processor_list_lock);
308
309 while ((processor = processor->processor_list) != NULL) {
310 stat = &PROCESSOR_DATA(processor, vm_stat);
311
312 host_vm_stat.zero_fill_count += stat->zero_fill_count;
313 host_vm_stat.reactivations += stat->reactivations;
314 host_vm_stat.pageins += stat->pageins;
315 host_vm_stat.pageouts += stat->pageouts;
316 host_vm_stat.faults += stat->faults;
317 host_vm_stat.cow_faults += stat->cow_faults;
318 host_vm_stat.lookups += stat->lookups;
319 host_vm_stat.hits += stat->hits;
320 }
321
322 simple_unlock(&processor_list_lock);
323 }
324
325 stat32 = (vm_statistics_t) info;
326
327 stat32->free_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_free_count + vm_page_speculative_count);
328 stat32->active_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_active_count);
329
330 if (vm_page_local_q) {
331 for (i = 0; i < vm_page_local_q_count; i++) {
332 struct vpl *lq;
333
334 lq = &vm_page_local_q[i].vpl_un.vpl;
335
336 stat32->active_count += VM_STATISTICS_TRUNCATE_TO_32_BIT(lq->vpl_count);
337 }
338 }
339 stat32->inactive_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_inactive_count);
340 #if CONFIG_EMBEDDED
341 stat32->wire_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_wire_count);
342 #else
343 stat32->wire_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_wire_count + vm_page_throttled_count + vm_lopage_free_count);
344 #endif
345 stat32->zero_fill_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.zero_fill_count);
346 stat32->reactivations = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.reactivations);
347 stat32->pageins = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.pageins);
348 stat32->pageouts = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.pageouts);
349 stat32->faults = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.faults);
350 stat32->cow_faults = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.cow_faults);
351 stat32->lookups = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.lookups);
352 stat32->hits = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.hits);
353
354 /*
355 * Fill in extra info added in later revisions of the
356 * vm_statistics data structure. Fill in only what can fit
357 * in the data structure the caller gave us !
358 */
359 original_count = *count;
360 *count = HOST_VM_INFO_REV0_COUNT; /* rev0 already filled in */
361 if (original_count >= HOST_VM_INFO_REV1_COUNT) {
362 /* rev1 added "purgeable" info */
363 stat32->purgeable_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_purgeable_count);
364 stat32->purges = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_purged_count);
365 *count = HOST_VM_INFO_REV1_COUNT;
366 }
367
368 if (original_count >= HOST_VM_INFO_REV2_COUNT) {
369 /* rev2 added "speculative" info */
370 stat32->speculative_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_speculative_count);
371 *count = HOST_VM_INFO_REV2_COUNT;
372 }
373
374 /* rev3 changed some of the fields to be 64-bit*/
375
376 return (KERN_SUCCESS);
377 }
378
379 case HOST_CPU_LOAD_INFO:
380 {
381 register processor_t processor;
382 host_cpu_load_info_t cpu_load_info;
383
384 if (*count < HOST_CPU_LOAD_INFO_COUNT)
385 return (KERN_FAILURE);
386
387 #define GET_TICKS_VALUE(processor, state, timer) \
388 MACRO_BEGIN \
389 cpu_load_info->cpu_ticks[(state)] += \
390 (uint32_t)(timer_grab(&PROCESSOR_DATA(processor, timer)) \
391 / hz_tick_interval); \
392 MACRO_END
393
394 cpu_load_info = (host_cpu_load_info_t)info;
395 cpu_load_info->cpu_ticks[CPU_STATE_USER] = 0;
396 cpu_load_info->cpu_ticks[CPU_STATE_SYSTEM] = 0;
397 cpu_load_info->cpu_ticks[CPU_STATE_IDLE] = 0;
398 cpu_load_info->cpu_ticks[CPU_STATE_NICE] = 0;
399
400 processor = processor_list;
401 GET_TICKS_VALUE(processor, CPU_STATE_USER, user_state);
402 GET_TICKS_VALUE(processor, CPU_STATE_SYSTEM, system_state);
403 GET_TICKS_VALUE(processor, CPU_STATE_IDLE, idle_state);
404
405 if (processor_count > 1) {
406 simple_lock(&processor_list_lock);
407
408 while ((processor = processor->processor_list) != NULL) {
409 GET_TICKS_VALUE(processor, CPU_STATE_USER, user_state);
410 GET_TICKS_VALUE(processor, CPU_STATE_SYSTEM, system_state);
411 GET_TICKS_VALUE(processor, CPU_STATE_IDLE, idle_state);
412 }
413
414 simple_unlock(&processor_list_lock);
415 }
416
417 *count = HOST_CPU_LOAD_INFO_COUNT;
418
419 return (KERN_SUCCESS);
420 }
421
422 default:
423 return (KERN_INVALID_ARGUMENT);
424 }
425 }
426
427
428 kern_return_t
429 host_statistics64(
430 host_t host,
431 host_flavor_t flavor,
432 host_info64_t info,
433 mach_msg_type_number_t *count)
434 {
435 uint32_t i;
436
437 if (host == HOST_NULL)
438 return (KERN_INVALID_HOST);
439
440 switch(flavor) {
441
442 case HOST_VM_INFO64: /* We were asked to get vm_statistics64 */
443 {
444 register processor_t processor;
445 register vm_statistics64_t stat;
446 vm_statistics64_data_t host_vm_stat;
447
448 if (*count < HOST_VM_INFO64_COUNT)
449 return (KERN_FAILURE);
450
451 processor = processor_list;
452 stat = &PROCESSOR_DATA(processor, vm_stat);
453 host_vm_stat = *stat;
454
455 if (processor_count > 1) {
456 simple_lock(&processor_list_lock);
457
458 while ((processor = processor->processor_list) != NULL) {
459 stat = &PROCESSOR_DATA(processor, vm_stat);
460
461 host_vm_stat.zero_fill_count += stat->zero_fill_count;
462 host_vm_stat.reactivations += stat->reactivations;
463 host_vm_stat.pageins += stat->pageins;
464 host_vm_stat.pageouts += stat->pageouts;
465 host_vm_stat.faults += stat->faults;
466 host_vm_stat.cow_faults += stat->cow_faults;
467 host_vm_stat.lookups += stat->lookups;
468 host_vm_stat.hits += stat->hits;
469 }
470
471 simple_unlock(&processor_list_lock);
472 }
473
474 stat = (vm_statistics64_t) info;
475
476 stat->free_count = vm_page_free_count + vm_page_speculative_count;
477 stat->active_count = vm_page_active_count;
478
479 if (vm_page_local_q) {
480 for (i = 0; i < vm_page_local_q_count; i++) {
481 struct vpl *lq;
482
483 lq = &vm_page_local_q[i].vpl_un.vpl;
484
485 stat->active_count += lq->vpl_count;
486 }
487 }
488 stat->inactive_count = vm_page_inactive_count;
489 #if CONFIG_EMBEDDED
490 stat->wire_count = vm_page_wire_count;
491 #else
492 stat->wire_count = vm_page_wire_count + vm_page_throttled_count + vm_lopage_free_count;
493 #endif
494 stat->zero_fill_count = host_vm_stat.zero_fill_count;
495 stat->reactivations = host_vm_stat.reactivations;
496 stat->pageins = host_vm_stat.pageins;
497 stat->pageouts = host_vm_stat.pageouts;
498 stat->faults = host_vm_stat.faults;
499 stat->cow_faults = host_vm_stat.cow_faults;
500 stat->lookups = host_vm_stat.lookups;
501 stat->hits = host_vm_stat.hits;
502
503 /* rev1 added "purgable" info */
504 stat->purgeable_count = vm_page_purgeable_count;
505 stat->purges = vm_page_purged_count;
506
507 /* rev2 added "speculative" info */
508 stat->speculative_count = vm_page_speculative_count;
509
510 *count = HOST_VM_INFO64_COUNT;
511
512 return(KERN_SUCCESS);
513 }
514
515 default: /* If we didn't recognize the flavor, send to host_statistics */
516 return(host_statistics(host, flavor, (host_info_t) info, count));
517 }
518 }
519
520
521 /*
522 * Get host statistics that require privilege.
523 * None for now, just call the un-privileged version.
524 */
525 kern_return_t
526 host_priv_statistics(
527 host_priv_t host_priv,
528 host_flavor_t flavor,
529 host_info_t info,
530 mach_msg_type_number_t *count)
531 {
532 return(host_statistics((host_t)host_priv, flavor, info, count));
533 }
534
535 kern_return_t
536 host_page_size(
537 host_t host,
538 vm_size_t *out_page_size)
539 {
540 if (host == HOST_NULL)
541 return(KERN_INVALID_ARGUMENT);
542
543 *out_page_size = PAGE_SIZE;
544
545 return(KERN_SUCCESS);
546 }
547
548 /*
549 * Return kernel version string (more than you ever
550 * wanted to know about what version of the kernel this is).
551 */
552 extern char version[];
553
554 kern_return_t
555 host_kernel_version(
556 host_t host,
557 kernel_version_t out_version)
558 {
559
560 if (host == HOST_NULL)
561 return(KERN_INVALID_ARGUMENT);
562
563 (void) strncpy(out_version, version, sizeof(kernel_version_t));
564
565 return(KERN_SUCCESS);
566 }
567
568 /*
569 * host_processor_sets:
570 *
571 * List all processor sets on the host.
572 */
573 kern_return_t
574 host_processor_sets(
575 host_priv_t host_priv,
576 processor_set_name_array_t *pset_list,
577 mach_msg_type_number_t *count)
578 {
579 void *addr;
580
581 if (host_priv == HOST_PRIV_NULL)
582 return (KERN_INVALID_ARGUMENT);
583
584 /*
585 * Allocate memory. Can be pageable because it won't be
586 * touched while holding a lock.
587 */
588
589 addr = kalloc((vm_size_t) sizeof(mach_port_t));
590 if (addr == 0)
591 return (KERN_RESOURCE_SHORTAGE);
592
593 /* do the conversion that Mig should handle */
594 *((ipc_port_t *) addr) = convert_pset_name_to_port(&pset0);
595
596 *pset_list = (processor_set_array_t)addr;
597 *count = 1;
598
599 return (KERN_SUCCESS);
600 }
601
602 /*
603 * host_processor_set_priv:
604 *
605 * Return control port for given processor set.
606 */
607 kern_return_t
608 host_processor_set_priv(
609 host_priv_t host_priv,
610 processor_set_t pset_name,
611 processor_set_t *pset)
612 {
613 if (host_priv == HOST_PRIV_NULL || pset_name == PROCESSOR_SET_NULL) {
614 *pset = PROCESSOR_SET_NULL;
615
616 return (KERN_INVALID_ARGUMENT);
617 }
618
619 *pset = pset_name;
620
621 return (KERN_SUCCESS);
622 }
623
624 /*
625 * host_processor_info
626 *
627 * Return info about the processors on this host. It will return
628 * the number of processors, and the specific type of info requested
629 * in an OOL array.
630 */
631 kern_return_t
632 host_processor_info(
633 host_t host,
634 processor_flavor_t flavor,
635 natural_t *out_pcount,
636 processor_info_array_t *out_array,
637 mach_msg_type_number_t *out_array_count)
638 {
639 kern_return_t result;
640 processor_t processor;
641 host_t thost;
642 processor_info_t info;
643 unsigned int icount, tcount;
644 unsigned int pcount, i;
645 vm_offset_t addr;
646 vm_size_t size, needed;
647 vm_map_copy_t copy;
648
649 if (host == HOST_NULL)
650 return (KERN_INVALID_ARGUMENT);
651
652 result = processor_info_count(flavor, &icount);
653 if (result != KERN_SUCCESS)
654 return (result);
655
656 pcount = processor_count;
657 assert(pcount != 0);
658
659 needed = pcount * icount * sizeof(natural_t);
660 size = round_page(needed);
661 result = kmem_alloc(ipc_kernel_map, &addr, size);
662 if (result != KERN_SUCCESS)
663 return (KERN_RESOURCE_SHORTAGE);
664
665 info = (processor_info_t) addr;
666 processor = processor_list;
667 tcount = icount;
668
669 result = processor_info(processor, flavor, &thost, info, &tcount);
670 if (result != KERN_SUCCESS) {
671 kmem_free(ipc_kernel_map, addr, size);
672 return (result);
673 }
674
675 if (pcount > 1) {
676 for (i = 1; i < pcount; i++) {
677 simple_lock(&processor_list_lock);
678 processor = processor->processor_list;
679 simple_unlock(&processor_list_lock);
680
681 info += icount;
682 tcount = icount;
683 result = processor_info(processor, flavor, &thost, info, &tcount);
684 if (result != KERN_SUCCESS) {
685 kmem_free(ipc_kernel_map, addr, size);
686 return (result);
687 }
688 }
689 }
690
691 if (size != needed)
692 bzero((char *) addr + needed, size - needed);
693
694 result = vm_map_unwire(ipc_kernel_map, vm_map_trunc_page(addr),
695 vm_map_round_page(addr + size), FALSE);
696 assert(result == KERN_SUCCESS);
697 result = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)addr,
698 (vm_map_size_t)size, TRUE, &copy);
699 assert(result == KERN_SUCCESS);
700
701 *out_pcount = pcount;
702 *out_array = (processor_info_array_t) copy;
703 *out_array_count = pcount * icount;
704
705 return (KERN_SUCCESS);
706 }
707
708 /*
709 * Kernel interface for setting a special port.
710 */
711 kern_return_t
712 kernel_set_special_port(
713 host_priv_t host_priv,
714 int id,
715 ipc_port_t port)
716 {
717 ipc_port_t old_port;
718
719 host_lock(host_priv);
720 old_port = host_priv->special[id];
721 host_priv->special[id] = port;
722 host_unlock(host_priv);
723 if (IP_VALID(old_port))
724 ipc_port_release_send(old_port);
725 return KERN_SUCCESS;
726 }
727
728 /*
729 * User interface for setting a special port.
730 *
731 * Only permits the user to set a user-owned special port
732 * ID, rejecting a kernel-owned special port ID.
733 *
734 * A special kernel port cannot be set up using this
735 * routine; use kernel_set_special_port() instead.
736 */
737 kern_return_t
738 host_set_special_port(
739 host_priv_t host_priv,
740 int id,
741 ipc_port_t port)
742 {
743 if (host_priv == HOST_PRIV_NULL ||
744 id <= HOST_MAX_SPECIAL_KERNEL_PORT || id > HOST_MAX_SPECIAL_PORT ) {
745 if (IP_VALID(port))
746 ipc_port_release_send(port);
747 return KERN_INVALID_ARGUMENT;
748 }
749
750 return kernel_set_special_port(host_priv, id, port);
751 }
752
753
754 /*
755 * User interface for retrieving a special port.
756 *
757 * Note that there is nothing to prevent a user special
758 * port from disappearing after it has been discovered by
759 * the caller; thus, using a special port can always result
760 * in a "port not valid" error.
761 */
762
763 kern_return_t
764 host_get_special_port(
765 host_priv_t host_priv,
766 __unused int node,
767 int id,
768 ipc_port_t *portp)
769 {
770 ipc_port_t port;
771
772 if (host_priv == HOST_PRIV_NULL ||
773 id == HOST_SECURITY_PORT || id > HOST_MAX_SPECIAL_PORT || id < 0)
774 return KERN_INVALID_ARGUMENT;
775
776 host_lock(host_priv);
777 port = realhost.special[id];
778 *portp = ipc_port_copy_send(port);
779 host_unlock(host_priv);
780
781 return KERN_SUCCESS;
782 }
783
784
785 /*
786 * host_get_io_master
787 *
788 * Return the IO master access port for this host.
789 */
790 kern_return_t
791 host_get_io_master(
792 host_t host,
793 io_master_t *io_masterp)
794 {
795 if (host == HOST_NULL)
796 return KERN_INVALID_ARGUMENT;
797
798 return (host_get_io_master_port(host_priv_self(), io_masterp));
799 }
800
801 host_t
802 host_self(void)
803 {
804 return &realhost;
805 }
806
807 host_priv_t
808 host_priv_self(void)
809 {
810 return &realhost;
811 }
812
813 host_security_t
814 host_security_self(void)
815 {
816 return &realhost;
817 }
818