1*1545Seschrock /* 2*1545Seschrock * CDDL HEADER START 3*1545Seschrock * 4*1545Seschrock * The contents of this file are subject to the terms of the 5*1545Seschrock * Common Development and Distribution License (the "License"). 6*1545Seschrock * You may not use this file except in compliance with the License. 7*1545Seschrock * 8*1545Seschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1545Seschrock * or http://www.opensolaris.org/os/licensing. 10*1545Seschrock * See the License for the specific language governing permissions 11*1545Seschrock * and limitations under the License. 12*1545Seschrock * 13*1545Seschrock * When distributing Covered Code, include this CDDL HEADER in each 14*1545Seschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1545Seschrock * If applicable, add the following below this CDDL HEADER, with the 16*1545Seschrock * fields enclosed by brackets "[]" replaced with your own identifying 17*1545Seschrock * information: Portions Copyright [yyyy] [name of copyright owner] 18*1545Seschrock * 19*1545Seschrock * CDDL HEADER END 20*1545Seschrock */ 21*1545Seschrock 22*1545Seschrock /* 23*1545Seschrock * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24*1545Seschrock * Use is subject to license terms. 25*1545Seschrock */ 26*1545Seschrock 27*1545Seschrock #pragma ident "%Z%%M% %I% %E% SMI" 28*1545Seschrock 29*1545Seschrock #include <libdisasm.h> 30*1545Seschrock #include <stdlib.h> 31*1545Seschrock #ifdef DIS_STANDALONE 32*1545Seschrock #include <mdb/mdb_modapi.h> 33*1545Seschrock #endif 34*1545Seschrock 35*1545Seschrock static int _dis_errno; 36*1545Seschrock 37*1545Seschrock /* 38*1545Seschrock * For the standalone library, we need to link against mdb's malloc/free. 39*1545Seschrock * Otherwise, use the standard malloc/free. 40*1545Seschrock */ 41*1545Seschrock #ifdef DIS_STANDALONE 42*1545Seschrock void * 43*1545Seschrock dis_zalloc(size_t bytes) 44*1545Seschrock { 45*1545Seschrock return (mdb_zalloc(bytes, UM_SLEEP)); 46*1545Seschrock } 47*1545Seschrock 48*1545Seschrock void 49*1545Seschrock dis_free(void *ptr, size_t bytes) 50*1545Seschrock { 51*1545Seschrock mdb_free(ptr, bytes); 52*1545Seschrock } 53*1545Seschrock #else 54*1545Seschrock void * 55*1545Seschrock dis_zalloc(size_t bytes) 56*1545Seschrock { 57*1545Seschrock return (calloc(1, bytes)); 58*1545Seschrock } 59*1545Seschrock 60*1545Seschrock /*ARGSUSED*/ 61*1545Seschrock void 62*1545Seschrock dis_free(void *ptr, size_t bytes) 63*1545Seschrock { 64*1545Seschrock free(ptr); 65*1545Seschrock } 66*1545Seschrock #endif 67*1545Seschrock 68*1545Seschrock int 69*1545Seschrock dis_seterrno(int error) 70*1545Seschrock { 71*1545Seschrock _dis_errno = error; 72*1545Seschrock return (-1); 73*1545Seschrock } 74*1545Seschrock 75*1545Seschrock int 76*1545Seschrock dis_errno(void) 77*1545Seschrock { 78*1545Seschrock return (_dis_errno); 79*1545Seschrock } 80*1545Seschrock 81*1545Seschrock const char * 82*1545Seschrock dis_strerror(int error) 83*1545Seschrock { 84*1545Seschrock switch (error) { 85*1545Seschrock case E_DIS_NOMEM: 86*1545Seschrock return ("out of memory"); 87*1545Seschrock case E_DIS_INVALFLAG: 88*1545Seschrock return ("invalid flags for this architecture"); 89*1545Seschrock default: 90*1545Seschrock return ("unknown error"); 91*1545Seschrock } 92*1545Seschrock } 93