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
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.
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]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/sysmacros.h>
28 #include <sys/modctl.h>
29 #include <sys/debug.h>
31 #include <sys/modctl.h>
35 int ctf_leave_compressed
= 0;
37 static struct modlmisc modlmisc
= {
38 &mod_miscops
, "Compact C Type Format routines"
41 static struct modlinkage modlinkage
= {
42 MODREV_1
, &modlmisc
, NULL
48 return (mod_install(&modlinkage
));
52 _info(struct modinfo
*mip
)
54 return (mod_info(&modlinkage
, mip
));
60 return (mod_remove(&modlinkage
));
67 return ((void *)1); /* zmod is always loaded because we depend on it */
72 ctf_sect_mmap(ctf_sect_t
*sp
, int fd
)
74 return (MAP_FAILED
); /* we don't support this in the kernel */
79 ctf_sect_munmap(const ctf_sect_t
*sp
)
81 /* we don't support this in the kernel */
86 ctf_fdopen(int fd
, int *errp
)
88 return (ctf_set_open_errno(errp
, ENOTSUP
));
93 ctf_open(const char *filename
, int *errp
)
95 return (ctf_set_open_errno(errp
, ENOTSUP
));
100 ctf_write(ctf_file_t
*fp
, int fd
)
102 return (ctf_set_errno(fp
, ENOTSUP
));
106 ctf_version(int version
)
108 ASSERT(version
> 0 && version
<= CTF_VERSION
);
111 _libctf_version
= MIN(CTF_VERSION
, version
);
113 return (_libctf_version
);
118 ctf_fdcreate_int(int fd
, int *errp
, ctf_sect_t
*ctfp
)
127 ctf_modopen(struct module
*mp
, int *error
)
129 ctf_sect_t ctfsect
, symsect
, strsect
;
130 ctf_file_t
*fp
= NULL
;
136 ctfsect
.cts_name
= ".SUNW_ctf";
137 ctfsect
.cts_type
= SHT_PROGBITS
;
138 ctfsect
.cts_flags
= SHF_ALLOC
;
139 ctfsect
.cts_data
= mp
->ctfdata
;
140 ctfsect
.cts_size
= mp
->ctfsize
;
141 ctfsect
.cts_entsize
= 1;
142 ctfsect
.cts_offset
= 0;
144 symsect
.cts_name
= ".symtab";
145 symsect
.cts_type
= SHT_SYMTAB
;
146 symsect
.cts_flags
= 0;
147 symsect
.cts_data
= mp
->symtbl
;
148 symsect
.cts_size
= mp
->symhdr
->sh_size
;
150 symsect
.cts_entsize
= sizeof (Elf64_Sym
);
152 symsect
.cts_entsize
= sizeof (Elf32_Sym
);
154 symsect
.cts_offset
= 0;
156 strsect
.cts_name
= ".strtab";
157 strsect
.cts_type
= SHT_STRTAB
;
158 strsect
.cts_flags
= 0;
159 strsect
.cts_data
= mp
->strings
;
160 strsect
.cts_size
= mp
->strhdr
->sh_size
;
161 strsect
.cts_entsize
= 1;
162 strsect
.cts_offset
= 0;
164 ASSERT(MUTEX_HELD(&mod_lock
));
166 if ((fp
= ctf_bufopen(&ctfsect
, &symsect
, &strsect
, error
)) == NULL
)
169 if (!ctf_leave_compressed
&& (caddr_t
)fp
->ctf_base
!= mp
->ctfdata
) {
171 * We must have just uncompressed the CTF data. To avoid
172 * others having to pay the (substantial) cost of decompressing
173 * the data, we're going to substitute the uncompressed version
174 * for the compressed version. Note that this implies that the
175 * first CTF consumer will induce memory impact on the system
176 * (but in the name of performance of future CTF consumers).
178 kobj_set_ctf(mp
, (caddr_t
)fp
->ctf_base
, fp
->ctf_size
);
179 fp
->ctf_data
.cts_data
= fp
->ctf_base
;
180 fp
->ctf_data
.cts_size
= fp
->ctf_size
;