16ff6d951SJohn Birrell /*
26ff6d951SJohn Birrell  * CDDL HEADER START
36ff6d951SJohn Birrell  *
46ff6d951SJohn Birrell  * The contents of this file are subject to the terms of the
56ff6d951SJohn Birrell  * Common Development and Distribution License, Version 1.0 only
66ff6d951SJohn Birrell  * (the "License").  You may not use this file except in compliance
76ff6d951SJohn Birrell  * with the License.
86ff6d951SJohn Birrell  *
96ff6d951SJohn Birrell  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
106ff6d951SJohn Birrell  * or http://www.opensolaris.org/os/licensing.
116ff6d951SJohn Birrell  * See the License for the specific language governing permissions
126ff6d951SJohn Birrell  * and limitations under the License.
136ff6d951SJohn Birrell  *
146ff6d951SJohn Birrell  * When distributing Covered Code, include this CDDL HEADER in each
156ff6d951SJohn Birrell  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
166ff6d951SJohn Birrell  * If applicable, add the following below this CDDL HEADER, with the
176ff6d951SJohn Birrell  * fields enclosed by brackets "[]" replaced with your own identifying
186ff6d951SJohn Birrell  * information: Portions Copyright [yyyy] [name of copyright owner]
196ff6d951SJohn Birrell  *
206ff6d951SJohn Birrell  * CDDL HEADER END
216ff6d951SJohn Birrell  */
226ff6d951SJohn Birrell /*
236ff6d951SJohn Birrell  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
246ff6d951SJohn Birrell  * Use is subject to license terms.
256ff6d951SJohn Birrell  */
266ff6d951SJohn Birrell 
276ff6d951SJohn Birrell #pragma ident	"%Z%%M%	%I%	%E% SMI"
286ff6d951SJohn Birrell 
296ff6d951SJohn Birrell #include <ctf_impl.h>
306ff6d951SJohn Birrell #include <sys/mman.h>
316ff6d951SJohn Birrell #include <stdarg.h>
326ff6d951SJohn Birrell 
336ff6d951SJohn Birrell void *
ctf_data_alloc(size_t size)346ff6d951SJohn Birrell ctf_data_alloc(size_t size)
356ff6d951SJohn Birrell {
366ff6d951SJohn Birrell 	return (mmap(NULL, size, PROT_READ | PROT_WRITE,
376ff6d951SJohn Birrell 	    MAP_PRIVATE | MAP_ANON, -1, 0));
386ff6d951SJohn Birrell }
396ff6d951SJohn Birrell 
406ff6d951SJohn Birrell void
ctf_data_free(void * buf,size_t size)416ff6d951SJohn Birrell ctf_data_free(void *buf, size_t size)
426ff6d951SJohn Birrell {
436ff6d951SJohn Birrell 	(void) munmap(buf, size);
446ff6d951SJohn Birrell }
456ff6d951SJohn Birrell 
466ff6d951SJohn Birrell void
ctf_data_protect(void * buf,size_t size)476ff6d951SJohn Birrell ctf_data_protect(void *buf, size_t size)
486ff6d951SJohn Birrell {
496ff6d951SJohn Birrell 	(void) mprotect(buf, size, PROT_READ);
506ff6d951SJohn Birrell }
516ff6d951SJohn Birrell 
526ff6d951SJohn Birrell void *
ctf_alloc(size_t size)536ff6d951SJohn Birrell ctf_alloc(size_t size)
546ff6d951SJohn Birrell {
556ff6d951SJohn Birrell 	return (malloc(size));
566ff6d951SJohn Birrell }
576ff6d951SJohn Birrell 
586ff6d951SJohn Birrell /*ARGSUSED*/
596ff6d951SJohn Birrell void
ctf_free(void * buf,__unused size_t size)60c8392607SJohn Birrell ctf_free(void *buf, __unused size_t size)
616ff6d951SJohn Birrell {
626ff6d951SJohn Birrell 	free(buf);
636ff6d951SJohn Birrell }
646ff6d951SJohn Birrell 
656ff6d951SJohn Birrell const char *
ctf_strerror(int err)666ff6d951SJohn Birrell ctf_strerror(int err)
676ff6d951SJohn Birrell {
68c8392607SJohn Birrell 	return ((const char *) strerror(err));
696ff6d951SJohn Birrell }
706ff6d951SJohn Birrell 
716ff6d951SJohn Birrell /*PRINTFLIKE1*/
726ff6d951SJohn Birrell void
ctf_dprintf(const char * format,...)736ff6d951SJohn Birrell ctf_dprintf(const char *format, ...)
746ff6d951SJohn Birrell {
756ff6d951SJohn Birrell 	if (_libctf_debug) {
766ff6d951SJohn Birrell 		va_list alist;
776ff6d951SJohn Birrell 
786ff6d951SJohn Birrell 		va_start(alist, format);
796ff6d951SJohn Birrell 		(void) fputs("libctf DEBUG: ", stderr);
806ff6d951SJohn Birrell 		(void) vfprintf(stderr, format, alist);
816ff6d951SJohn Birrell 		va_end(alist);
826ff6d951SJohn Birrell 	}
836ff6d951SJohn Birrell }
84