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