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