]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/chud/chud_bsd_callback.c
bc2f004221f3e71f0ef178b213e091397d6b689c
[apple/xnu.git] / bsd / dev / chud / chud_bsd_callback.c
1 /*
2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <stdint.h>
24 #include <mach/boolean.h>
25 #include <mach/mach_types.h>
26
27 #include <sys/syscall.h>
28 #include <sys/types.h> /* u_int */
29 #include <sys/proc.h> /* struct proc */
30 #include <sys/systm.h> /* struct sysent */
31 #include <sys/sysproto.h>
32
33 #pragma mark **** kern debug ****
34 typedef void (*chudxnu_kdebug_callback_func_t)(uint32_t debugid, uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
35 static chudxnu_kdebug_callback_func_t kdebug_callback_fn = NULL;
36
37 kern_return_t chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t);
38 kern_return_t chudxnu_kdebug_callback_cancel(void);
39
40 extern void kdbg_control_chud(int val, void *fn);
41 extern unsigned int kdebug_enable;
42
43 static void
44 chudxnu_private_kdebug_callback(
45 unsigned int debugid,
46 unsigned int arg0,
47 unsigned int arg1,
48 unsigned int arg2,
49 unsigned int arg3,
50 unsigned int arg4)
51 {
52 chudxnu_kdebug_callback_func_t fn = kdebug_callback_fn;
53
54 if(fn) {
55 (fn)(debugid, arg0, arg1, arg2, arg3, arg4);
56 }
57 }
58
59 __private_extern__ kern_return_t
60 chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func)
61 {
62 kdebug_callback_fn = func;
63
64 kdbg_control_chud(TRUE, (void *)chudxnu_private_kdebug_callback);
65 kdebug_enable |= 0x10;
66
67 return KERN_SUCCESS;
68 }
69
70 __private_extern__ kern_return_t
71 chudxnu_kdebug_callback_cancel(void)
72 {
73 kdebug_callback_fn = NULL;
74 kdbg_control_chud(FALSE, NULL);
75 kdebug_enable &= ~(0x10);
76
77 return KERN_SUCCESS;
78 }
79
80 #pragma mark **** CHUD syscall ****
81 typedef kern_return_t (*chudxnu_syscall_callback_func_t)(uint32_t code, uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
82 static chudxnu_syscall_callback_func_t syscall_callback_fn = NULL;
83
84 kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func);
85 kern_return_t chudxnu_syscall_callback_cancel(void);
86
87 int chud(p, uap, retval)
88 struct proc *p;
89 struct chud_args *uap;
90 register_t *retval;
91 {
92 #pragma unused (p)
93
94 chudxnu_syscall_callback_func_t fn = syscall_callback_fn;
95
96 if(!fn) {
97 return EINVAL;
98 }
99
100 *retval = fn(uap->code, uap->arg1, uap->arg2, uap->arg3, uap->arg4, uap->arg5);
101
102 return 0;
103 }
104
105 __private_extern__
106 kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func)
107 {
108 syscall_callback_fn = func;
109 return KERN_SUCCESS;
110 }
111
112 __private_extern__
113 kern_return_t chudxnu_syscall_callback_cancel(void)
114 {
115 syscall_callback_fn = NULL;
116 return KERN_SUCCESS;
117 }