1*cd844e7aSJohn Birrell /*
2*cd844e7aSJohn Birrell * CDDL HEADER START
3*cd844e7aSJohn Birrell *
4*cd844e7aSJohn Birrell * The contents of this file are subject to the terms of the
5*cd844e7aSJohn Birrell * Common Development and Distribution License, Version 1.0 only
6*cd844e7aSJohn Birrell * (the "License"). You may not use this file except in compliance
7*cd844e7aSJohn Birrell * with the License.
8*cd844e7aSJohn Birrell *
9*cd844e7aSJohn Birrell * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*cd844e7aSJohn Birrell * or http://www.opensolaris.org/os/licensing.
11*cd844e7aSJohn Birrell * See the License for the specific language governing permissions
12*cd844e7aSJohn Birrell * and limitations under the License.
13*cd844e7aSJohn Birrell *
14*cd844e7aSJohn Birrell * When distributing Covered Code, include this CDDL HEADER in each
15*cd844e7aSJohn Birrell * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*cd844e7aSJohn Birrell * If applicable, add the following below this CDDL HEADER, with the
17*cd844e7aSJohn Birrell * fields enclosed by brackets "[]" replaced with your own identifying
18*cd844e7aSJohn Birrell * information: Portions Copyright [yyyy] [name of copyright owner]
19*cd844e7aSJohn Birrell *
20*cd844e7aSJohn Birrell * CDDL HEADER END
21*cd844e7aSJohn Birrell */
22*cd844e7aSJohn Birrell /*
23*cd844e7aSJohn Birrell * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*cd844e7aSJohn Birrell * Use is subject to license terms.
25*cd844e7aSJohn Birrell */
26*cd844e7aSJohn Birrell
27*cd844e7aSJohn Birrell #pragma ident "%Z%%M% %I% %E% SMI"
28*cd844e7aSJohn Birrell
29*cd844e7aSJohn Birrell #include <ctf_impl.h>
30*cd844e7aSJohn Birrell #include <sys/kobj.h>
31*cd844e7aSJohn Birrell #include <sys/kobj_impl.h>
32*cd844e7aSJohn Birrell
33*cd844e7aSJohn Birrell /*
34*cd844e7aSJohn Birrell * This module is used both during the normal operation of the kernel (i.e.
35*cd844e7aSJohn Birrell * after kmem has been initialized) and during boot (before unix`_start has
36*cd844e7aSJohn Birrell * been called). kobj_alloc is able to tell the difference between the two
37*cd844e7aSJohn Birrell * cases, and as such must be used instead of kmem_alloc.
38*cd844e7aSJohn Birrell */
39*cd844e7aSJohn Birrell
40*cd844e7aSJohn Birrell void *
ctf_data_alloc(size_t size)41*cd844e7aSJohn Birrell ctf_data_alloc(size_t size)
42*cd844e7aSJohn Birrell {
43*cd844e7aSJohn Birrell void *buf = kobj_alloc(size, KM_NOWAIT|KM_SCRATCH);
44*cd844e7aSJohn Birrell
45*cd844e7aSJohn Birrell if (buf == NULL)
46*cd844e7aSJohn Birrell return (MAP_FAILED);
47*cd844e7aSJohn Birrell
48*cd844e7aSJohn Birrell return (buf);
49*cd844e7aSJohn Birrell }
50*cd844e7aSJohn Birrell
51*cd844e7aSJohn Birrell void
ctf_data_free(void * buf,size_t size)52*cd844e7aSJohn Birrell ctf_data_free(void *buf, size_t size)
53*cd844e7aSJohn Birrell {
54*cd844e7aSJohn Birrell kobj_free(buf, size);
55*cd844e7aSJohn Birrell }
56*cd844e7aSJohn Birrell
57*cd844e7aSJohn Birrell /*ARGSUSED*/
58*cd844e7aSJohn Birrell void
ctf_data_protect(void * buf,size_t size)59*cd844e7aSJohn Birrell ctf_data_protect(void *buf, size_t size)
60*cd844e7aSJohn Birrell {
61*cd844e7aSJohn Birrell /* we don't support this operation in the kernel */
62*cd844e7aSJohn Birrell }
63*cd844e7aSJohn Birrell
64*cd844e7aSJohn Birrell void *
ctf_alloc(size_t size)65*cd844e7aSJohn Birrell ctf_alloc(size_t size)
66*cd844e7aSJohn Birrell {
67*cd844e7aSJohn Birrell return (kobj_alloc(size, KM_NOWAIT|KM_TMP));
68*cd844e7aSJohn Birrell }
69*cd844e7aSJohn Birrell
70*cd844e7aSJohn Birrell /*ARGSUSED*/
71*cd844e7aSJohn Birrell void
ctf_free(void * buf,size_t size)72*cd844e7aSJohn Birrell ctf_free(void *buf, size_t size)
73*cd844e7aSJohn Birrell {
74*cd844e7aSJohn Birrell kobj_free(buf, size);
75*cd844e7aSJohn Birrell }
76*cd844e7aSJohn Birrell
77*cd844e7aSJohn Birrell /*ARGSUSED*/
78*cd844e7aSJohn Birrell const char *
ctf_strerror(int err)79*cd844e7aSJohn Birrell ctf_strerror(int err)
80*cd844e7aSJohn Birrell {
81*cd844e7aSJohn Birrell return (NULL); /* we don't support this operation in the kernel */
82*cd844e7aSJohn Birrell }
83*cd844e7aSJohn Birrell
84*cd844e7aSJohn Birrell /*PRINTFLIKE1*/
85*cd844e7aSJohn Birrell void
ctf_dprintf(const char * format,...)86*cd844e7aSJohn Birrell ctf_dprintf(const char *format, ...)
87*cd844e7aSJohn Birrell {
88*cd844e7aSJohn Birrell if (_libctf_debug) {
89*cd844e7aSJohn Birrell va_list alist;
90*cd844e7aSJohn Birrell
91*cd844e7aSJohn Birrell va_start(alist, format);
92*cd844e7aSJohn Birrell (void) printf("ctf DEBUG: ");
93*cd844e7aSJohn Birrell (void) vprintf(format, alist);
94*cd844e7aSJohn Birrell va_end(alist);
95*cd844e7aSJohn Birrell }
96*cd844e7aSJohn Birrell }
97