xref: /titanic_51/usr/src/uts/i86pc/sys/dr_util.h (revision a31148363f598def767ac48c5d82e1572e44b935)
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 #ifndef _SYS_DR_UTIL_H_
27 #define	_SYS_DR_UTIL_H_
28 #include <sys/types.h>
29 #include <sys/kmem.h>
30 #include <sys/memlist.h>
31 #include <sys/varargs.h>
32 #include <sys/sbd_ioctl.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #define	GETSTRUCT(t, n) \
39 		((t *)kmem_zalloc((size_t)(n) * sizeof (t), KM_SLEEP))
40 #define	FREESTRUCT(p, t, n) \
41 		(kmem_free((caddr_t)(p), sizeof (t) * (size_t)(n)))
42 
43 #define	DRERR_SET_C(epps, eppn)		\
44 	if (*(epps) == NULL)		\
45 		*(epps) = *(eppn);	\
46 	else				\
47 		sbd_err_clear(eppn)
48 
49 #ifdef DEBUG
50 #define	MEMLIST_DUMP(ml) memlist_dump(ml)
51 #else
52 #define	MEMLIST_DUMP(ml)
53 #endif
54 
55 extern sbd_error_t	*sbd_err_new(int e_code, char *fmt, va_list args);
56 extern void		sbd_err_log(sbd_error_t *ep, int ce);
57 extern void		sbd_err_clear(sbd_error_t **ep);
58 extern void		sbd_err_set_c(sbd_error_t **ep, int ce,
59 				int e_code, char *fmt, ...);
60 extern void		sbd_err_set(sbd_error_t **ep, int ce,
61 				int e_code, char *fmt, ...);
62 
63 extern sbd_error_t	*drerr_new(int log, int e_code, char *fmt, ...);
64 extern sbd_error_t	*drerr_new_v(int e_code, char *fmt, va_list args);
65 extern void		drerr_set_c(int log, sbd_error_t **ep,
66 				int e_code, char *fmt, ...);
67 
68 extern void		dr_memlist_delete(struct memlist *mlist);
69 extern void		memlist_dump(struct memlist *mlist);
70 extern int		dr_memlist_intersect(struct memlist *al,
71 				struct memlist *bl);
72 extern void		dr_memlist_coalesce(struct memlist *mlist);
73 extern struct memlist	*dr_memlist_dup(struct memlist *mlist);
74 extern struct memlist	*dr_memlist_add_span(struct memlist *mlist,
75 				uint64_t base, uint64_t len);
76 extern struct memlist	*dr_memlist_del_span(struct memlist *mlist,
77 				uint64_t base, uint64_t len);
78 extern struct memlist	*dr_memlist_cat_span(struct memlist *mlist,
79 				uint64_t base, uint64_t len);
80 
81 /*
82  * These are all utilities internal for DR.  There are
83  * similar functions in common/os which have similar names.
84  * We rename them to make sure there is no name space
85  * conflict.
86  */
87 #define	memlist_delete		dr_memlist_delete
88 #define	memlist_intersect	dr_memlist_intersect
89 #define	memlist_coalesce	dr_memlist_coalesce
90 #define	memlist_dup		dr_memlist_dup
91 #define	memlist_add_span	dr_memlist_add_span
92 #define	memlist_del_span	dr_memlist_del_span
93 #define	memlist_cat_span	dr_memlist_cat_span
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 #endif /* _SYS_DR_UTIL_H_ */
100