2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License, Version 1.0 only 2N/A * (the "License"). You may not use this file except in compliance 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A const char *p =
getenv(
"LIBCTF_DECOMPRESSOR");
2N/A * Attempt to dlopen the decompression library and locate the symbols of 2N/A * interest that we will need to call. This information in cached so 2N/A * that multiple calls to ctf_bufopen() do not need to reopen the library. 2N/A * The ctf_bufopen() routine calls these subroutines, defined by <sys/zmod.h>, 2N/A * which we then patch through to the functions in the decompression library. 2N/A * Convert a 32-bit ELF file header into GElf. 2N/A * Convert a 32-bit ELF section header into GElf. 2N/A * In order to mmap a section from the ELF file, we must round down sh_offset 2N/A * to the previous page boundary, and mmap the surrounding page. We store 2N/A * the pointer to the start of the actual section data back into sp->cts_data. 2N/A * Since sp->cts_data has the adjusted offset, we have to again round down 2N/A * to get the actual mmap address and round up to get the size. 2N/A * Open the specified file descriptor and return a pointer to a CTF container. 2N/A * The file can be either an ELF file or raw CTF file. The caller is 2N/A * responsible for closing the file descriptor when it is no longer needed. 2N/A * If we have read enough bytes to form a CTF header and the magic 2N/A * string matches, attempt to interpret the file as raw CTF. 2N/A * If we have read enough bytes to form an ELF header and the magic 2N/A * string matches, attempt to interpret the file as an ELF file. We 2N/A * do our own largefile ELF processing, and convert everything to 2N/A * GElf structures so that clients can operate on any data model. 2N/A * Read in and convert to GElf the array of Shdr structures 2N/A * from e_shoff so we can locate sections of interest. 2N/A for (i = 0; i < n; i++)
2N/A * Now mmap the section header strings section so that we can 2N/A * perform string comparison on the section names. 2N/A * Iterate over the section header array looking for the CTF 2N/A * section and symbol table. The strtab is linked to symtab. 2N/A for (i = 0; i < n; i++) {
2N/A continue;
/* corrupt sh_link field */ 2N/A continue;
/* corrupt sh_name field */ 2N/A * Now mmap the CTF data, symtab, and strtab sections and 2N/A * call ctf_bufopen() to do the rest of the work. 2N/A goto bad;
/* unmap all and abort */ 2N/A * Open the specified file and return a pointer to a CTF container. The file 2N/A * can be either an ELF file or raw CTF file. This is just a convenient 2N/A * wrapper around ctf_fdopen() for callers. 2N/A * Write the uncompressed CTF data stream to the specified file descriptor. 2N/A * This is useful for saving the results of dynamic CTF containers. 2N/A * Set the CTF library client version to the specified version. If version is 2N/A * zero, we just return the default library version number.