xref: /titanic_50/usr/src/uts/common/sys/hook.h (revision 0209230bf1261579beab4f55226bb509e6b850cb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * This file includes definitions of kernel hook framework components
28  */
29 
30 #ifndef _SYS_HOOK_H
31 #define	_SYS_HOOK_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <sys/queue.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Definition exposed to hook provider and consumer
43  */
44 
45 #define	HOOK_VERSION	1
46 
47 typedef uintptr_t hook_data_t;
48 
49 struct hook_event_int;
50 typedef struct hook_event_int *hook_event_token_t;
51 
52 typedef int (* hook_func_t)(hook_event_token_t, hook_data_t);
53 
54 /*
55  * Hook
56  */
57 typedef struct hook {
58 	int32_t		h_version;	/* version number */
59 	hook_func_t	h_func;		/* callback func */
60 	char		*h_name;	/* name of this hook */
61 	int		h_flags;	/* extra hook properties */
62 } hook_t;
63 
64 #define	HOOK_INIT(x, fn, r)			\
65 	do {					\
66 		(x)->h_version = HOOK_VERSION;	\
67 		(x)->h_func = (fn);		\
68 		(x)->h_name = (r);		\
69 		(x)->h_flags = 0;		\
70 		_NOTE(CONSTCOND)		\
71 	} while (0)
72 
73 /*
74  * Family
75  */
76 typedef struct hook_family {
77 	int32_t		hf_version;	/* version number */
78 	char		*hf_name;	/* family name */
79 } hook_family_t;
80 
81 #define	HOOK_FAMILY_INIT(x, y)			\
82 	do {					\
83 		(x)->hf_version = HOOK_VERSION;	\
84 		(x)->hf_name = (y);		\
85 		_NOTE(CONSTCOND)		\
86 	} while (0)
87 
88 /*
89  * Event
90  */
91 typedef struct hook_event {
92 	int32_t		he_version;	/* version number */
93 	char		*he_name;	/* name of this hook list */
94 	int		he_flags;	/* 1 = multiple entries allowed */
95 	boolean_t	he_interested;	/* true if callback exist */
96 } hook_event_t;
97 
98 #define	HOOK_RDONLY	0x1		/* Callbacks must not change data */
99 					/* Multiple callbacks are allowed */
100 
101 #define	HOOK_EVENT_INIT(x, y)			\
102 	do {					\
103 		(x)->he_version = HOOK_VERSION;	\
104 		(x)->he_name = (y);		\
105 		(x)->he_flags = 0;		\
106 		(x)->he_interested = B_FALSE;	\
107 		_NOTE(CONSTCOND)		\
108 	} while (0)
109 
110 
111 #ifdef	__cplusplus
112 }
113 #endif
114 
115 #endif /* _SYS_HOOK_H */
116