xref: /titanic_51/usr/src/lib/libctf/common/ctf_subr.c (revision 7fd791373689a6af05e27efec3b1ab556e02aa23)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <ctf_impl.h>
287c478bd9Sstevel@tonic-gate #include <libctf.h>
297c478bd9Sstevel@tonic-gate #include <sys/mman.h>
307c478bd9Sstevel@tonic-gate #include <stdarg.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate void *
337c478bd9Sstevel@tonic-gate ctf_data_alloc(size_t size)
347c478bd9Sstevel@tonic-gate {
357c478bd9Sstevel@tonic-gate 	return (mmap(NULL, size, PROT_READ | PROT_WRITE,
367c478bd9Sstevel@tonic-gate 	    MAP_PRIVATE | MAP_ANON, -1, 0));
377c478bd9Sstevel@tonic-gate }
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate void
407c478bd9Sstevel@tonic-gate ctf_data_free(void *buf, size_t size)
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate 	(void) munmap(buf, size);
437c478bd9Sstevel@tonic-gate }
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate void
467c478bd9Sstevel@tonic-gate ctf_data_protect(void *buf, size_t size)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate 	(void) mprotect(buf, size, PROT_READ);
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate void *
527c478bd9Sstevel@tonic-gate ctf_alloc(size_t size)
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate 	return (malloc(size));
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate 
57*7fd79137SRobert Mustacchi void *
58*7fd79137SRobert Mustacchi mergeq_alloc(size_t size)
59*7fd79137SRobert Mustacchi {
60*7fd79137SRobert Mustacchi 	return (malloc(size));
61*7fd79137SRobert Mustacchi }
62*7fd79137SRobert Mustacchi 
63*7fd79137SRobert Mustacchi void *
64*7fd79137SRobert Mustacchi workq_alloc(size_t size)
65*7fd79137SRobert Mustacchi {
66*7fd79137SRobert Mustacchi 	return (malloc(size));
67*7fd79137SRobert Mustacchi }
68*7fd79137SRobert Mustacchi 
697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
707c478bd9Sstevel@tonic-gate void
717c478bd9Sstevel@tonic-gate ctf_free(void *buf, size_t size)
727c478bd9Sstevel@tonic-gate {
737c478bd9Sstevel@tonic-gate 	free(buf);
747c478bd9Sstevel@tonic-gate }
757c478bd9Sstevel@tonic-gate 
76*7fd79137SRobert Mustacchi /*ARGSUSED*/
77*7fd79137SRobert Mustacchi void
78*7fd79137SRobert Mustacchi mergeq_free(void *buf, size_t size)
79*7fd79137SRobert Mustacchi {
80*7fd79137SRobert Mustacchi 	free(buf);
81*7fd79137SRobert Mustacchi }
82*7fd79137SRobert Mustacchi 
83*7fd79137SRobert Mustacchi /*ARGSUSED*/
84*7fd79137SRobert Mustacchi void
85*7fd79137SRobert Mustacchi workq_free(void *buf, size_t size)
86*7fd79137SRobert Mustacchi {
87*7fd79137SRobert Mustacchi 	free(buf);
88*7fd79137SRobert Mustacchi }
89*7fd79137SRobert Mustacchi 
907c478bd9Sstevel@tonic-gate const char *
917c478bd9Sstevel@tonic-gate ctf_strerror(int err)
927c478bd9Sstevel@tonic-gate {
937c478bd9Sstevel@tonic-gate 	return (strerror(err));
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
977c478bd9Sstevel@tonic-gate void
987c478bd9Sstevel@tonic-gate ctf_dprintf(const char *format, ...)
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	if (_libctf_debug) {
1017c478bd9Sstevel@tonic-gate 		va_list alist;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 		va_start(alist, format);
1047c478bd9Sstevel@tonic-gate 		(void) fputs("libctf DEBUG: ", stderr);
1057c478bd9Sstevel@tonic-gate 		(void) vfprintf(stderr, format, alist);
1067c478bd9Sstevel@tonic-gate 		va_end(alist);
1077c478bd9Sstevel@tonic-gate 	}
1087c478bd9Sstevel@tonic-gate }
109