]> git.saurik.com Git - apple/xnu.git/blame - osfmk/chud/chud_xnu.h
xnu-2050.48.11.tar.gz
[apple/xnu.git] / osfmk / chud / chud_xnu.h
CommitLineData
0c530ab8 1/*
b0d623f7 2 * Copyright (c) 2003-2008 Apple Inc. All rights reserved.
0c530ab8 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0c530ab8 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.
0c530ab8 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
0c530ab8
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.
0c530ab8 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
0c530ab8
A
27 */
28
29#ifndef _CHUD_XNU_H_
30#define _CHUD_XNU_H_
31
0c530ab8
A
32#include <stdint.h>
33#include <mach/boolean.h>
34#include <mach/mach_types.h>
b0d623f7 35#include <kern/thread_call.h>
0c530ab8 36
b0d623f7 37#if 0
0c530ab8 38#pragma mark **** version ****
b0d623f7 39#endif
0c530ab8
A
40extern uint32_t chudxnu_version(void);
41
b0d623f7 42#if 0
0c530ab8 43#pragma mark **** task ****
b0d623f7 44#endif
0c530ab8
A
45// ********************************************************************************
46// task
47// ********************************************************************************
0c530ab8 48extern task_t chudxnu_task_for_pid(int pid);
b0d623f7 49extern int chudxnu_pid_for_task(task_t task);
0c530ab8 50extern int chudxnu_current_pid(void);
b0d623f7 51extern task_t chudxnu_current_task(void);
0c530ab8
A
52
53extern kern_return_t chudxnu_task_read(task_t task, void *kernaddr, uint64_t usraddr, vm_size_t size);
54extern kern_return_t chudxnu_task_write(task_t task, uint64_t useraddr, void *kernaddr, vm_size_t size);
55extern kern_return_t chudxnu_kern_read(void *destaddr, vm_offset_t srcaddr, vm_size_t size);
56extern kern_return_t chudxnu_kern_write(vm_offset_t destaddr, void *srcaddr, vm_size_t size);
57
58extern boolean_t chudxnu_is_64bit_task(task_t task);
59
b0d623f7 60#if 0
0c530ab8 61#pragma mark **** thread ****
b0d623f7 62#endif
0c530ab8
A
63// ********************************************************************************
64// thread
65// ********************************************************************************
b0d623f7
A
66extern thread_t chudxnu_current_thread(void);
67extern task_t chudxnu_task_for_thread(thread_t thread);
68
2d21ac55
A
69extern kern_return_t chudxnu_bind_thread(thread_t thread, int cpu, int options);
70extern kern_return_t chudxnu_unbind_thread(thread_t thread, int options);
0c530ab8
A
71
72extern kern_return_t chudxnu_thread_get_state(thread_t thread, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t *count, boolean_t user_only);
73extern kern_return_t chudxnu_thread_set_state(thread_t thread, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count, boolean_t user_only);
0c530ab8 74
0c530ab8
A
75extern kern_return_t chudxnu_thread_get_callstack64(thread_t thread, uint64_t *callStack, mach_msg_type_number_t *count, boolean_t user_only);
76
0c530ab8
A
77extern kern_return_t chudxnu_all_tasks(task_array_t *task_list, mach_msg_type_number_t *count);
78extern kern_return_t chudxnu_free_task_list(task_array_t *task_list, mach_msg_type_number_t *count);
79
80extern kern_return_t chudxnu_all_threads(thread_array_t *thread_list, mach_msg_type_number_t *count);
81extern kern_return_t chudxnu_task_threads(task_t task, thread_array_t *thread_list, mach_msg_type_number_t *count);
82extern kern_return_t chudxnu_free_thread_list(thread_array_t *thread_list, mach_msg_type_number_t *count);
83
84extern kern_return_t chudxnu_thread_info( thread_t thread, thread_flavor_t flavor, thread_info_t thread_info_out, mach_msg_type_number_t *thread_info_count);
85
2d21ac55
A
86extern boolean_t chudxnu_thread_set_marked(thread_t thread, boolean_t marked);
87extern boolean_t chudxnu_thread_get_marked(thread_t thread);
88extern boolean_t chudxnu_thread_get_idle(thread_t thread);
89
6d2010ae
A
90enum {
91 CHUDXNU_TS_RUNNING = 0x1,
92 CHUDXNU_TS_RUNNABLE = 0x2,
93 CHUDXNU_TS_WAIT = 0x4,
94 CHUDXNU_TS_UNINT = 0x8,
95 CHUDXNU_TS_SUSP = 0x10,
96 CHUDXNU_TS_TERMINATE = 0x20,
97 CHUDXNU_TS_IDLE = 0x40
98};
99
100extern int chudxnu_thread_get_scheduler_state(thread_t thread);
101
316670eb
A
102extern boolean_t chudxnu_thread_get_dirty(thread_t thread);
103extern void chudxnu_thread_set_dirty(thread_t thread, boolean_t);
104
b0d623f7 105#if 0
0c530ab8 106#pragma mark **** memory ****
b0d623f7 107#endif
0c530ab8
A
108// ********************************************************************************
109// memory
110// ********************************************************************************
111
112extern uint64_t chudxnu_avail_memory_size(void);
113extern uint64_t chudxnu_phys_memory_size(void);
114extern uint64_t chudxnu_free_memory_size(void);
2d21ac55 115extern uint64_t chudxnu_inactive_memory_size(void);
0c530ab8 116
b0d623f7 117#if 0
0c530ab8 118#pragma mark **** cpu ****
b0d623f7 119#endif
0c530ab8
A
120// ********************************************************************************
121// cpu
122// ********************************************************************************
2d21ac55 123extern int chudxnu_logical_cpu_count(void);
0c530ab8
A
124extern int chudxnu_phys_cpu_count(void);
125extern int chudxnu_cpu_number(void);
126
127extern kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable);
128
0c530ab8 129extern boolean_t chudxnu_set_interrupts_enabled(boolean_t enable);
0c530ab8
A
130extern void chudxnu_cause_interrupt(void);
131
132extern void chudxnu_enable_preemption(void);
133extern void chudxnu_disable_preemption(void);
134extern int chudxnu_get_preemption_level(void);
135
0c530ab8
A
136extern kern_return_t chudxnu_perfmon_acquire_facility(task_t);
137extern kern_return_t chudxnu_perfmon_release_facility(task_t);
138
0c530ab8
A
139typedef struct {
140 uint32_t hwResets;
141 uint32_t hwMachineChecks;
142 uint32_t hwDSIs;
143 uint32_t hwISIs;
144 uint32_t hwExternals;
145 uint32_t hwAlignments;
146 uint32_t hwPrograms;
147 uint32_t hwFloatPointUnavailable;
148 uint32_t hwDecrementers;
149 uint32_t hwIOErrors;
150 uint32_t hwSystemCalls;
151 uint32_t hwTraces;
152 uint32_t hwFloatingPointAssists;
153 uint32_t hwPerformanceMonitors;
154 uint32_t hwAltivecs;
155 uint32_t hwInstBreakpoints;
156 uint32_t hwSystemManagements;
157 uint32_t hwAltivecAssists;
158 uint32_t hwThermal;
159 uint32_t hwSoftPatches;
160 uint32_t hwMaintenances;
161 uint32_t hwInstrumentations;
b0d623f7 162} interrupt_counters_t;
0c530ab8 163
b0d623f7 164extern kern_return_t chudxnu_get_cpu_interrupt_counters(int cpu, interrupt_counters_t *rupts);
2d21ac55 165extern kern_return_t chudxnu_clear_cpu_interrupt_counters(int cpu);
0c530ab8 166
b0d623f7 167#if 0
0c530ab8 168#pragma mark **** callbacks ****
b0d623f7 169#endif
0c530ab8
A
170// ********************************************************************************
171// callbacks
172// ********************************************************************************
173
174extern void chudxnu_cancel_all_callbacks(void);
175
176// cpu timer - each cpu has its own callback
177typedef kern_return_t (*chudxnu_cpu_timer_callback_func_t)(thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
178extern kern_return_t chudxnu_cpu_timer_callback_enter(chudxnu_cpu_timer_callback_func_t func, uint32_t time, uint32_t units); // callback is entered on current cpu
179extern kern_return_t chudxnu_cpu_timer_callback_cancel(void); // callback is cleared on current cpu
180extern kern_return_t chudxnu_cpu_timer_callback_cancel_all(void); // callback is cleared on all cpus
181
182enum {
183 PPC_TRAP_PROGRAM = 0x700,
184 PPC_TRAP_TRACE = 0xD00,
185 PPC_TRAP_PERFMON = 0xF00,
186};
187
188enum {
189 X86_TRAP_DEBUG = 0x1,
190};
191
192// trap callback - one callback for system
193typedef kern_return_t (*chudxnu_trap_callback_func_t)(uint32_t trapentry, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
194extern kern_return_t chudxnu_trap_callback_enter(chudxnu_trap_callback_func_t func);
195extern kern_return_t chudxnu_trap_callback_cancel(void);
196
197enum {
198 PPC_INTERRUPT_DECREMENTER = 0x900,
199 PPC_INTERRUPT_INTERRUPT = 0x500,
200 PPC_INTERRUPT_CPU_SIGNAL = 0x2200,
201};
202
203enum {
204 X86_INTERRUPT_PERFMON = 0xB,
205};
206
207// interrupt callback - one callback for system
208typedef kern_return_t (*chudxnu_interrupt_callback_func_t)(uint32_t trapentry, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
209extern kern_return_t chudxnu_interrupt_callback_enter(chudxnu_interrupt_callback_func_t func);
210extern kern_return_t chudxnu_interrupt_callback_cancel(void);
211
212// ast callback - one callback for system
213typedef kern_return_t (*chudxnu_perfmon_ast_callback_func_t)(thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
214extern kern_return_t chudxnu_perfmon_ast_callback_enter(chudxnu_perfmon_ast_callback_func_t func);
215extern kern_return_t chudxnu_perfmon_ast_callback_cancel(void);
0c530ab8
A
216extern kern_return_t chudxnu_perfmon_ast_send_urgent(boolean_t urgent);
217
218// cpusig callback - one callback for system
219typedef kern_return_t (*chudxnu_cpusig_callback_func_t)(int request, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count);
220extern kern_return_t chudxnu_cpusig_callback_enter(chudxnu_cpusig_callback_func_t func);
221extern kern_return_t chudxnu_cpusig_callback_cancel(void);
222extern kern_return_t chudxnu_cpusig_send(int otherCPU, uint32_t request);
223
224// kdebug callback - one callback for system
b0d623f7 225typedef kern_return_t (*chudxnu_kdebug_callback_func_t)(uint32_t debugid, uintptr_t arg0, uintptr_t arg1, uintptr_t arg2, uintptr_t arg3, uintptr_t arg4);
0c530ab8
A
226extern kern_return_t chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func);
227extern kern_return_t chudxnu_kdebug_callback_cancel(void);
228
229// timer callback - multiple callbacks
b0d623f7 230typedef kern_return_t (*chudxnu_timer_callback_func_t)(thread_call_param_t param0, thread_call_param_t param1);
0c530ab8 231typedef void * chud_timer_t;
b0d623f7
A
232extern chud_timer_t chudxnu_timer_alloc(chudxnu_timer_callback_func_t func, thread_call_param_t param0);
233extern kern_return_t chudxnu_timer_callback_enter(chud_timer_t timer, thread_call_param_t param1, uint32_t time, uint32_t units);
0c530ab8
A
234extern kern_return_t chudxnu_timer_callback_cancel(chud_timer_t timer);
235extern kern_return_t chudxnu_timer_free(chud_timer_t timer);
236
237// CHUD systemcall callback - one callback for system
b0d623f7 238typedef kern_return_t (*chudxnu_syscall_callback_func_t)(uint64_t code, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5);
0c530ab8
A
239extern kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func);
240extern kern_return_t chudxnu_syscall_callback_cancel(void);
241
2d21ac55
A
242// DTrace Triggering
243typedef kern_return_t (*chudxnu_dtrace_callback_t)(uint64_t selector, uint64_t *args, uint32_t count);
b0d623f7
A
244extern int chudxnu_dtrace_callback(uint64_t selector, uint64_t *args, uint32_t count);
245extern kern_return_t chudxnu_dtrace_callback_enter(chudxnu_dtrace_callback_t fn);
2d21ac55
A
246extern void chudxnu_dtrace_callback_cancel(void);
247
0c530ab8
A
248// ********************************************************************************
249// DEPRECATED
250// ********************************************************************************
2d21ac55 251extern kern_return_t chudxnu_thread_get_callstack(thread_t thread, uint32_t *callStack, mach_msg_type_number_t *count, boolean_t user_only);
0c530ab8 252
b0d623f7
A
253extern kern_return_t chudxnu_set_shadowed_spr(int cpu, int spr, uint32_t val);
254extern kern_return_t chudxnu_set_shadowed_spr64(int cpu, int spr, uint64_t val);
0c530ab8 255
2d21ac55
A
256extern kern_return_t chudxnu_enable_cpu_nap(int cpu, boolean_t enable);
257extern boolean_t chudxnu_cpu_nap_enabled(int cpu);
258
2d21ac55
A
259extern kern_return_t chudxnu_read_spr(int cpu, int spr, uint32_t *val_p);
260extern kern_return_t chudxnu_read_spr64(int cpu, int spr, uint64_t *val_p);
261extern kern_return_t chudxnu_write_spr(int cpu, int spr, uint32_t val);
262extern kern_return_t chudxnu_write_spr64(int cpu, int spr, uint64_t val);
263
0c530ab8 264#endif /* _CHUD_XNU_H_ */