]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
b0d623f7 | 2 | * Copyright (c) 2000-2009 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
3e170ce0 | 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. | |
3e170ce0 | 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. | |
3e170ce0 | 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. | |
3e170ce0 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
3e170ce0 | 31 | /* |
1c79356b A |
32 | * Mach Operating System |
33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
3e170ce0 | 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. | |
3e170ce0 | 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. | |
3e170ce0 | 45 | * |
1c79356b | 46 | * Carnegie Mellon requests users of this software to return to |
3e170ce0 | 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 | |
3e170ce0 | 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 | /* | |
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> | |
39236c6e | 78 | #include <mach/task_info.h> |
91447636 | 79 | |
490019cf A |
80 | #include <machine/commpage.h> |
81 | #include <machine/cpu_capabilities.h> | |
82 | ||
91447636 A |
83 | #include <kern/kern_types.h> |
84 | #include <kern/assert.h> | |
85 | #include <kern/kalloc.h> | |
86 | #include <kern/host.h> | |
87 | #include <kern/host_statistics.h> | |
88 | #include <kern/ipc_host.h> | |
89 | #include <kern/misc_protos.h> | |
90 | #include <kern/sched.h> | |
91 | #include <kern/processor.h> | |
39037602 | 92 | #include <kern/mach_node.h> // mach_node_port_changed() |
91447636 A |
93 | |
94 | #include <vm/vm_map.h> | |
39236c6e A |
95 | #include <vm/vm_purgeable_internal.h> |
96 | #include <vm/vm_pageout.h> | |
91447636 | 97 | |
39037602 | 98 | |
3e170ce0 A |
99 | #if CONFIG_ATM |
100 | #include <atm/atm_internal.h> | |
101 | #endif | |
102 | ||
103 | #if CONFIG_MACF | |
104 | #include <security/mac_mach_internal.h> | |
105 | #endif | |
106 | ||
39037602 A |
107 | #include <pexpert/pexpert.h> |
108 | ||
3e170ce0 | 109 | host_data_t realhost; |
1c79356b | 110 | |
6d2010ae A |
111 | vm_extmod_statistics_data_t host_extmod_statistics; |
112 | ||
1c79356b | 113 | kern_return_t |
3e170ce0 | 114 | host_processors(host_priv_t host_priv, processor_array_t * out_array, mach_msg_type_number_t * countp) |
1c79356b | 115 | { |
39037602 | 116 | processor_t processor, *tp; |
3e170ce0 A |
117 | void * addr; |
118 | unsigned int count, i; | |
1c79356b A |
119 | |
120 | if (host_priv == HOST_PRIV_NULL) | |
91447636 | 121 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
122 | |
123 | assert(host_priv == &realhost); | |
124 | ||
91447636 A |
125 | count = processor_count; |
126 | assert(count != 0); | |
1c79356b | 127 | |
3e170ce0 | 128 | addr = kalloc((vm_size_t)(count * sizeof(mach_port_t))); |
1c79356b | 129 | if (addr == 0) |
91447636 | 130 | return (KERN_RESOURCE_SHORTAGE); |
1c79356b | 131 | |
3e170ce0 | 132 | tp = (processor_t *)addr; |
91447636 A |
133 | *tp++ = processor = processor_list; |
134 | ||
135 | if (count > 1) { | |
136 | simple_lock(&processor_list_lock); | |
137 | ||
138 | for (i = 1; i < count; i++) | |
139 | *tp++ = processor = processor->processor_list; | |
140 | ||
141 | simple_unlock(&processor_list_lock); | |
142 | } | |
1c79356b A |
143 | |
144 | *countp = count; | |
91447636 | 145 | *out_array = (processor_array_t)addr; |
1c79356b A |
146 | |
147 | /* do the conversion that Mig should handle */ | |
3e170ce0 | 148 | tp = (processor_t *)addr; |
1c79356b | 149 | for (i = 0; i < count; i++) |
3e170ce0 | 150 | ((mach_port_t *)tp)[i] = (mach_port_t)convert_processor_to_port(tp[i]); |
1c79356b | 151 | |
91447636 | 152 | return (KERN_SUCCESS); |
1c79356b A |
153 | } |
154 | ||
155 | kern_return_t | |
3e170ce0 | 156 | host_info(host_t host, host_flavor_t flavor, host_info_t info, mach_msg_type_number_t * count) |
1c79356b | 157 | { |
1c79356b | 158 | if (host == HOST_NULL) |
91447636 | 159 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 160 | |
3e170ce0 A |
161 | switch (flavor) { |
162 | case HOST_BASIC_INFO: { | |
39037602 A |
163 | host_basic_info_t basic_info; |
164 | int master_id; | |
1c79356b A |
165 | |
166 | /* | |
167 | * Basic information about this host. | |
168 | */ | |
91447636 A |
169 | if (*count < HOST_BASIC_INFO_OLD_COUNT) |
170 | return (KERN_FAILURE); | |
1c79356b | 171 | |
3e170ce0 | 172 | basic_info = (host_basic_info_t)info; |
1c79356b | 173 | |
1c79356b | 174 | basic_info->memory_size = machine_info.memory_size; |
2d21ac55 A |
175 | basic_info->max_cpus = machine_info.max_cpus; |
176 | basic_info->avail_cpus = processor_avail_count; | |
b0d623f7 A |
177 | master_id = master_processor->cpu_id; |
178 | basic_info->cpu_type = slot_type(master_id); | |
179 | basic_info->cpu_subtype = slot_subtype(master_id); | |
91447636 A |
180 | |
181 | if (*count >= HOST_BASIC_INFO_COUNT) { | |
b0d623f7 | 182 | basic_info->cpu_threadtype = slot_threadtype(master_id); |
91447636 A |
183 | basic_info->physical_cpu = machine_info.physical_cpu; |
184 | basic_info->physical_cpu_max = machine_info.physical_cpu_max; | |
185 | basic_info->logical_cpu = machine_info.logical_cpu; | |
186 | basic_info->logical_cpu_max = machine_info.logical_cpu_max; | |
187 | basic_info->max_mem = machine_info.max_mem; | |
188 | ||
189 | *count = HOST_BASIC_INFO_COUNT; | |
190 | } else { | |
191 | *count = HOST_BASIC_INFO_OLD_COUNT; | |
192 | } | |
1c79356b | 193 | |
91447636 | 194 | return (KERN_SUCCESS); |
1c79356b A |
195 | } |
196 | ||
3e170ce0 | 197 | case HOST_SCHED_INFO: { |
39037602 | 198 | host_sched_info_t sched_info; |
6d2010ae A |
199 | uint32_t quantum_time; |
200 | uint64_t quantum_ns; | |
1c79356b A |
201 | |
202 | /* | |
203 | * Return scheduler information. | |
204 | */ | |
205 | if (*count < HOST_SCHED_INFO_COUNT) | |
91447636 | 206 | return (KERN_FAILURE); |
1c79356b | 207 | |
3e170ce0 | 208 | sched_info = (host_sched_info_t)info; |
1c79356b | 209 | |
6d2010ae A |
210 | quantum_time = SCHED(initial_quantum_size)(THREAD_NULL); |
211 | absolutetime_to_nanoseconds(quantum_time, &quantum_ns); | |
212 | ||
3e170ce0 | 213 | sched_info->min_timeout = sched_info->min_quantum = (uint32_t)(quantum_ns / 1000 / 1000); |
1c79356b A |
214 | |
215 | *count = HOST_SCHED_INFO_COUNT; | |
216 | ||
91447636 | 217 | return (KERN_SUCCESS); |
1c79356b A |
218 | } |
219 | ||
3e170ce0 | 220 | case HOST_RESOURCE_SIZES: { |
1c79356b A |
221 | /* |
222 | * Return sizes of kernel data structures | |
223 | */ | |
224 | if (*count < HOST_RESOURCE_SIZES_COUNT) | |
91447636 | 225 | return (KERN_FAILURE); |
1c79356b A |
226 | |
227 | /* XXX Fail until ledgers are implemented */ | |
91447636 | 228 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 229 | } |
3e170ce0 A |
230 | |
231 | case HOST_PRIORITY_INFO: { | |
39037602 | 232 | host_priority_info_t priority_info; |
1c79356b A |
233 | |
234 | if (*count < HOST_PRIORITY_INFO_COUNT) | |
91447636 | 235 | return (KERN_FAILURE); |
1c79356b | 236 | |
3e170ce0 | 237 | priority_info = (host_priority_info_t)info; |
1c79356b | 238 | |
3e170ce0 A |
239 | priority_info->kernel_priority = MINPRI_KERNEL; |
240 | priority_info->system_priority = MINPRI_KERNEL; | |
241 | priority_info->server_priority = MINPRI_RESERVED; | |
242 | priority_info->user_priority = BASEPRI_DEFAULT; | |
243 | priority_info->depress_priority = DEPRESSPRI; | |
244 | priority_info->idle_priority = IDLEPRI; | |
245 | priority_info->minimum_priority = MINPRI_USER; | |
246 | priority_info->maximum_priority = MAXPRI_RESERVED; | |
1c79356b A |
247 | |
248 | *count = HOST_PRIORITY_INFO_COUNT; | |
249 | ||
91447636 | 250 | return (KERN_SUCCESS); |
1c79356b A |
251 | } |
252 | ||
253 | /* | |
9bccf70c | 254 | * Gestalt for various trap facilities. |
1c79356b | 255 | */ |
9bccf70c | 256 | case HOST_MACH_MSG_TRAP: |
3e170ce0 | 257 | case HOST_SEMAPHORE_TRAPS: { |
1c79356b | 258 | *count = 0; |
91447636 | 259 | return (KERN_SUCCESS); |
1c79356b A |
260 | } |
261 | ||
39037602 A |
262 | case HOST_CAN_HAS_DEBUGGER: { |
263 | host_can_has_debugger_info_t can_has_debugger_info; | |
264 | ||
265 | if (*count < HOST_CAN_HAS_DEBUGGER_COUNT) | |
266 | return (KERN_FAILURE); | |
267 | ||
268 | can_has_debugger_info = (host_can_has_debugger_info_t)info; | |
269 | can_has_debugger_info->can_has_debugger = PE_i_can_has_debugger(NULL); | |
270 | *count = HOST_CAN_HAS_DEBUGGER_COUNT; | |
271 | ||
272 | return KERN_SUCCESS; | |
273 | } | |
274 | ||
3e170ce0 | 275 | case HOST_VM_PURGABLE: { |
39236c6e A |
276 | if (*count < HOST_VM_PURGABLE_COUNT) |
277 | return (KERN_FAILURE); | |
278 | ||
3e170ce0 | 279 | vm_purgeable_stats((vm_purgeable_info_t)info, NULL); |
39236c6e A |
280 | |
281 | *count = HOST_VM_PURGABLE_COUNT; | |
282 | return (KERN_SUCCESS); | |
283 | } | |
284 | ||
3e170ce0 A |
285 | case HOST_DEBUG_INFO_INTERNAL: { |
286 | #if DEVELOPMENT || DEBUG | |
287 | if (*count < HOST_DEBUG_INFO_INTERNAL_COUNT) | |
288 | return (KERN_FAILURE); | |
289 | ||
290 | host_debug_info_internal_t debug_info = (host_debug_info_internal_t)info; | |
291 | bzero(debug_info, sizeof(host_debug_info_internal_data_t)); | |
292 | *count = HOST_DEBUG_INFO_INTERNAL_COUNT; | |
293 | ||
294 | #if CONFIG_COALITIONS | |
295 | debug_info->config_coalitions = 1; | |
296 | #endif | |
297 | #if CONFIG_BANK | |
298 | debug_info->config_bank = 1; | |
299 | #endif | |
300 | #if CONFIG_ATM | |
301 | debug_info->config_atm = 1; | |
302 | #endif | |
303 | #if CONFIG_CSR | |
304 | debug_info->config_csr = 1; | |
305 | #endif | |
306 | return (KERN_SUCCESS); | |
307 | #else /* DEVELOPMENT || DEBUG */ | |
308 | return (KERN_NOT_SUPPORTED); | |
309 | #endif | |
310 | } | |
311 | ||
312 | default: return (KERN_INVALID_ARGUMENT); | |
1c79356b A |
313 | } |
314 | } | |
315 | ||
316 | kern_return_t | |
3e170ce0 | 317 | host_statistics(host_t host, host_flavor_t flavor, host_info_t info, mach_msg_type_number_t * count) |
1c79356b | 318 | { |
3e170ce0 | 319 | uint32_t i; |
1c79356b A |
320 | |
321 | if (host == HOST_NULL) | |
91447636 | 322 | return (KERN_INVALID_HOST); |
1c79356b | 323 | |
3e170ce0 A |
324 | switch (flavor) { |
325 | case HOST_LOAD_INFO: { | |
326 | host_load_info_t load_info; | |
1c79356b A |
327 | |
328 | if (*count < HOST_LOAD_INFO_COUNT) | |
91447636 | 329 | return (KERN_FAILURE); |
1c79356b | 330 | |
3e170ce0 | 331 | load_info = (host_load_info_t)info; |
1c79356b | 332 | |
3e170ce0 A |
333 | bcopy((char *)avenrun, (char *)load_info->avenrun, sizeof avenrun); |
334 | bcopy((char *)mach_factor, (char *)load_info->mach_factor, sizeof mach_factor); | |
1c79356b A |
335 | |
336 | *count = HOST_LOAD_INFO_COUNT; | |
91447636 A |
337 | return (KERN_SUCCESS); |
338 | } | |
339 | ||
3e170ce0 | 340 | case HOST_VM_INFO: { |
39037602 A |
341 | processor_t processor; |
342 | vm_statistics64_t stat; | |
3e170ce0 A |
343 | vm_statistics64_data_t host_vm_stat; |
344 | vm_statistics_t stat32; | |
345 | mach_msg_type_number_t original_count; | |
346 | ||
91447636 A |
347 | if (*count < HOST_VM_INFO_REV0_COUNT) |
348 | return (KERN_FAILURE); | |
1c79356b | 349 | |
91447636 A |
350 | processor = processor_list; |
351 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
1c79356b | 352 | host_vm_stat = *stat; |
91447636 A |
353 | |
354 | if (processor_count > 1) { | |
355 | simple_lock(&processor_list_lock); | |
356 | ||
357 | while ((processor = processor->processor_list) != NULL) { | |
358 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
359 | ||
3e170ce0 | 360 | host_vm_stat.zero_fill_count += stat->zero_fill_count; |
91447636 | 361 | host_vm_stat.reactivations += stat->reactivations; |
1c79356b A |
362 | host_vm_stat.pageins += stat->pageins; |
363 | host_vm_stat.pageouts += stat->pageouts; | |
364 | host_vm_stat.faults += stat->faults; | |
365 | host_vm_stat.cow_faults += stat->cow_faults; | |
366 | host_vm_stat.lookups += stat->lookups; | |
367 | host_vm_stat.hits += stat->hits; | |
368 | } | |
91447636 A |
369 | |
370 | simple_unlock(&processor_list_lock); | |
1c79356b | 371 | } |
1c79356b | 372 | |
3e170ce0 | 373 | stat32 = (vm_statistics_t)info; |
b0d623f7 A |
374 | |
375 | stat32->free_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_free_count + vm_page_speculative_count); | |
376 | stat32->active_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_active_count); | |
3e170ce0 | 377 | |
b0d623f7 A |
378 | if (vm_page_local_q) { |
379 | for (i = 0; i < vm_page_local_q_count; i++) { | |
3e170ce0 | 380 | struct vpl * lq; |
b0d623f7 A |
381 | |
382 | lq = &vm_page_local_q[i].vpl_un.vpl; | |
383 | ||
384 | stat32->active_count += VM_STATISTICS_TRUNCATE_TO_32_BIT(lq->vpl_count); | |
385 | } | |
386 | } | |
387 | stat32->inactive_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_inactive_count); | |
0b4c1975 | 388 | stat32->wire_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_wire_count + vm_page_throttled_count + vm_lopage_free_count); |
b0d623f7 A |
389 | stat32->zero_fill_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.zero_fill_count); |
390 | stat32->reactivations = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.reactivations); | |
391 | stat32->pageins = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.pageins); | |
392 | stat32->pageouts = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.pageouts); | |
393 | stat32->faults = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.faults); | |
394 | stat32->cow_faults = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.cow_faults); | |
395 | stat32->lookups = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.lookups); | |
396 | stat32->hits = VM_STATISTICS_TRUNCATE_TO_32_BIT(host_vm_stat.hits); | |
91447636 | 397 | |
2d21ac55 A |
398 | /* |
399 | * Fill in extra info added in later revisions of the | |
400 | * vm_statistics data structure. Fill in only what can fit | |
401 | * in the data structure the caller gave us ! | |
402 | */ | |
403 | original_count = *count; | |
404 | *count = HOST_VM_INFO_REV0_COUNT; /* rev0 already filled in */ | |
405 | if (original_count >= HOST_VM_INFO_REV1_COUNT) { | |
406 | /* rev1 added "purgeable" info */ | |
b0d623f7 A |
407 | stat32->purgeable_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_purgeable_count); |
408 | stat32->purges = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_purged_count); | |
2d21ac55 A |
409 | *count = HOST_VM_INFO_REV1_COUNT; |
410 | } | |
b0d623f7 | 411 | |
2d21ac55 A |
412 | if (original_count >= HOST_VM_INFO_REV2_COUNT) { |
413 | /* rev2 added "speculative" info */ | |
b0d623f7 | 414 | stat32->speculative_count = VM_STATISTICS_TRUNCATE_TO_32_BIT(vm_page_speculative_count); |
2d21ac55 | 415 | *count = HOST_VM_INFO_REV2_COUNT; |
91447636 A |
416 | } |
417 | ||
b0d623f7 A |
418 | /* rev3 changed some of the fields to be 64-bit*/ |
419 | ||
91447636 A |
420 | return (KERN_SUCCESS); |
421 | } | |
3e170ce0 A |
422 | |
423 | case HOST_CPU_LOAD_INFO: { | |
39037602 | 424 | processor_t processor; |
3e170ce0 | 425 | host_cpu_load_info_t cpu_load_info; |
1c79356b A |
426 | |
427 | if (*count < HOST_CPU_LOAD_INFO_COUNT) | |
91447636 A |
428 | return (KERN_FAILURE); |
429 | ||
3e170ce0 A |
430 | #define GET_TICKS_VALUE(state, ticks) \ |
431 | MACRO_BEGIN cpu_load_info->cpu_ticks[(state)] += (uint32_t)(ticks / hz_tick_interval); \ | |
432 | MACRO_END | |
433 | #define GET_TICKS_VALUE_FROM_TIMER(processor, state, timer) \ | |
434 | MACRO_BEGIN GET_TICKS_VALUE(state, timer_grab(&PROCESSOR_DATA(processor, timer))); \ | |
435 | MACRO_END | |
1c79356b | 436 | |
91447636 | 437 | cpu_load_info = (host_cpu_load_info_t)info; |
1c79356b | 438 | cpu_load_info->cpu_ticks[CPU_STATE_USER] = 0; |
1c79356b A |
439 | cpu_load_info->cpu_ticks[CPU_STATE_SYSTEM] = 0; |
440 | cpu_load_info->cpu_ticks[CPU_STATE_IDLE] = 0; | |
2d21ac55 | 441 | cpu_load_info->cpu_ticks[CPU_STATE_NICE] = 0; |
91447636 | 442 | |
6d2010ae | 443 | simple_lock(&processor_list_lock); |
91447636 | 444 | |
6d2010ae | 445 | for (processor = processor_list; processor != NULL; processor = processor->processor_list) { |
3e170ce0 A |
446 | timer_t idle_state; |
447 | uint64_t idle_time_snapshot1, idle_time_snapshot2; | |
448 | uint64_t idle_time_tstamp1, idle_time_tstamp2; | |
449 | ||
39236c6e | 450 | /* See discussion in processor_info(PROCESSOR_CPU_LOAD_INFO) */ |
91447636 | 451 | |
39236c6e | 452 | GET_TICKS_VALUE_FROM_TIMER(processor, CPU_STATE_USER, user_state); |
316670eb | 453 | if (precise_user_kernel_time) { |
39236c6e | 454 | GET_TICKS_VALUE_FROM_TIMER(processor, CPU_STATE_SYSTEM, system_state); |
316670eb A |
455 | } else { |
456 | /* system_state may represent either sys or user */ | |
39236c6e | 457 | GET_TICKS_VALUE_FROM_TIMER(processor, CPU_STATE_USER, system_state); |
316670eb | 458 | } |
6d2010ae A |
459 | |
460 | idle_state = &PROCESSOR_DATA(processor, idle_state); | |
39236c6e A |
461 | idle_time_snapshot1 = timer_grab(idle_state); |
462 | idle_time_tstamp1 = idle_state->tstamp; | |
3e170ce0 | 463 | |
39236c6e A |
464 | if (PROCESSOR_DATA(processor, current_state) != idle_state) { |
465 | /* Processor is non-idle, so idle timer should be accurate */ | |
466 | GET_TICKS_VALUE_FROM_TIMER(processor, CPU_STATE_IDLE, idle_state); | |
467 | } else if ((idle_time_snapshot1 != (idle_time_snapshot2 = timer_grab(idle_state))) || | |
3e170ce0 | 468 | (idle_time_tstamp1 != (idle_time_tstamp2 = idle_state->tstamp))) { |
39236c6e A |
469 | /* Idle timer is being updated concurrently, second stamp is good enough */ |
470 | GET_TICKS_VALUE(CPU_STATE_IDLE, idle_time_snapshot2); | |
471 | } else { | |
472 | /* | |
473 | * Idle timer may be very stale. Fortunately we have established | |
474 | * that idle_time_snapshot1 and idle_time_tstamp1 are unchanging | |
475 | */ | |
476 | idle_time_snapshot1 += mach_absolute_time() - idle_time_tstamp1; | |
3e170ce0 | 477 | |
39236c6e | 478 | GET_TICKS_VALUE(CPU_STATE_IDLE, idle_time_snapshot1); |
6d2010ae | 479 | } |
1c79356b | 480 | } |
6d2010ae | 481 | simple_unlock(&processor_list_lock); |
316670eb | 482 | |
1c79356b | 483 | *count = HOST_CPU_LOAD_INFO_COUNT; |
91447636 A |
484 | |
485 | return (KERN_SUCCESS); | |
486 | } | |
1c79356b | 487 | |
3e170ce0 | 488 | case HOST_EXPIRED_TASK_INFO: { |
4b17d6b6 A |
489 | if (*count < TASK_POWER_INFO_COUNT) { |
490 | return (KERN_FAILURE); | |
491 | } | |
492 | ||
493 | task_power_info_t tinfo = (task_power_info_t)info; | |
494 | ||
495 | tinfo->task_interrupt_wakeups = dead_task_statistics.task_interrupt_wakeups; | |
496 | tinfo->task_platform_idle_wakeups = dead_task_statistics.task_platform_idle_wakeups; | |
497 | ||
498 | tinfo->task_timer_wakeups_bin_1 = dead_task_statistics.task_timer_wakeups_bin_1; | |
39236c6e | 499 | |
4b17d6b6 A |
500 | tinfo->task_timer_wakeups_bin_2 = dead_task_statistics.task_timer_wakeups_bin_2; |
501 | ||
502 | tinfo->total_user = dead_task_statistics.total_user_time; | |
503 | tinfo->total_system = dead_task_statistics.total_system_time; | |
504 | ||
505 | return (KERN_SUCCESS); | |
39236c6e | 506 | } |
3e170ce0 | 507 | default: return (KERN_INVALID_ARGUMENT); |
1c79356b A |
508 | } |
509 | } | |
510 | ||
3e170ce0 | 511 | extern uint32_t c_segment_pages_compressed; |
b0d623f7 A |
512 | |
513 | kern_return_t | |
3e170ce0 | 514 | host_statistics64(host_t host, host_flavor_t flavor, host_info64_t info, mach_msg_type_number_t * count) |
b0d623f7 | 515 | { |
3e170ce0 A |
516 | uint32_t i; |
517 | ||
b0d623f7 A |
518 | if (host == HOST_NULL) |
519 | return (KERN_INVALID_HOST); | |
b0d623f7 | 520 | |
3e170ce0 A |
521 | switch (flavor) { |
522 | case HOST_VM_INFO64: /* We were asked to get vm_statistics64 */ | |
523 | { | |
39037602 A |
524 | processor_t processor; |
525 | vm_statistics64_t stat; | |
3e170ce0 A |
526 | vm_statistics64_data_t host_vm_stat; |
527 | mach_msg_type_number_t original_count; | |
528 | unsigned int local_q_internal_count; | |
529 | unsigned int local_q_external_count; | |
530 | ||
531 | if (*count < HOST_VM_INFO64_REV0_COUNT) | |
532 | return (KERN_FAILURE); | |
533 | ||
534 | processor = processor_list; | |
535 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
536 | host_vm_stat = *stat; | |
537 | ||
538 | if (processor_count > 1) { | |
539 | simple_lock(&processor_list_lock); | |
540 | ||
541 | while ((processor = processor->processor_list) != NULL) { | |
542 | stat = &PROCESSOR_DATA(processor, vm_stat); | |
543 | ||
544 | host_vm_stat.zero_fill_count += stat->zero_fill_count; | |
545 | host_vm_stat.reactivations += stat->reactivations; | |
546 | host_vm_stat.pageins += stat->pageins; | |
547 | host_vm_stat.pageouts += stat->pageouts; | |
548 | host_vm_stat.faults += stat->faults; | |
549 | host_vm_stat.cow_faults += stat->cow_faults; | |
550 | host_vm_stat.lookups += stat->lookups; | |
551 | host_vm_stat.hits += stat->hits; | |
552 | host_vm_stat.compressions += stat->compressions; | |
553 | host_vm_stat.decompressions += stat->decompressions; | |
554 | host_vm_stat.swapins += stat->swapins; | |
555 | host_vm_stat.swapouts += stat->swapouts; | |
39236c6e | 556 | } |
b0d623f7 | 557 | |
3e170ce0 | 558 | simple_unlock(&processor_list_lock); |
b0d623f7 A |
559 | } |
560 | ||
3e170ce0 A |
561 | stat = (vm_statistics64_t)info; |
562 | ||
563 | stat->free_count = vm_page_free_count + vm_page_speculative_count; | |
564 | stat->active_count = vm_page_active_count; | |
6d2010ae | 565 | |
3e170ce0 A |
566 | local_q_internal_count = 0; |
567 | local_q_external_count = 0; | |
568 | if (vm_page_local_q) { | |
569 | for (i = 0; i < vm_page_local_q_count; i++) { | |
570 | struct vpl * lq; | |
6d2010ae | 571 | |
3e170ce0 | 572 | lq = &vm_page_local_q[i].vpl_un.vpl; |
6d2010ae | 573 | |
3e170ce0 A |
574 | stat->active_count += lq->vpl_count; |
575 | local_q_internal_count += lq->vpl_internal_count; | |
576 | local_q_external_count += lq->vpl_external_count; | |
577 | } | |
578 | } | |
579 | stat->inactive_count = vm_page_inactive_count; | |
580 | stat->wire_count = vm_page_wire_count + vm_page_throttled_count + vm_lopage_free_count; | |
581 | stat->zero_fill_count = host_vm_stat.zero_fill_count; | |
582 | stat->reactivations = host_vm_stat.reactivations; | |
583 | stat->pageins = host_vm_stat.pageins; | |
584 | stat->pageouts = host_vm_stat.pageouts; | |
585 | stat->faults = host_vm_stat.faults; | |
586 | stat->cow_faults = host_vm_stat.cow_faults; | |
587 | stat->lookups = host_vm_stat.lookups; | |
588 | stat->hits = host_vm_stat.hits; | |
589 | ||
590 | stat->purgeable_count = vm_page_purgeable_count; | |
591 | stat->purges = vm_page_purged_count; | |
592 | ||
593 | stat->speculative_count = vm_page_speculative_count; | |
6d2010ae | 594 | |
3e170ce0 A |
595 | /* |
596 | * Fill in extra info added in later revisions of the | |
597 | * vm_statistics data structure. Fill in only what can fit | |
598 | * in the data structure the caller gave us ! | |
599 | */ | |
600 | original_count = *count; | |
601 | *count = HOST_VM_INFO64_REV0_COUNT; /* rev0 already filled in */ | |
602 | if (original_count >= HOST_VM_INFO64_REV1_COUNT) { | |
603 | /* rev1 added "throttled count" */ | |
604 | stat->throttled_count = vm_page_throttled_count; | |
605 | /* rev1 added "compression" info */ | |
606 | stat->compressor_page_count = VM_PAGE_COMPRESSOR_COUNT; | |
607 | stat->compressions = host_vm_stat.compressions; | |
608 | stat->decompressions = host_vm_stat.decompressions; | |
609 | stat->swapins = host_vm_stat.swapins; | |
610 | stat->swapouts = host_vm_stat.swapouts; | |
611 | /* rev1 added: | |
612 | * "external page count" | |
613 | * "anonymous page count" | |
614 | * "total # of pages (uncompressed) held in the compressor" | |
615 | */ | |
616 | stat->external_page_count = (vm_page_pageable_external_count + local_q_external_count); | |
617 | stat->internal_page_count = (vm_page_pageable_internal_count + local_q_internal_count); | |
618 | stat->total_uncompressed_pages_in_compressor = c_segment_pages_compressed; | |
619 | *count = HOST_VM_INFO64_REV1_COUNT; | |
6d2010ae A |
620 | } |
621 | ||
3e170ce0 | 622 | return (KERN_SUCCESS); |
b0d623f7 | 623 | } |
b0d623f7 | 624 | |
3e170ce0 A |
625 | case HOST_EXTMOD_INFO64: /* We were asked to get vm_statistics64 */ |
626 | { | |
627 | vm_extmod_statistics_t out_extmod_statistics; | |
628 | ||
629 | if (*count < HOST_EXTMOD_INFO64_COUNT) | |
630 | return (KERN_FAILURE); | |
631 | ||
632 | out_extmod_statistics = (vm_extmod_statistics_t)info; | |
633 | *out_extmod_statistics = host_extmod_statistics; | |
634 | ||
635 | *count = HOST_EXTMOD_INFO64_COUNT; | |
636 | ||
637 | return (KERN_SUCCESS); | |
638 | } | |
639 | ||
640 | default: /* If we didn't recognize the flavor, send to host_statistics */ | |
641 | return (host_statistics(host, flavor, (host_info_t)info, count)); | |
642 | } | |
643 | } | |
b0d623f7 | 644 | |
1c79356b A |
645 | /* |
646 | * Get host statistics that require privilege. | |
647 | * None for now, just call the un-privileged version. | |
648 | */ | |
649 | kern_return_t | |
3e170ce0 | 650 | host_priv_statistics(host_priv_t host_priv, host_flavor_t flavor, host_info_t info, mach_msg_type_number_t * count) |
1c79356b | 651 | { |
3e170ce0 | 652 | return (host_statistics((host_t)host_priv, flavor, info, count)); |
1c79356b A |
653 | } |
654 | ||
6d2010ae | 655 | kern_return_t |
3e170ce0 | 656 | set_sched_stats_active(boolean_t active) |
6d2010ae A |
657 | { |
658 | sched_stats_active = active; | |
3e170ce0 | 659 | return (KERN_SUCCESS); |
6d2010ae A |
660 | } |
661 | ||
6d2010ae | 662 | kern_return_t |
3e170ce0 | 663 | get_sched_statistics(struct _processor_statistics_np * out, uint32_t * count) |
6d2010ae A |
664 | { |
665 | processor_t processor; | |
666 | ||
667 | if (!sched_stats_active) { | |
3e170ce0 | 668 | return (KERN_FAILURE); |
6d2010ae A |
669 | } |
670 | ||
671 | simple_lock(&processor_list_lock); | |
3e170ce0 A |
672 | |
673 | if (*count < (processor_count + 1) * sizeof(struct _processor_statistics_np)) { /* One for RT */ | |
6d2010ae | 674 | simple_unlock(&processor_list_lock); |
3e170ce0 | 675 | return (KERN_FAILURE); |
6d2010ae A |
676 | } |
677 | ||
678 | processor = processor_list; | |
679 | while (processor) { | |
3e170ce0 A |
680 | struct processor_sched_statistics * stats = &processor->processor_data.sched_stats; |
681 | ||
682 | out->ps_cpuid = processor->cpu_id; | |
683 | out->ps_csw_count = stats->csw_count; | |
684 | out->ps_preempt_count = stats->preempt_count; | |
685 | out->ps_preempted_rt_count = stats->preempted_rt_count; | |
686 | out->ps_preempted_by_rt_count = stats->preempted_by_rt_count; | |
687 | out->ps_rt_sched_count = stats->rt_sched_count; | |
688 | out->ps_interrupt_count = stats->interrupt_count; | |
689 | out->ps_ipi_count = stats->ipi_count; | |
690 | out->ps_timer_pop_count = stats->timer_pop_count; | |
691 | out->ps_runq_count_sum = SCHED(processor_runq_stats_count_sum)(processor); | |
692 | out->ps_idle_transitions = stats->idle_transitions; | |
693 | out->ps_quantum_timer_expirations = stats->quantum_timer_expirations; | |
6d2010ae A |
694 | |
695 | out++; | |
696 | processor = processor->processor_list; | |
697 | } | |
698 | ||
3e170ce0 | 699 | *count = (uint32_t)(processor_count * sizeof(struct _processor_statistics_np)); |
6d2010ae A |
700 | |
701 | simple_unlock(&processor_list_lock); | |
702 | ||
703 | /* And include RT Queue information */ | |
704 | bzero(out, sizeof(*out)); | |
705 | out->ps_cpuid = (-1); | |
706 | out->ps_runq_count_sum = rt_runq.runq_stats.count_sum; | |
707 | out++; | |
708 | *count += (uint32_t)sizeof(struct _processor_statistics_np); | |
709 | ||
3e170ce0 | 710 | return (KERN_SUCCESS); |
6d2010ae A |
711 | } |
712 | ||
1c79356b | 713 | kern_return_t |
3e170ce0 | 714 | host_page_size(host_t host, vm_size_t * out_page_size) |
1c79356b A |
715 | { |
716 | if (host == HOST_NULL) | |
3e170ce0 | 717 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 718 | |
3e170ce0 | 719 | *out_page_size = PAGE_SIZE; |
1c79356b | 720 | |
3e170ce0 | 721 | return (KERN_SUCCESS); |
1c79356b A |
722 | } |
723 | ||
724 | /* | |
725 | * Return kernel version string (more than you ever | |
726 | * wanted to know about what version of the kernel this is). | |
727 | */ | |
3e170ce0 | 728 | extern char version[]; |
1c79356b A |
729 | |
730 | kern_return_t | |
3e170ce0 | 731 | host_kernel_version(host_t host, kernel_version_t out_version) |
1c79356b | 732 | { |
1c79356b | 733 | if (host == HOST_NULL) |
3e170ce0 | 734 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 735 | |
3e170ce0 | 736 | (void)strncpy(out_version, version, sizeof(kernel_version_t)); |
1c79356b | 737 | |
3e170ce0 | 738 | return (KERN_SUCCESS); |
1c79356b A |
739 | } |
740 | ||
741 | /* | |
742 | * host_processor_sets: | |
743 | * | |
744 | * List all processor sets on the host. | |
745 | */ | |
746 | kern_return_t | |
3e170ce0 | 747 | host_processor_sets(host_priv_t host_priv, processor_set_name_array_t * pset_list, mach_msg_type_number_t * count) |
1c79356b | 748 | { |
3e170ce0 | 749 | void * addr; |
1c79356b A |
750 | |
751 | if (host_priv == HOST_PRIV_NULL) | |
2d21ac55 | 752 | return (KERN_INVALID_ARGUMENT); |
1c79356b A |
753 | |
754 | /* | |
755 | * Allocate memory. Can be pageable because it won't be | |
756 | * touched while holding a lock. | |
757 | */ | |
758 | ||
3e170ce0 | 759 | addr = kalloc((vm_size_t)sizeof(mach_port_t)); |
1c79356b | 760 | if (addr == 0) |
2d21ac55 | 761 | return (KERN_RESOURCE_SHORTAGE); |
1c79356b | 762 | |
1c79356b | 763 | /* do the conversion that Mig should handle */ |
3e170ce0 | 764 | *((ipc_port_t *)addr) = convert_pset_name_to_port(&pset0); |
1c79356b A |
765 | |
766 | *pset_list = (processor_set_array_t)addr; | |
767 | *count = 1; | |
768 | ||
2d21ac55 | 769 | return (KERN_SUCCESS); |
1c79356b A |
770 | } |
771 | ||
772 | /* | |
773 | * host_processor_set_priv: | |
774 | * | |
775 | * Return control port for given processor set. | |
776 | */ | |
777 | kern_return_t | |
3e170ce0 | 778 | host_processor_set_priv(host_priv_t host_priv, processor_set_t pset_name, processor_set_t * pset) |
1c79356b | 779 | { |
3e170ce0 | 780 | if (host_priv == HOST_PRIV_NULL || pset_name == PROCESSOR_SET_NULL) { |
2d21ac55 A |
781 | *pset = PROCESSOR_SET_NULL; |
782 | ||
783 | return (KERN_INVALID_ARGUMENT); | |
3e170ce0 | 784 | } |
1c79356b | 785 | |
3e170ce0 | 786 | *pset = pset_name; |
2d21ac55 | 787 | |
3e170ce0 | 788 | return (KERN_SUCCESS); |
1c79356b A |
789 | } |
790 | ||
791 | /* | |
792 | * host_processor_info | |
793 | * | |
794 | * Return info about the processors on this host. It will return | |
795 | * the number of processors, and the specific type of info requested | |
796 | * in an OOL array. | |
797 | */ | |
798 | kern_return_t | |
3e170ce0 A |
799 | host_processor_info(host_t host, |
800 | processor_flavor_t flavor, | |
801 | natural_t * out_pcount, | |
802 | processor_info_array_t * out_array, | |
803 | mach_msg_type_number_t * out_array_count) | |
1c79356b | 804 | { |
3e170ce0 A |
805 | kern_return_t result; |
806 | processor_t processor; | |
807 | host_t thost; | |
808 | processor_info_t info; | |
809 | unsigned int icount, tcount; | |
810 | unsigned int pcount, i; | |
811 | vm_offset_t addr; | |
812 | vm_size_t size, needed; | |
813 | vm_map_copy_t copy; | |
1c79356b A |
814 | |
815 | if (host == HOST_NULL) | |
91447636 | 816 | return (KERN_INVALID_ARGUMENT); |
1c79356b | 817 | |
91447636 A |
818 | result = processor_info_count(flavor, &icount); |
819 | if (result != KERN_SUCCESS) | |
820 | return (result); | |
1c79356b | 821 | |
91447636 A |
822 | pcount = processor_count; |
823 | assert(pcount != 0); | |
1c79356b | 824 | |
6601e61a | 825 | needed = pcount * icount * sizeof(natural_t); |
3e170ce0 A |
826 | size = vm_map_round_page(needed, VM_MAP_PAGE_MASK(ipc_kernel_map)); |
827 | result = kmem_alloc(ipc_kernel_map, &addr, size, VM_KERN_MEMORY_IPC); | |
91447636 A |
828 | if (result != KERN_SUCCESS) |
829 | return (KERN_RESOURCE_SHORTAGE); | |
830 | ||
3e170ce0 | 831 | info = (processor_info_t)addr; |
91447636 A |
832 | processor = processor_list; |
833 | tcount = icount; | |
1c79356b | 834 | |
91447636 A |
835 | result = processor_info(processor, flavor, &thost, info, &tcount); |
836 | if (result != KERN_SUCCESS) { | |
1c79356b | 837 | kmem_free(ipc_kernel_map, addr, size); |
91447636 | 838 | return (result); |
1c79356b A |
839 | } |
840 | ||
91447636 A |
841 | if (pcount > 1) { |
842 | for (i = 1; i < pcount; i++) { | |
843 | simple_lock(&processor_list_lock); | |
844 | processor = processor->processor_list; | |
845 | simple_unlock(&processor_list_lock); | |
846 | ||
847 | info += icount; | |
848 | tcount = icount; | |
849 | result = processor_info(processor, flavor, &thost, info, &tcount); | |
850 | if (result != KERN_SUCCESS) { | |
1c79356b | 851 | kmem_free(ipc_kernel_map, addr, size); |
91447636 | 852 | return (result); |
1c79356b | 853 | } |
1c79356b A |
854 | } |
855 | } | |
856 | ||
3e170ce0 A |
857 | if (size != needed) |
858 | bzero((char *)addr + needed, size - needed); | |
6601e61a | 859 | |
3e170ce0 A |
860 | result = vm_map_unwire(ipc_kernel_map, vm_map_trunc_page(addr, VM_MAP_PAGE_MASK(ipc_kernel_map)), |
861 | vm_map_round_page(addr + size, VM_MAP_PAGE_MASK(ipc_kernel_map)), FALSE); | |
91447636 | 862 | assert(result == KERN_SUCCESS); |
2dced7af | 863 | result = vm_map_copyin(ipc_kernel_map, (vm_map_address_t)addr, (vm_map_size_t)needed, TRUE, ©); |
91447636 | 864 | assert(result == KERN_SUCCESS); |
1c79356b | 865 | |
91447636 | 866 | *out_pcount = pcount; |
3e170ce0 | 867 | *out_array = (processor_info_array_t)copy; |
91447636 A |
868 | *out_array_count = pcount * icount; |
869 | ||
870 | return (KERN_SUCCESS); | |
1c79356b A |
871 | } |
872 | ||
1c79356b | 873 | /* |
55e303ae | 874 | * Kernel interface for setting a special port. |
1c79356b A |
875 | */ |
876 | kern_return_t | |
3e170ce0 | 877 | kernel_set_special_port(host_priv_t host_priv, int id, ipc_port_t port) |
1c79356b | 878 | { |
55e303ae A |
879 | ipc_port_t old_port; |
880 | ||
39037602 A |
881 | #if !MACH_FLIPC |
882 | if (id == HOST_NODE_PORT) | |
883 | return (KERN_NOT_SUPPORTED); | |
884 | #endif | |
885 | ||
55e303ae A |
886 | host_lock(host_priv); |
887 | old_port = host_priv->special[id]; | |
888 | host_priv->special[id] = port; | |
889 | host_unlock(host_priv); | |
39037602 A |
890 | |
891 | #if MACH_FLIPC | |
892 | if (id == HOST_NODE_PORT) | |
893 | mach_node_port_changed(); | |
894 | #endif | |
895 | ||
55e303ae A |
896 | if (IP_VALID(old_port)) |
897 | ipc_port_release_send(old_port); | |
3e170ce0 | 898 | return (KERN_SUCCESS); |
1c79356b A |
899 | } |
900 | ||
39037602 A |
901 | /* |
902 | * Kernel interface for retrieving a special port. | |
903 | */ | |
904 | kern_return_t | |
905 | kernel_get_special_port(host_priv_t host_priv, int id, ipc_port_t * portp) | |
906 | { | |
907 | host_lock(host_priv); | |
908 | *portp = host_priv->special[id]; | |
909 | host_unlock(host_priv); | |
910 | return (KERN_SUCCESS); | |
911 | } | |
912 | ||
1c79356b A |
913 | /* |
914 | * User interface for setting a special port. | |
915 | * | |
916 | * Only permits the user to set a user-owned special port | |
917 | * ID, rejecting a kernel-owned special port ID. | |
918 | * | |
919 | * A special kernel port cannot be set up using this | |
920 | * routine; use kernel_set_special_port() instead. | |
921 | */ | |
922 | kern_return_t | |
3e170ce0 | 923 | host_set_special_port(host_priv_t host_priv, int id, ipc_port_t port) |
1c79356b | 924 | { |
3e170ce0 A |
925 | if (host_priv == HOST_PRIV_NULL || id <= HOST_MAX_SPECIAL_KERNEL_PORT || id > HOST_MAX_SPECIAL_PORT) |
926 | return (KERN_INVALID_ARGUMENT); | |
55e303ae | 927 | |
3e170ce0 A |
928 | #if CONFIG_MACF |
929 | if (mac_task_check_set_host_special_port(current_task(), id, port) != 0) | |
930 | return (KERN_NO_ACCESS); | |
931 | #endif | |
1c79356b | 932 | |
3e170ce0 A |
933 | return (kernel_set_special_port(host_priv, id, port)); |
934 | } | |
1c79356b A |
935 | |
936 | /* | |
937 | * User interface for retrieving a special port. | |
938 | * | |
1c79356b A |
939 | * Note that there is nothing to prevent a user special |
940 | * port from disappearing after it has been discovered by | |
941 | * the caller; thus, using a special port can always result | |
942 | * in a "port not valid" error. | |
943 | */ | |
944 | ||
945 | kern_return_t | |
3e170ce0 | 946 | host_get_special_port(host_priv_t host_priv, __unused int node, int id, ipc_port_t * portp) |
1c79356b | 947 | { |
3e170ce0 | 948 | ipc_port_t port; |
55e303ae | 949 | |
3e170ce0 A |
950 | if (host_priv == HOST_PRIV_NULL || id == HOST_SECURITY_PORT || id > HOST_MAX_SPECIAL_PORT || id < 0) |
951 | return (KERN_INVALID_ARGUMENT); | |
55e303ae | 952 | |
55e303ae A |
953 | host_lock(host_priv); |
954 | port = realhost.special[id]; | |
955 | *portp = ipc_port_copy_send(port); | |
956 | host_unlock(host_priv); | |
957 | ||
3e170ce0 | 958 | return (KERN_SUCCESS); |
55e303ae A |
959 | } |
960 | ||
55e303ae | 961 | /* |
3e170ce0 | 962 | * host_get_io_master |
55e303ae A |
963 | * |
964 | * Return the IO master access port for this host. | |
965 | */ | |
966 | kern_return_t | |
3e170ce0 | 967 | host_get_io_master(host_t host, io_master_t * io_masterp) |
55e303ae A |
968 | { |
969 | if (host == HOST_NULL) | |
3e170ce0 | 970 | return (KERN_INVALID_ARGUMENT); |
55e303ae A |
971 | |
972 | return (host_get_io_master_port(host_priv_self(), io_masterp)); | |
1c79356b A |
973 | } |
974 | ||
975 | host_t | |
976 | host_self(void) | |
977 | { | |
3e170ce0 | 978 | return (&realhost); |
1c79356b A |
979 | } |
980 | ||
981 | host_priv_t | |
982 | host_priv_self(void) | |
983 | { | |
3e170ce0 | 984 | return (&realhost); |
1c79356b A |
985 | } |
986 | ||
987 | host_security_t | |
988 | host_security_self(void) | |
989 | { | |
3e170ce0 A |
990 | return (&realhost); |
991 | } | |
992 | ||
993 | kern_return_t | |
994 | host_set_atm_diagnostic_flag(host_priv_t host_priv, uint32_t diagnostic_flag) | |
995 | { | |
996 | if (host_priv == HOST_PRIV_NULL) | |
997 | return (KERN_INVALID_ARGUMENT); | |
998 | ||
999 | assert(host_priv == &realhost); | |
1000 | ||
1001 | #if CONFIG_ATM | |
1002 | return (atm_set_diagnostic_config(diagnostic_flag)); | |
1003 | #else | |
1004 | (void)diagnostic_flag; | |
1005 | return (KERN_NOT_SUPPORTED); | |
1006 | #endif | |
1c79356b | 1007 | } |
490019cf A |
1008 | |
1009 | kern_return_t | |
1010 | host_set_multiuser_config_flags(host_priv_t host_priv, uint32_t multiuser_config) | |
1011 | { | |
1012 | (void)host_priv; | |
1013 | (void)multiuser_config; | |
1014 | return (KERN_NOT_SUPPORTED); | |
1015 | } |