Path: blob/main/cddl/contrib/opensolaris/lib/libctf/common/ctf_subr.c
39535 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License, Version 1.0 only5* (the "License"). You may not use this file except in compliance6* with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or http://www.opensolaris.org/os/licensing.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/21/*22* Copyright 2003 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/2526#pragma ident "%Z%%M% %I% %E% SMI"2728#include <ctf_impl.h>29#include <sys/mman.h>30#include <stdarg.h>3132void *33ctf_data_alloc(size_t size)34{35return (mmap(NULL, size, PROT_READ | PROT_WRITE,36MAP_PRIVATE | MAP_ANON, -1, 0));37}3839void40ctf_data_free(void *buf, size_t size)41{42(void) munmap(buf, size);43}4445void46ctf_data_protect(void *buf, size_t size)47{48(void) mprotect(buf, size, PROT_READ);49}5051void *52ctf_alloc(size_t size)53{54return (malloc(size));55}5657/*ARGSUSED*/58void59ctf_free(void *buf, __unused size_t size)60{61free(buf);62}6364const char *65ctf_strerror(int err)66{67return ((const char *) strerror(err));68}6970/*PRINTFLIKE1*/71void72ctf_dprintf(const char *format, ...)73{74if (_libctf_debug) {75va_list alist;7677va_start(alist, format);78(void) fputs("libctf DEBUG: ", stderr);79(void) vfprintf(stderr, format, alist);80va_end(alist);81}82}838485