xref: /illumos-gate/usr/src/uts/common/ctf/ctf_subr.c (revision 1e56f352c1c208679012bca47d552e127f5b1072)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include <ctf_impl.h>
28 #include <sys/kobj.h>
29 #include <sys/kobj_impl.h>
30 
31 /*
32  * This module is used both during the normal operation of the kernel (i.e.
33  * after kmem has been initialized) and during boot (before unix`_start has
34  * been called).  kobj_alloc is able to tell the difference between the two
35  * cases, and as such must be used instead of kmem_alloc.
36  */
37 
38 void *
39 ctf_data_alloc(size_t size)
40 {
41 	void *buf = kobj_alloc(size, KM_NOWAIT|KM_SCRATCH);
42 
43 	if (buf == NULL)
44 		return (MAP_FAILED);
45 
46 	return (buf);
47 }
48 
49 void
50 ctf_data_free(void *buf, size_t size)
51 {
52 	kobj_free(buf, size);
53 }
54 
55 /*ARGSUSED*/
56 void
57 ctf_data_protect(void *buf, size_t size)
58 {
59 	/* we don't support this operation in the kernel */
60 }
61 
62 void *
63 ctf_alloc(size_t size)
64 {
65 	return (kobj_alloc(size, KM_NOWAIT|KM_TMP));
66 }
67 
68 /*ARGSUSED*/
69 void
70 ctf_free(void *buf, size_t size)
71 {
72 	kobj_free(buf, size);
73 }
74 
75 /*ARGSUSED*/
76 const char *
77 ctf_strerror(int err)
78 {
79 	return (NULL); /* we don't support this operation in the kernel */
80 }
81 
82 /*PRINTFLIKE1*/
83 void
84 ctf_dprintf(const char *format, ...)
85 {
86 	if (_libctf_debug) {
87 		va_list alist;
88 
89 		va_start(alist, format);
90 		(void) printf("ctf DEBUG: ");
91 		(void) vprintf(format, alist);
92 		va_end(alist);
93 	}
94 }
95