]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/chud/chud_bsd_callback.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / bsd / dev / chud / chud_bsd_callback.c
CommitLineData
8f6c56a5 1/*
89b3af67 2 * Copyright (c) 2003-2005 Apple Computer, Inc. All rights reserved.
8f6c56a5
A
3 *
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
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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 */
35#include <sys/proc.h> /* struct proc */
36#include <sys/systm.h> /* struct sysent */
37#include <sys/sysproto.h>
38
39#pragma mark **** kern debug ****
40typedef void (*chudxnu_kdebug_callback_func_t)(uint32_t debugid, uint32_t arg0, uint32_t arg1, uint32_t arg2, uint32_t arg3, uint32_t arg4);
41static chudxnu_kdebug_callback_func_t kdebug_callback_fn = NULL;
42
89b3af67
A
43kern_return_t chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t);
44kern_return_t chudxnu_kdebug_callback_cancel(void);
45
46extern void kdbg_control_chud(int val, void *fn);
8f6c56a5
A
47extern unsigned int kdebug_enable;
48
89b3af67
A
49static void
50chudxnu_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)
8f6c56a5 57{
89b3af67
A
58 chudxnu_kdebug_callback_func_t fn = kdebug_callback_fn;
59
60 if(fn) {
61 (fn)(debugid, arg0, arg1, arg2, arg3, arg4);
8f6c56a5
A
62 }
63}
64
89b3af67
A
65__private_extern__ kern_return_t
66chudxnu_kdebug_callback_enter(chudxnu_kdebug_callback_func_t func)
8f6c56a5
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
89b3af67
A
76__private_extern__ kern_return_t
77chudxnu_kdebug_callback_cancel(void)
8f6c56a5
A
78{
79 kdebug_callback_fn = NULL;
80 kdbg_control_chud(FALSE, NULL);
81 kdebug_enable &= ~(0x10);
82
83 return KERN_SUCCESS;
84}
89b3af67
A
85
86#pragma mark **** CHUD syscall ****
87typedef 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);
88static chudxnu_syscall_callback_func_t syscall_callback_fn = NULL;
89
90kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func);
91kern_return_t chudxnu_syscall_callback_cancel(void);
92
93int chud(p, uap, retval)
94 struct proc *p;
95 struct chud_args *uap;
96 register_t *retval;
97{
98#pragma unused (p)
99
100 chudxnu_syscall_callback_func_t fn = syscall_callback_fn;
101
102 if(!fn) {
103 return EINVAL;
104 }
105
106 *retval = fn(uap->code, uap->arg1, uap->arg2, uap->arg3, uap->arg4, uap->arg5);
107
108 return 0;
109}
110
111__private_extern__
112kern_return_t chudxnu_syscall_callback_enter(chudxnu_syscall_callback_func_t func)
113{
114 syscall_callback_fn = func;
115 return KERN_SUCCESS;
116}
117
118__private_extern__
119kern_return_t chudxnu_syscall_callback_cancel(void)
120{
121 syscall_callback_fn = NULL;
122 return KERN_SUCCESS;
123}