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