10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 56812Sraf * Common Development and Distribution License (the "License"). 66812Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 216812Sraf 226812Sraf /* 23*12457SAli.Bahrami@Oracle.COM * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. 246812Sraf */ 256812Sraf 260Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 29*12457SAli.Bahrami@Oracle.COM #include <ar.h> 300Sstevel@tonic-gate #include "libelf.h" 310Sstevel@tonic-gate #include "decl.h" 320Sstevel@tonic-gate 330Sstevel@tonic-gate 340Sstevel@tonic-gate off_t elf_getbase(Elf * elf)35*12457SAli.Bahrami@Oracle.COMelf_getbase(Elf *elf) 360Sstevel@tonic-gate { 370Sstevel@tonic-gate off_t rc; 38*12457SAli.Bahrami@Oracle.COM if (elf == NULL) 390Sstevel@tonic-gate return (-1); 400Sstevel@tonic-gate ELFRLOCK(elf) 410Sstevel@tonic-gate rc = elf->ed_baseoff; 420Sstevel@tonic-gate ELFUNLOCK(elf) 430Sstevel@tonic-gate return (rc); 440Sstevel@tonic-gate } 45*12457SAli.Bahrami@Oracle.COM 46*12457SAli.Bahrami@Oracle.COM /* 47*12457SAli.Bahrami@Oracle.COM * Private function to obtain the offset of the archive header for 48*12457SAli.Bahrami@Oracle.COM * this archive member. The header directly precedes the base offset, 49*12457SAli.Bahrami@Oracle.COM * which is available via elf_getbase(), but we wish to isolate the 50*12457SAli.Bahrami@Oracle.COM * caller from implementation details that might change. 51*12457SAli.Bahrami@Oracle.COM * 52*12457SAli.Bahrami@Oracle.COM * Returns the offset on success, and -1 on failure. 53*12457SAli.Bahrami@Oracle.COM */ 54*12457SAli.Bahrami@Oracle.COM off_t _elf_getarhdrbase(Elf * elf)55*12457SAli.Bahrami@Oracle.COM_elf_getarhdrbase(Elf *elf) 56*12457SAli.Bahrami@Oracle.COM { 57*12457SAli.Bahrami@Oracle.COM off_t rc; 58*12457SAli.Bahrami@Oracle.COM if (elf == NULL) 59*12457SAli.Bahrami@Oracle.COM return (-1); 60*12457SAli.Bahrami@Oracle.COM ELFRLOCK(elf) 61*12457SAli.Bahrami@Oracle.COM if (elf->ed_parent == NULL) { 62*12457SAli.Bahrami@Oracle.COM _elf_seterr(EREQ_AR, 0); 63*12457SAli.Bahrami@Oracle.COM ELFUNLOCK(elf); 64*12457SAli.Bahrami@Oracle.COM return (-1); 65*12457SAli.Bahrami@Oracle.COM } 66*12457SAli.Bahrami@Oracle.COM rc = elf->ed_baseoff - sizeof (struct ar_hdr); 67*12457SAli.Bahrami@Oracle.COM ELFUNLOCK(elf) 68*12457SAli.Bahrami@Oracle.COM return (rc); 69*12457SAli.Bahrami@Oracle.COM } 70