summaryrefslogtreecommitdiffstats
path: root/src/VBox/ExtPacks/VBoxDTrace/onnv/lib/libctf/common/ctf_subr.c
blob: 7de8069b81b74e7167e84916c198eaf441f22c95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef VBOX
#pragma ident	"%Z%%M%	%I%	%E% SMI"
#endif

#include <ctf_impl.h>
#include <libctf.h>
#ifndef VBOX
#include <sys/mman.h>
#include <stdarg.h>
#else
# include <iprt/asm.h>
# include <iprt/log.h>
#endif

void *
ctf_data_alloc(size_t size)
{
#ifndef VBOX
	return (mmap(NULL, size, PROT_READ | PROT_WRITE,
	    MAP_PRIVATE | MAP_ANON, -1, 0));
#else
    void *pv = RTMemPageAlloc(size);
    return pv == NULL ? MAP_FAILED : pv;
#endif
}

void
ctf_data_free(void *buf, size_t size)
{
#ifndef VBOX
	(void) munmap(buf, size);
#else
    RTMemProtect(buf, size, RTMEM_PROT_WRITE | RTMEM_PROT_READ);
    RTMemPageFree(buf, size);
#endif
}

void
ctf_data_protect(void *buf, size_t size)
{
#ifndef VBOX
	(void) mprotect(buf, size, PROT_READ);
#else
    int rc = RTMemProtect(buf, size, RTMEM_PROT_READ);
    AssertRC(rc);
#endif
}

void *
ctf_alloc(size_t size)
{
#ifndef VBOX
	return (malloc(size));
#else
    return RTMemAlloc(size);
#endif
}

/*ARGSUSED*/
void
ctf_free(void *buf, size_t size)
{
#ifndef VBOX
	free(buf);
#else
    RT_NOREF1(size);
    RTMemFree(buf);
#endif
}

const char *
ctf_strerror(int err)
{
	return (strerror(err));
}

/*PRINTFLIKE1*/
void
ctf_dprintf(const char *format, ...)
{
	if (_libctf_debug) {
		va_list alist;

		va_start(alist, format);
#ifndef VBOX
		(void) fputs("libctf DEBUG: ", stderr);
		(void) vfprintf(stderr, format, alist);
#else
        RTLogPrintf("libctf DEBUG: %N", format, alist);
#endif
		va_end(alist);
	}
}