2 * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <mach/boolean.h>
31 #include <mach/mach_types.h>
33 #include <kern/kern_types.h>
34 #include <kern/processor.h>
35 #include <kern/timer_call.h>
36 #include <kern/thread_call.h>
37 #include <kern/kalloc.h>
38 #include <kern/thread.h>
40 #include <libkern/OSAtomic.h>
42 #include <machine/machine_routines.h>
43 #include <machine/cpu_data.h>
45 #include <chud/chud_xnu.h>
46 #include <chud/chud_xnu_private.h>
48 #pragma mark **** timer ****
50 __private_extern__ chud_timer_t
51 chudxnu_timer_alloc(chudxnu_timer_callback_func_t func
, uint32_t param0
)
53 return (chud_timer_t
)thread_call_allocate((thread_call_func_t
)func
, (thread_call_param_t
)param0
);
56 __private_extern__ kern_return_t
57 chudxnu_timer_callback_enter(
64 clock_interval_to_deadline(time
, units
, &t_delay
);
65 thread_call_enter1_delayed((thread_call_t
)timer
, (thread_call_param_t
)param1
, t_delay
);
69 __private_extern__ kern_return_t
70 chudxnu_timer_callback_cancel(chud_timer_t timer
)
72 thread_call_cancel((thread_call_t
)timer
);
76 __private_extern__ kern_return_t
77 chudxnu_timer_free(chud_timer_t timer
)
79 thread_call_cancel((thread_call_t
)timer
);
80 thread_call_free((thread_call_t
)timer
);
84 static chudxnu_dtrace_callback_t
85 dtrace_callback
= (chudxnu_dtrace_callback_t
) NULL
;
88 chudxnu_dtrace_callback(uint64_t selector
, uint64_t *args
, uint32_t count
)
90 /* it's not an error if no callback is hooked up */
91 kern_return_t ret
= KERN_SUCCESS
;
93 /* Make a local stack copy of the function ptr */
94 chudxnu_dtrace_callback_t fn
= dtrace_callback
;
97 ret
= fn(selector
, args
, count
);
103 __private_extern__
void
104 chudxnu_dtrace_callback_enter(chudxnu_dtrace_callback_t fn
)
106 chudxnu_dtrace_callback_t old_fn
= dtrace_callback
;
108 /* Atomically clear the call back */
109 while(!OSCompareAndSwap((UInt32
)old_fn
, (UInt32
)fn
,
110 (volatile UInt32
*) &dtrace_callback
)) {
111 old_fn
= dtrace_callback
;
115 __private_extern__
void
116 chudxnu_dtrace_callback_cancel(void)
118 chudxnu_dtrace_callback_enter(NULL
);