17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 287c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 297c478bd9Sstevel@tonic-gate #include <sys/debug.h> 307c478bd9Sstevel@tonic-gate #include <sys/mman.h> 317c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 327c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 337c478bd9Sstevel@tonic-gate #include <ctf_impl.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate int ctf_leave_compressed = 0; 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = { 387c478bd9Sstevel@tonic-gate &mod_miscops, "Compact C Type Format routines" 397c478bd9Sstevel@tonic-gate }; 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 427c478bd9Sstevel@tonic-gate MODREV_1, &modlmisc, NULL 437c478bd9Sstevel@tonic-gate }; 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate int 467c478bd9Sstevel@tonic-gate _init(void) 477c478bd9Sstevel@tonic-gate { 487c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 497c478bd9Sstevel@tonic-gate } 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate int 527c478bd9Sstevel@tonic-gate _info(struct modinfo *mip) 537c478bd9Sstevel@tonic-gate { 547c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, mip)); 557c478bd9Sstevel@tonic-gate } 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate int 587c478bd9Sstevel@tonic-gate _fini(void) 597c478bd9Sstevel@tonic-gate { 607c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 617c478bd9Sstevel@tonic-gate } 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 647c478bd9Sstevel@tonic-gate void * 657c478bd9Sstevel@tonic-gate ctf_zopen(int *errp) 667c478bd9Sstevel@tonic-gate { 677c478bd9Sstevel@tonic-gate return ((void *)1); /* zmod is always loaded because we depend on it */ 687c478bd9Sstevel@tonic-gate } 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 717c478bd9Sstevel@tonic-gate const void * 727c478bd9Sstevel@tonic-gate ctf_sect_mmap(ctf_sect_t *sp, int fd) 737c478bd9Sstevel@tonic-gate { 747c478bd9Sstevel@tonic-gate return (MAP_FAILED); /* we don't support this in the kernel */ 757c478bd9Sstevel@tonic-gate } 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 787c478bd9Sstevel@tonic-gate void 797c478bd9Sstevel@tonic-gate ctf_sect_munmap(const ctf_sect_t *sp) 807c478bd9Sstevel@tonic-gate { 817c478bd9Sstevel@tonic-gate /* we don't support this in the kernel */ 827c478bd9Sstevel@tonic-gate } 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 857c478bd9Sstevel@tonic-gate ctf_file_t * 867c478bd9Sstevel@tonic-gate ctf_fdopen(int fd, int *errp) 877c478bd9Sstevel@tonic-gate { 887c478bd9Sstevel@tonic-gate return (ctf_set_open_errno(errp, ENOTSUP)); 897c478bd9Sstevel@tonic-gate } 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 927c478bd9Sstevel@tonic-gate ctf_file_t * 937c478bd9Sstevel@tonic-gate ctf_open(const char *filename, int *errp) 947c478bd9Sstevel@tonic-gate { 957c478bd9Sstevel@tonic-gate return (ctf_set_open_errno(errp, ENOTSUP)); 967c478bd9Sstevel@tonic-gate } 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 997c478bd9Sstevel@tonic-gate int 1007c478bd9Sstevel@tonic-gate ctf_write(ctf_file_t *fp, int fd) 1017c478bd9Sstevel@tonic-gate { 1027c478bd9Sstevel@tonic-gate return (ctf_set_errno(fp, ENOTSUP)); 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate int 1067c478bd9Sstevel@tonic-gate ctf_version(int version) 1077c478bd9Sstevel@tonic-gate { 1087c478bd9Sstevel@tonic-gate ASSERT(version > 0 && version <= CTF_VERSION); 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate if (version > 0) 1117c478bd9Sstevel@tonic-gate _libctf_version = MIN(CTF_VERSION, version); 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate return (_libctf_version); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1177c478bd9Sstevel@tonic-gate ctf_file_t * 118*7fd79137SRobert Mustacchi ctf_fdcreate_int(int fd, int *errp, ctf_sect_t *ctfp) 119*7fd79137SRobert Mustacchi { 120*7fd79137SRobert Mustacchi if (errp != NULL) 121*7fd79137SRobert Mustacchi *errp = ENOTSUP; 122*7fd79137SRobert Mustacchi return (NULL); 123*7fd79137SRobert Mustacchi } 124*7fd79137SRobert Mustacchi 125*7fd79137SRobert Mustacchi /*ARGSUSED*/ 126*7fd79137SRobert Mustacchi ctf_file_t * 1277c478bd9Sstevel@tonic-gate ctf_modopen(struct module *mp, int *error) 1287c478bd9Sstevel@tonic-gate { 1297c478bd9Sstevel@tonic-gate ctf_sect_t ctfsect, symsect, strsect; 1307c478bd9Sstevel@tonic-gate ctf_file_t *fp = NULL; 1317c478bd9Sstevel@tonic-gate int err; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate if (error == NULL) 1347c478bd9Sstevel@tonic-gate error = &err; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate ctfsect.cts_name = ".SUNW_ctf"; 1377c478bd9Sstevel@tonic-gate ctfsect.cts_type = SHT_PROGBITS; 1387c478bd9Sstevel@tonic-gate ctfsect.cts_flags = SHF_ALLOC; 1397c478bd9Sstevel@tonic-gate ctfsect.cts_data = mp->ctfdata; 1407c478bd9Sstevel@tonic-gate ctfsect.cts_size = mp->ctfsize; 1417c478bd9Sstevel@tonic-gate ctfsect.cts_entsize = 1; 1427c478bd9Sstevel@tonic-gate ctfsect.cts_offset = 0; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate symsect.cts_name = ".symtab"; 1457c478bd9Sstevel@tonic-gate symsect.cts_type = SHT_SYMTAB; 1467c478bd9Sstevel@tonic-gate symsect.cts_flags = 0; 1477c478bd9Sstevel@tonic-gate symsect.cts_data = mp->symtbl; 1487c478bd9Sstevel@tonic-gate symsect.cts_size = mp->symhdr->sh_size; 1497c478bd9Sstevel@tonic-gate #ifdef _LP64 1507c478bd9Sstevel@tonic-gate symsect.cts_entsize = sizeof (Elf64_Sym); 1517c478bd9Sstevel@tonic-gate #else 1527c478bd9Sstevel@tonic-gate symsect.cts_entsize = sizeof (Elf32_Sym); 1537c478bd9Sstevel@tonic-gate #endif 1547c478bd9Sstevel@tonic-gate symsect.cts_offset = 0; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate strsect.cts_name = ".strtab"; 1577c478bd9Sstevel@tonic-gate strsect.cts_type = SHT_STRTAB; 1587c478bd9Sstevel@tonic-gate strsect.cts_flags = 0; 1597c478bd9Sstevel@tonic-gate strsect.cts_data = mp->strings; 1607c478bd9Sstevel@tonic-gate strsect.cts_size = mp->strhdr->sh_size; 1617c478bd9Sstevel@tonic-gate strsect.cts_entsize = 1; 1627c478bd9Sstevel@tonic-gate strsect.cts_offset = 0; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&mod_lock)); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate if ((fp = ctf_bufopen(&ctfsect, &symsect, &strsect, error)) == NULL) 1677c478bd9Sstevel@tonic-gate return (NULL); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate if (!ctf_leave_compressed && (caddr_t)fp->ctf_base != mp->ctfdata) { 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * We must have just uncompressed the CTF data. To avoid 1727c478bd9Sstevel@tonic-gate * others having to pay the (substantial) cost of decompressing 1737c478bd9Sstevel@tonic-gate * the data, we're going to substitute the uncompressed version 1747c478bd9Sstevel@tonic-gate * for the compressed version. Note that this implies that the 1757c478bd9Sstevel@tonic-gate * first CTF consumer will induce memory impact on the system 1767c478bd9Sstevel@tonic-gate * (but in the name of performance of future CTF consumers). 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate kobj_set_ctf(mp, (caddr_t)fp->ctf_base, fp->ctf_size); 1797c478bd9Sstevel@tonic-gate fp->ctf_data.cts_data = fp->ctf_base; 1807c478bd9Sstevel@tonic-gate fp->ctf_data.cts_size = fp->ctf_size; 1817c478bd9Sstevel@tonic-gate } 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate return (fp); 1847c478bd9Sstevel@tonic-gate } 185