]>
Commit | Line | Data |
---|---|---|
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 |
40 | extern 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 | 48 | extern task_t chudxnu_task_for_pid(int pid); |
b0d623f7 | 49 | extern int chudxnu_pid_for_task(task_t task); |
0c530ab8 | 50 | extern int chudxnu_current_pid(void); |
b0d623f7 | 51 | extern task_t chudxnu_current_task(void); |
0c530ab8 A |
52 | |
53 | extern kern_return_t chudxnu_task_read(task_t task, void *kernaddr, uint64_t usraddr, vm_size_t size); | |
54 | extern kern_return_t chudxnu_task_write(task_t task, uint64_t useraddr, void *kernaddr, vm_size_t size); | |
55 | extern kern_return_t chudxnu_kern_read(void *destaddr, vm_offset_t srcaddr, vm_size_t size); | |
56 | extern kern_return_t chudxnu_kern_write(vm_offset_t destaddr, void *srcaddr, vm_size_t size); | |
57 | ||
58 | extern 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 |
66 | extern thread_t chudxnu_current_thread(void); |
67 | extern task_t chudxnu_task_for_thread(thread_t thread); | |
68 | ||
2d21ac55 A |
69 | extern kern_return_t chudxnu_bind_thread(thread_t thread, int cpu, int options); |
70 | extern kern_return_t chudxnu_unbind_thread(thread_t thread, int options); | |
0c530ab8 A |
71 | |
72 | extern 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); | |
73 | extern 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); | |
74 | extern kern_return_t chudxnu_thread_user_state_available(thread_t thread); | |
75 | ||
0c530ab8 A |
76 | extern kern_return_t chudxnu_thread_get_callstack64(thread_t thread, uint64_t *callStack, mach_msg_type_number_t *count, boolean_t user_only); |
77 | ||
0c530ab8 A |
78 | extern kern_return_t chudxnu_all_tasks(task_array_t *task_list, mach_msg_type_number_t *count); |
79 | extern kern_return_t chudxnu_free_task_list(task_array_t *task_list, mach_msg_type_number_t *count); | |
80 | ||
81 | extern kern_return_t chudxnu_all_threads(thread_array_t *thread_list, mach_msg_type_number_t *count); | |
82 | extern kern_return_t chudxnu_task_threads(task_t task, thread_array_t *thread_list, mach_msg_type_number_t *count); | |
83 | extern kern_return_t chudxnu_free_thread_list(thread_array_t *thread_list, mach_msg_type_number_t *count); | |
84 | ||
85 | extern 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); | |
86 | ||
87 | extern kern_return_t chudxnu_thread_last_context_switch(thread_t thread, uint64_t *timestamp); | |
88 | ||
2d21ac55 A |
89 | extern boolean_t chudxnu_thread_set_marked(thread_t thread, boolean_t marked); |
90 | extern boolean_t chudxnu_thread_get_marked(thread_t thread); | |
91 | extern boolean_t chudxnu_thread_get_idle(thread_t thread); | |
92 | ||
b0d623f7 | 93 | #if 0 |
0c530ab8 | 94 | #pragma mark **** memory **** |
b0d623f7 | 95 | #endif |
0c530ab8 A |
96 | // ******************************************************************************** |
97 | // memory | |
98 | // ******************************************************************************** | |
99 | ||
100 | extern uint64_t chudxnu_avail_memory_size(void); | |
101 | extern uint64_t chudxnu_phys_memory_size(void); | |
102 | extern uint64_t chudxnu_free_memory_size(void); | |
2d21ac55 | 103 | extern uint64_t chudxnu_inactive_memory_size(void); |
0c530ab8 | 104 | |
b0d623f7 | 105 | #if 0 |
0c530ab8 | 106 | #pragma mark **** cpu **** |
b0d623f7 | 107 | #endif |
0c530ab8 A |
108 | // ******************************************************************************** |
109 | // cpu | |
110 | // ******************************************************************************** | |
2d21ac55 | 111 | extern int chudxnu_logical_cpu_count(void); |
0c530ab8 A |
112 | extern int chudxnu_phys_cpu_count(void); |
113 | extern int chudxnu_cpu_number(void); | |
114 | ||
115 | extern kern_return_t chudxnu_enable_cpu(int cpu, boolean_t enable); | |
116 | ||
0c530ab8 A |
117 | extern boolean_t chudxnu_get_interrupts_enabled(void); |
118 | extern boolean_t chudxnu_set_interrupts_enabled(boolean_t enable); | |
119 | extern boolean_t chudxnu_at_interrupt_context(void); | |
120 | extern void chudxnu_cause_interrupt(void); | |
121 | ||
122 | extern void chudxnu_enable_preemption(void); | |
123 | extern void chudxnu_disable_preemption(void); | |
124 | extern int chudxnu_get_preemption_level(void); | |
125 | ||
0c530ab8 A |
126 | extern kern_return_t chudxnu_perfmon_acquire_facility(task_t); |
127 | extern kern_return_t chudxnu_perfmon_release_facility(task_t); | |
128 | ||
0c530ab8 A |
129 | typedef struct { |
130 | uint32_t hwResets; | |
131 | uint32_t hwMachineChecks; | |
132 | uint32_t hwDSIs; | |
133 | uint32_t hwISIs; | |
134 | uint32_t hwExternals; | |
135 | uint32_t hwAlignments; | |
136 | uint32_t hwPrograms; | |
137 | uint32_t hwFloatPointUnavailable; | |
138 | uint32_t hwDecrementers; | |
139 | uint32_t hwIOErrors; | |
140 | uint32_t hwSystemCalls; | |
141 | uint32_t hwTraces; | |
142 | uint32_t hwFloatingPointAssists; | |
143 | uint32_t hwPerformanceMonitors; | |
144 | uint32_t hwAltivecs; | |
145 | uint32_t hwInstBreakpoints; | |
146 | uint32_t hwSystemManagements; | |
147 | uint32_t hwAltivecAssists; | |
148 | uint32_t hwThermal; | |
149 | uint32_t hwSoftPatches; | |
150 | uint32_t hwMaintenances; | |
151 | uint32_t hwInstrumentations; | |
b0d623f7 | 152 | } interrupt_counters_t; |
0c530ab8 | 153 | |
b0d623f7 | 154 | extern kern_return_t chudxnu_get_cpu_interrupt_counters(int cpu, interrupt_counters_t *rupts); |
2d21ac55 | 155 | extern kern_return_t chudxnu_clear_cpu_interrupt_counters(int cpu); |
0c530ab8 | 156 | |
b0d623f7 | 157 | #if 0 |
0c530ab8 | 158 | #pragma mark **** callbacks **** |
b0d623f7 | 159 | #endif |
0c530ab8 A |
160 | // ******************************************************************************** |
161 | // callbacks | |
162 | // ******************************************************************************** | |
163 | ||
164 | extern void chudxnu_cancel_all_callbacks(void); | |
165 | ||
166 | // cpu timer - each cpu has its own callback | |
167 | typedef kern_return_t (*chudxnu_cpu_timer_callback_func_t)(thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count); | |
168 | extern 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 | |
169 | extern kern_return_t chudxnu_cpu_timer_callback_cancel(void); // callback is cleared on current cpu | |
170 | extern kern_return_t chudxnu_cpu_timer_callback_cancel_all(void); // callback is cleared on all cpus | |
171 | ||
172 | enum { | |
173 | PPC_TRAP_PROGRAM = 0x700, | |
174 | PPC_TRAP_TRACE = 0xD00, | |
175 | PPC_TRAP_PERFMON = 0xF00, | |
176 | }; | |
177 | ||
178 | enum { | |
179 | X86_TRAP_DEBUG = 0x1, | |
180 | }; | |
181 | ||
182 | // trap callback - one callback for system | |
183 | typedef 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); | |
184 | extern kern_return_t chudxnu_trap_callback_enter(chudxnu_trap_callback_func_t func); | |
185 | extern kern_return_t chudxnu_trap_callback_cancel(void); | |
186 | ||
187 | enum { | |
188 | PPC_INTERRUPT_DECREMENTER = 0x900, | |
189 | PPC_INTERRUPT_INTERRUPT = 0x500, | |
190 | PPC_INTERRUPT_CPU_SIGNAL = 0x2200, | |
191 | }; | |
192 | ||
193 | enum { | |
194 | X86_INTERRUPT_PERFMON = 0xB, | |
195 | }; | |
196 | ||
197 | // interrupt callback - one callback for system | |
198 | typedef 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); | |
199 | extern kern_return_t chudxnu_interrupt_callback_enter(chudxnu_interrupt_callback_func_t func); | |
200 | extern kern_return_t chudxnu_interrupt_callback_cancel(void); | |
201 | ||
202 | // ast callback - one callback for system | |
203 | typedef kern_return_t (*chudxnu_perfmon_ast_callback_func_t)(thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count); | |
204 | extern kern_return_t chudxnu_perfmon_ast_callback_enter(chudxnu_perfmon_ast_callback_func_t func); | |
205 | extern kern_return_t chudxnu_perfmon_ast_callback_cancel(void); | |
0c530ab8 A |
206 | extern kern_return_t chudxnu_perfmon_ast_send_urgent(boolean_t urgent); |
207 | ||
208 | // cpusig callback - one callback for system | |
209 | typedef kern_return_t (*chudxnu_cpusig_callback_func_t)(int request, thread_flavor_t flavor, thread_state_t tstate, mach_msg_type_number_t count); | |
210 | extern kern_return_t chudxnu_cpusig_callback_enter(chudxnu_cpusig_callback_func_t func); | |
211 | extern kern_return_t chudxnu_cpusig_callback_cancel(void); | |
212 | extern kern_return_t chudxnu_cpusig_send(int otherCPU, uint32_t request); | |
213 | ||
214 | // kdebug callback - one callback for system | |
b0d623f7 | 215 | typedef 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 |
216 | extern kern_return_t chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func); |
217 | extern kern_return_t chudxnu_kdebug_callback_cancel(void); | |
218 | ||
219 | // timer callback - multiple callbacks | |
b0d623f7 | 220 | typedef kern_return_t (*chudxnu_timer_callback_func_t)(thread_call_param_t param0, thread_call_param_t param1); |
0c530ab8 | 221 | typedef void * chud_timer_t; |
b0d623f7 A |
222 | extern chud_timer_t chudxnu_timer_alloc(chudxnu_timer_callback_func_t func, thread_call_param_t param0); |
223 | extern kern_return_t chudxnu_timer_callback_enter(chud_timer_t timer, thread_call_param_t param1, uint32_t time, uint32_t units); | |
0c530ab8 A |
224 | extern kern_return_t chudxnu_timer_callback_cancel(chud_timer_t timer); |
225 | extern kern_return_t chudxnu_timer_free(chud_timer_t timer); | |
226 | ||
227 | // CHUD systemcall callback - one callback for system | |
b0d623f7 | 228 | typedef 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 |
229 | extern kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func); |
230 | extern kern_return_t chudxnu_syscall_callback_cancel(void); | |
231 | ||
2d21ac55 A |
232 | // DTrace Triggering |
233 | typedef kern_return_t (*chudxnu_dtrace_callback_t)(uint64_t selector, uint64_t *args, uint32_t count); | |
b0d623f7 A |
234 | extern int chudxnu_dtrace_callback(uint64_t selector, uint64_t *args, uint32_t count); |
235 | extern kern_return_t chudxnu_dtrace_callback_enter(chudxnu_dtrace_callback_t fn); | |
2d21ac55 A |
236 | extern void chudxnu_dtrace_callback_cancel(void); |
237 | ||
0c530ab8 A |
238 | // ******************************************************************************** |
239 | // DEPRECATED | |
240 | // ******************************************************************************** | |
2d21ac55 | 241 | extern kern_return_t chudxnu_thread_get_callstack(thread_t thread, uint32_t *callStack, mach_msg_type_number_t *count, boolean_t user_only); |
0c530ab8 | 242 | |
b0d623f7 A |
243 | extern kern_return_t chudxnu_set_shadowed_spr(int cpu, int spr, uint32_t val); |
244 | extern kern_return_t chudxnu_set_shadowed_spr64(int cpu, int spr, uint64_t val); | |
0c530ab8 | 245 | |
2d21ac55 A |
246 | extern kern_return_t chudxnu_enable_cpu_nap(int cpu, boolean_t enable); |
247 | extern boolean_t chudxnu_cpu_nap_enabled(int cpu); | |
248 | ||
249 | extern uint32_t chudxnu_get_orig_cpu_l2cr(int cpu); | |
250 | extern uint32_t chudxnu_get_orig_cpu_l3cr(int cpu); | |
251 | ||
252 | extern kern_return_t chudxnu_read_spr(int cpu, int spr, uint32_t *val_p); | |
253 | extern kern_return_t chudxnu_read_spr64(int cpu, int spr, uint64_t *val_p); | |
254 | extern kern_return_t chudxnu_write_spr(int cpu, int spr, uint32_t val); | |
255 | extern kern_return_t chudxnu_write_spr64(int cpu, int spr, uint64_t val); | |
256 | ||
2d21ac55 A |
257 | extern void chudxnu_flush_caches(void); |
258 | extern void chudxnu_enable_caches(boolean_t enable); | |
0c530ab8 A |
259 | |
260 | #endif /* _CHUD_XNU_H_ */ |