xref: /titanic_51/usr/src/cmd/mdb/common/libstandctf/ctf_subr.c (revision c10c16dec587a0662068f6e2991c29ed3a9db943)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <mdb/mdb_debug.h>
30 #include <mdb/mdb.h>
31 
32 #include <sys/types.h>
33 #include <sys/mman.h>
34 #include <sys/zmod.h>
35 
36 #include <ctf_impl.h>
37 #include <stdlib.h>
38 
39 /*ARGSUSED*/
40 void *
41 ctf_zopen(int *errp)
42 {
43 	/* The kernel will have decompressed the buffer for us */
44 	return (ctf_set_open_errno(errp, ECTF_ZMISSING));
45 }
46 
47 /*ARGSUSED*/
48 const void *
49 ctf_sect_mmap(ctf_sect_t *sp, int fd)
50 {
51 	return (MAP_FAILED); /* we don't support this in kmdb  */
52 }
53 
54 /*ARGSUSED*/
55 void
56 ctf_sect_munmap(const ctf_sect_t *sp)
57 {
58 	/* we don't support this in kmdb */
59 }
60 
61 /*ARGSUSED*/
62 ctf_file_t *
63 ctf_fdopen(int fd, int *errp)
64 {
65 	return (ctf_set_open_errno(errp, ENOTSUP));
66 }
67 
68 /*ARGSUSED*/
69 ctf_file_t *
70 ctf_open(const char *filename, int *errp)
71 {
72 	return (ctf_set_open_errno(errp, ENOTSUP));
73 }
74 
75 int
76 ctf_version(int version)
77 {
78 	ASSERT(version > 0 && version <= CTF_VERSION);
79 
80 	if (version > 0)
81 		_libctf_version = MIN(CTF_VERSION, version);
82 
83 	return (_libctf_version);
84 }
85 
86 void *
87 ctf_data_alloc(size_t size)
88 {
89 	void *buf = mdb_alloc(size, UM_NOSLEEP);
90 
91 	if (buf == NULL)
92 		return (MAP_FAILED);
93 
94 	return (buf);
95 }
96 
97 void
98 ctf_data_free(void *buf, size_t size)
99 {
100 	mdb_free(buf, size);
101 }
102 
103 /*ARGSUSED*/
104 void
105 ctf_data_protect(void *buf, size_t size)
106 {
107 	/* Not supported in kmdb */
108 }
109 
110 void *
111 ctf_alloc(size_t size)
112 {
113 	return (mdb_alloc(size, UM_NOSLEEP));
114 }
115 
116 void
117 ctf_free(void *buf, size_t size)
118 {
119 	mdb_free(buf, size);
120 }
121 
122 /*ARGSUSED*/
123 const char *
124 ctf_strerror(int err)
125 {
126 	return (NULL); /* Not supported in kmdb */
127 }
128 
129 /*PRINTFLIKE1*/
130 void
131 ctf_dprintf(const char *format, ...)
132 {
133 	va_list alist;
134 
135 	va_start(alist, format);
136 	mdb_dvprintf(MDB_DBG_CTF, format, alist);
137 	va_end(alist);
138 }
139 
140 /*ARGSUSED*/
141 int
142 z_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen)
143 {
144 	return (Z_ERRNO);
145 }
146 
147 /*ARGSUSED*/
148 const char *
149 z_strerror(int err)
150 {
151 	return ("zlib unsupported in kmdb");
152 }
153 
154 int
155 ctf_vsnprintf(char *buf, size_t nbytes, const char *format, va_list alist)
156 {
157 	return ((int)mdb_iob_vsnprintf(buf, nbytes, format, alist));
158 }
159