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