xref: /f-stack/tools/compat/include/sys/osd.h (revision 1eaf0ac3)
1*1eaf0ac3Slogwang /*-
2*1eaf0ac3Slogwang  * Copyright (c) 2007 Pawel Jakub Dawidek <[email protected]>
3*1eaf0ac3Slogwang  * All rights reserved.
4*1eaf0ac3Slogwang  *
5*1eaf0ac3Slogwang  * Redistribution and use in source and binary forms, with or without
6*1eaf0ac3Slogwang  * modification, are permitted provided that the following conditions
7*1eaf0ac3Slogwang  * are met:
8*1eaf0ac3Slogwang  * 1. Redistributions of source code must retain the above copyright
9*1eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer.
10*1eaf0ac3Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
11*1eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer in the
12*1eaf0ac3Slogwang  *    documentation and/or other materials provided with the distribution.
13*1eaf0ac3Slogwang  *
14*1eaf0ac3Slogwang  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15*1eaf0ac3Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*1eaf0ac3Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*1eaf0ac3Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18*1eaf0ac3Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*1eaf0ac3Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*1eaf0ac3Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*1eaf0ac3Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*1eaf0ac3Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*1eaf0ac3Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*1eaf0ac3Slogwang  * SUCH DAMAGE.
25*1eaf0ac3Slogwang  *
26*1eaf0ac3Slogwang  * $FreeBSD$
27*1eaf0ac3Slogwang  */
28*1eaf0ac3Slogwang 
29*1eaf0ac3Slogwang #ifndef _SYS_OSD_H_
30*1eaf0ac3Slogwang #define _SYS_OSD_H_
31*1eaf0ac3Slogwang 
32*1eaf0ac3Slogwang #include <sys/queue.h>
33*1eaf0ac3Slogwang 
34*1eaf0ac3Slogwang /*
35*1eaf0ac3Slogwang  * Lock key:
36*1eaf0ac3Slogwang  *   (c) container lock (e.g. jail's pr_mtx) and/or osd_object_lock
37*1eaf0ac3Slogwang  *   (l) osd_list_lock
38*1eaf0ac3Slogwang  */
39*1eaf0ac3Slogwang struct osd {
40*1eaf0ac3Slogwang 	u_int		  osd_nslots;	/* (c) */
41*1eaf0ac3Slogwang 	void		**osd_slots;	/* (c) */
42*1eaf0ac3Slogwang 	LIST_ENTRY(osd)	  osd_next;	/* (l) */
43*1eaf0ac3Slogwang };
44*1eaf0ac3Slogwang 
45*1eaf0ac3Slogwang #ifdef _KERNEL
46*1eaf0ac3Slogwang 
47*1eaf0ac3Slogwang #define	OSD_THREAD	0
48*1eaf0ac3Slogwang #define	OSD_JAIL	1
49*1eaf0ac3Slogwang #define	OSD_KHELP	2
50*1eaf0ac3Slogwang 
51*1eaf0ac3Slogwang #define	OSD_FIRST	OSD_THREAD
52*1eaf0ac3Slogwang #define	OSD_LAST	OSD_KHELP
53*1eaf0ac3Slogwang 
54*1eaf0ac3Slogwang typedef void (*osd_destructor_t)(void *value);
55*1eaf0ac3Slogwang typedef int (*osd_method_t)(void *obj, void *data);
56*1eaf0ac3Slogwang 
57*1eaf0ac3Slogwang int osd_register(u_int type, osd_destructor_t destructor,
58*1eaf0ac3Slogwang     osd_method_t *methods);
59*1eaf0ac3Slogwang void osd_deregister(u_int type, u_int slot);
60*1eaf0ac3Slogwang 
61*1eaf0ac3Slogwang int osd_set(u_int type, struct osd *osd, u_int slot, void *value);
62*1eaf0ac3Slogwang void **osd_reserve(u_int slot);
63*1eaf0ac3Slogwang int osd_set_reserved(u_int type, struct osd *osd, u_int slot, void **rsv,
64*1eaf0ac3Slogwang     void *value);
65*1eaf0ac3Slogwang void osd_free_reserved(void **rsv);
66*1eaf0ac3Slogwang void *osd_get(u_int type, struct osd *osd, u_int slot);
67*1eaf0ac3Slogwang void osd_del(u_int type, struct osd *osd, u_int slot);
68*1eaf0ac3Slogwang int osd_call(u_int type, u_int method, void *obj, void *data);
69*1eaf0ac3Slogwang 
70*1eaf0ac3Slogwang void osd_exit(u_int type, struct osd *osd);
71*1eaf0ac3Slogwang 
72*1eaf0ac3Slogwang #define	osd_thread_register(destructor)					\
73*1eaf0ac3Slogwang 	osd_register(OSD_THREAD, (destructor), NULL)
74*1eaf0ac3Slogwang #define	osd_thread_deregister(slot)					\
75*1eaf0ac3Slogwang 	osd_deregister(OSD_THREAD, (slot))
76*1eaf0ac3Slogwang #define	osd_thread_set(td, slot, value)					\
77*1eaf0ac3Slogwang 	osd_set(OSD_THREAD, &(td)->td_osd, (slot), (value))
78*1eaf0ac3Slogwang #define	osd_thread_set_reserved(td, slot, rsv, value)			\
79*1eaf0ac3Slogwang 	osd_set_reserved(OSD_THREAD, &(td)->td_osd, (slot), (rsv), (value))
80*1eaf0ac3Slogwang #define	osd_thread_get(td, slot)					\
81*1eaf0ac3Slogwang 	osd_get(OSD_THREAD, &(td)->td_osd, (slot))
82*1eaf0ac3Slogwang #define	osd_thread_del(td, slot)	do {				\
83*1eaf0ac3Slogwang 	KASSERT((td) == curthread, ("Not curthread."));			\
84*1eaf0ac3Slogwang 	osd_del(OSD_THREAD, &(td)->td_osd, (slot));			\
85*1eaf0ac3Slogwang } while (0)
86*1eaf0ac3Slogwang #define	osd_thread_call(td, method, data)				\
87*1eaf0ac3Slogwang 	osd_call(OSD_THREAD, (method), (td), (data))
88*1eaf0ac3Slogwang #define	osd_thread_exit(td)						\
89*1eaf0ac3Slogwang 	osd_exit(OSD_THREAD, &(td)->td_osd)
90*1eaf0ac3Slogwang 
91*1eaf0ac3Slogwang #define	osd_jail_register(destructor, methods)				\
92*1eaf0ac3Slogwang 	osd_register(OSD_JAIL, (destructor), (methods))
93*1eaf0ac3Slogwang #define	osd_jail_deregister(slot)					\
94*1eaf0ac3Slogwang 	osd_deregister(OSD_JAIL, (slot))
95*1eaf0ac3Slogwang #define	osd_jail_set(pr, slot, value)					\
96*1eaf0ac3Slogwang 	osd_set(OSD_JAIL, &(pr)->pr_osd, (slot), (value))
97*1eaf0ac3Slogwang #define	osd_jail_set_reserved(pr, slot, rsv, value)			\
98*1eaf0ac3Slogwang 	osd_set_reserved(OSD_JAIL, &(pr)->pr_osd, (slot), (rsv), (value))
99*1eaf0ac3Slogwang #define	osd_jail_get(pr, slot)						\
100*1eaf0ac3Slogwang 	osd_get(OSD_JAIL, &(pr)->pr_osd, (slot))
101*1eaf0ac3Slogwang #define	osd_jail_del(pr, slot)						\
102*1eaf0ac3Slogwang 	osd_del(OSD_JAIL, &(pr)->pr_osd, (slot))
103*1eaf0ac3Slogwang #define	osd_jail_call(pr, method, data)					\
104*1eaf0ac3Slogwang 	osd_call(OSD_JAIL, (method), (pr), (data))
105*1eaf0ac3Slogwang #define	osd_jail_exit(pr)						\
106*1eaf0ac3Slogwang 	osd_exit(OSD_JAIL, &(pr)->pr_osd)
107*1eaf0ac3Slogwang 
108*1eaf0ac3Slogwang #endif	/* _KERNEL */
109*1eaf0ac3Slogwang 
110*1eaf0ac3Slogwang #endif	/* !_SYS_OSD_H_ */
111