Path: blob/main/sys/cddl/contrib/opensolaris/uts/common/ctf/ctf_mod.c
96395 views
/*1* CDDL HEADER START2*3* The contents of this file are subject to the terms of the4* Common Development and Distribution License, Version 1.0 only5* (the "License"). You may not use this file except in compliance6* with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or http://www.opensolaris.org/os/licensing.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/21/*22* Copyright 2003 Sun Microsystems, Inc. All rights reserved.23* Use is subject to license terms.24*/2526#pragma ident "%Z%%M% %I% %E% SMI"2728#include <sys/sysmacros.h>29#include <sys/modctl.h>30#include <sys/debug.h>31#include <sys/mman.h>32#include <sys/modctl.h>33#include <sys/kobj.h>34#include <ctf_impl.h>3536int ctf_leave_compressed = 0;3738static struct modlmisc modlmisc = {39&mod_miscops, "Compact C Type Format routines"40};4142static struct modlinkage modlinkage = {43MODREV_1, &modlmisc, NULL44};4546int47_init(void)48{49return (mod_install(&modlinkage));50}5152int53_info(struct modinfo *mip)54{55return (mod_info(&modlinkage, mip));56}5758int59_fini(void)60{61return (mod_remove(&modlinkage));62}6364/*ARGSUSED*/65void *66ctf_zopen(int *errp)67{68return ((void *)1); /* zmod is always loaded because we depend on it */69}7071/*ARGSUSED*/72const void *73ctf_sect_mmap(ctf_sect_t *sp, int fd)74{75return (MAP_FAILED); /* we don't support this in the kernel */76}7778/*ARGSUSED*/79void80ctf_sect_munmap(const ctf_sect_t *sp)81{82/* we don't support this in the kernel */83}8485/*ARGSUSED*/86ctf_file_t *87ctf_fdopen(int fd, int *errp)88{89return (ctf_set_open_errno(errp, ENOTSUP));90}9192/*ARGSUSED*/93ctf_file_t *94ctf_open(const char *filename, int *errp)95{96return (ctf_set_open_errno(errp, ENOTSUP));97}9899/*ARGSUSED*/100int101ctf_write(ctf_file_t *fp, int fd)102{103return (ctf_set_errno(fp, ENOTSUP));104}105106int107ctf_version(int version)108{109ASSERT(version > 0 && version <= CTF_VERSION);110111if (version > 0)112_libctf_version = MIN(CTF_VERSION, version);113114return (_libctf_version);115}116117/*ARGSUSED*/118ctf_file_t *119ctf_modopen(struct module *mp, int *error)120{121ctf_sect_t ctfsect, symsect, strsect;122ctf_file_t *fp = NULL;123int err;124125if (error == NULL)126error = &err;127128ctfsect.cts_name = ".SUNW_ctf";129ctfsect.cts_type = SHT_PROGBITS;130ctfsect.cts_flags = SHF_ALLOC;131ctfsect.cts_data = mp->ctfdata;132ctfsect.cts_size = mp->ctfsize;133ctfsect.cts_entsize = 1;134ctfsect.cts_offset = 0;135136symsect.cts_name = ".symtab";137symsect.cts_type = SHT_SYMTAB;138symsect.cts_flags = 0;139symsect.cts_data = mp->symtbl;140symsect.cts_size = mp->symhdr->sh_size;141#ifdef _LP64142symsect.cts_entsize = sizeof (Elf64_Sym);143#else144symsect.cts_entsize = sizeof (Elf32_Sym);145#endif146symsect.cts_offset = 0;147148strsect.cts_name = ".strtab";149strsect.cts_type = SHT_STRTAB;150strsect.cts_flags = 0;151strsect.cts_data = mp->strings;152strsect.cts_size = mp->strhdr->sh_size;153strsect.cts_entsize = 1;154strsect.cts_offset = 0;155156ASSERT(MUTEX_HELD(&mod_lock));157158if ((fp = ctf_bufopen(&ctfsect, &symsect, &strsect, error)) == NULL)159return (NULL);160161if (!ctf_leave_compressed && (caddr_t)fp->ctf_base != mp->ctfdata) {162/*163* We must have just uncompressed the CTF data. To avoid164* others having to pay the (substantial) cost of decompressing165* the data, we're going to substitute the uncompressed version166* for the compressed version. Note that this implies that the167* first CTF consumer will induce memory impact on the system168* (but in the name of performance of future CTF consumers).169*/170kobj_set_ctf(mp, (caddr_t)fp->ctf_base, fp->ctf_size);171fp->ctf_data.cts_data = fp->ctf_base;172fp->ctf_data.cts_size = fp->ctf_size;173}174175return (fp);176}177178179