1*6ff6d951SJohn Birrell /* 2*6ff6d951SJohn Birrell * CDDL HEADER START 3*6ff6d951SJohn Birrell * 4*6ff6d951SJohn Birrell * The contents of this file are subject to the terms of the 5*6ff6d951SJohn Birrell * Common Development and Distribution License, Version 1.0 only 6*6ff6d951SJohn Birrell * (the "License"). You may not use this file except in compliance 7*6ff6d951SJohn Birrell * with the License. 8*6ff6d951SJohn Birrell * 9*6ff6d951SJohn Birrell * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*6ff6d951SJohn Birrell * or http://www.opensolaris.org/os/licensing. 11*6ff6d951SJohn Birrell * See the License for the specific language governing permissions 12*6ff6d951SJohn Birrell * and limitations under the License. 13*6ff6d951SJohn Birrell * 14*6ff6d951SJohn Birrell * When distributing Covered Code, include this CDDL HEADER in each 15*6ff6d951SJohn Birrell * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*6ff6d951SJohn Birrell * If applicable, add the following below this CDDL HEADER, with the 17*6ff6d951SJohn Birrell * fields enclosed by brackets "[]" replaced with your own identifying 18*6ff6d951SJohn Birrell * information: Portions Copyright [yyyy] [name of copyright owner] 19*6ff6d951SJohn Birrell * 20*6ff6d951SJohn Birrell * CDDL HEADER END 21*6ff6d951SJohn Birrell */ 22*6ff6d951SJohn Birrell /* 23*6ff6d951SJohn Birrell * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*6ff6d951SJohn Birrell * Use is subject to license terms. 25*6ff6d951SJohn Birrell */ 26*6ff6d951SJohn Birrell 27*6ff6d951SJohn Birrell #pragma ident "%Z%%M% %I% %E% SMI" 28*6ff6d951SJohn Birrell 29*6ff6d951SJohn Birrell #include <ctf_impl.h> 30*6ff6d951SJohn Birrell #include <sys/mman.h> 31*6ff6d951SJohn Birrell #include <stdarg.h> 32*6ff6d951SJohn Birrell 33*6ff6d951SJohn Birrell void * 34*6ff6d951SJohn Birrell ctf_data_alloc(size_t size) 35*6ff6d951SJohn Birrell { 36*6ff6d951SJohn Birrell return (mmap(NULL, size, PROT_READ | PROT_WRITE, 37*6ff6d951SJohn Birrell MAP_PRIVATE | MAP_ANON, -1, 0)); 38*6ff6d951SJohn Birrell } 39*6ff6d951SJohn Birrell 40*6ff6d951SJohn Birrell void 41*6ff6d951SJohn Birrell ctf_data_free(void *buf, size_t size) 42*6ff6d951SJohn Birrell { 43*6ff6d951SJohn Birrell (void) munmap(buf, size); 44*6ff6d951SJohn Birrell } 45*6ff6d951SJohn Birrell 46*6ff6d951SJohn Birrell void 47*6ff6d951SJohn Birrell ctf_data_protect(void *buf, size_t size) 48*6ff6d951SJohn Birrell { 49*6ff6d951SJohn Birrell (void) mprotect(buf, size, PROT_READ); 50*6ff6d951SJohn Birrell } 51*6ff6d951SJohn Birrell 52*6ff6d951SJohn Birrell void * 53*6ff6d951SJohn Birrell ctf_alloc(size_t size) 54*6ff6d951SJohn Birrell { 55*6ff6d951SJohn Birrell return (malloc(size)); 56*6ff6d951SJohn Birrell } 57*6ff6d951SJohn Birrell 58*6ff6d951SJohn Birrell /*ARGSUSED*/ 59*6ff6d951SJohn Birrell void 60*6ff6d951SJohn Birrell ctf_free(void *buf, __unused size_t size) 61*6ff6d951SJohn Birrell { 62*6ff6d951SJohn Birrell free(buf); 63*6ff6d951SJohn Birrell } 64*6ff6d951SJohn Birrell 65*6ff6d951SJohn Birrell const char * 66*6ff6d951SJohn Birrell ctf_strerror(int err) 67*6ff6d951SJohn Birrell { 68*6ff6d951SJohn Birrell return ((const char *) strerror(err)); 69*6ff6d951SJohn Birrell } 70*6ff6d951SJohn Birrell 71*6ff6d951SJohn Birrell /*PRINTFLIKE1*/ 72*6ff6d951SJohn Birrell void 73*6ff6d951SJohn Birrell ctf_dprintf(const char *format, ...) 74*6ff6d951SJohn Birrell { 75*6ff6d951SJohn Birrell if (_libctf_debug) { 76*6ff6d951SJohn Birrell va_list alist; 77*6ff6d951SJohn Birrell 78*6ff6d951SJohn Birrell va_start(alist, format); 79*6ff6d951SJohn Birrell (void) fputs("libctf DEBUG: ", stderr); 80*6ff6d951SJohn Birrell (void) vfprintf(stderr, format, alist); 81*6ff6d951SJohn Birrell va_end(alist); 82*6ff6d951SJohn Birrell } 83*6ff6d951SJohn Birrell } 84