]>
Commit | Line | Data |
---|---|---|
6601e61a | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved. |
6601e61a | 3 | * |
2d21ac55 A |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
5 | * | |
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. | |
14 | * | |
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 | |
6601e61a 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. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
6601e61a A |
27 | */ |
28 | ||
29 | #include <stdint.h> | |
30 | #include <mach/boolean.h> | |
31 | #include <mach/mach_types.h> | |
32 | ||
33 | #include <sys/syscall.h> | |
34 | #include <sys/types.h> /* u_int */ | |
2d21ac55 | 35 | #include <sys/proc.h> /* proc_t */ |
6601e61a A |
36 | #include <sys/systm.h> /* struct sysent */ |
37 | #include <sys/sysproto.h> | |
38 | ||
39 | #pragma mark **** kern debug **** | |
40 | 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); | |
41 | static chudxnu_kdebug_callback_func_t kdebug_callback_fn = NULL; | |
42 | ||
0c530ab8 A |
43 | kern_return_t chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t); |
44 | kern_return_t chudxnu_kdebug_callback_cancel(void); | |
45 | ||
46 | extern void kdbg_control_chud(int val, void *fn); | |
6601e61a A |
47 | extern unsigned int kdebug_enable; |
48 | ||
0c530ab8 A |
49 | static void |
50 | chudxnu_private_kdebug_callback( | |
51 | unsigned int debugid, | |
52 | unsigned int arg0, | |
53 | unsigned int arg1, | |
54 | unsigned int arg2, | |
55 | unsigned int arg3, | |
56 | unsigned int arg4) | |
6601e61a | 57 | { |
0c530ab8 A |
58 | chudxnu_kdebug_callback_func_t fn = kdebug_callback_fn; |
59 | ||
60 | if(fn) { | |
61 | (fn)(debugid, arg0, arg1, arg2, arg3, arg4); | |
6601e61a A |
62 | } |
63 | } | |
64 | ||
0c530ab8 A |
65 | __private_extern__ kern_return_t |
66 | chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func) | |
6601e61a A |
67 | { |
68 | kdebug_callback_fn = func; | |
69 | ||
70 | kdbg_control_chud(TRUE, (void *)chudxnu_private_kdebug_callback); | |
71 | kdebug_enable |= 0x10; | |
72 | ||
73 | return KERN_SUCCESS; | |
74 | } | |
75 | ||
0c530ab8 A |
76 | __private_extern__ kern_return_t |
77 | chudxnu_kdebug_callback_cancel(void) | |
6601e61a A |
78 | { |
79 | kdebug_callback_fn = NULL; | |
80 | kdbg_control_chud(FALSE, NULL); | |
81 | kdebug_enable &= ~(0x10); | |
82 | ||
83 | return KERN_SUCCESS; | |
84 | } | |
0c530ab8 A |
85 | |
86 | #pragma mark **** CHUD syscall **** | |
87 | 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); | |
88 | static chudxnu_syscall_callback_func_t syscall_callback_fn = NULL; | |
89 | ||
90 | kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func); | |
91 | kern_return_t chudxnu_syscall_callback_cancel(void); | |
92 | ||
2d21ac55 A |
93 | int |
94 | chud(__unused proc_t p, struct chud_args *uap, register_t *retval) | |
0c530ab8 | 95 | { |
0c530ab8 A |
96 | chudxnu_syscall_callback_func_t fn = syscall_callback_fn; |
97 | ||
98 | if(!fn) { | |
99 | return EINVAL; | |
100 | } | |
101 | ||
102 | *retval = fn(uap->code, uap->arg1, uap->arg2, uap->arg3, uap->arg4, uap->arg5); | |
103 | ||
104 | return 0; | |
105 | } | |
106 | ||
2d21ac55 A |
107 | __private_extern__ kern_return_t |
108 | chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func) | |
0c530ab8 A |
109 | { |
110 | syscall_callback_fn = func; | |
111 | return KERN_SUCCESS; | |
112 | } | |
113 | ||
2d21ac55 A |
114 | __private_extern__ kern_return_t |
115 | chudxnu_syscall_callback_cancel(void) | |
0c530ab8 A |
116 | { |
117 | syscall_callback_fn = NULL; | |
118 | return KERN_SUCCESS; | |
119 | } |