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 57257d1b4Sraf * Common Development and Distribution License (the "License"). 67257d1b4Sraf * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217257d1b4Sraf 227257d1b4Sraf /* 23*2a93c375SAli Bahrami * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. 247257d1b4Sraf */ 257257d1b4Sraf 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 29*2a93c375SAli Bahrami #include <ar.h> 307c478bd9Sstevel@tonic-gate #include "libelf.h" 317c478bd9Sstevel@tonic-gate #include "decl.h" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate off_t elf_getbase(Elf * elf)357c478bd9Sstevel@tonic-gateelf_getbase(Elf *elf) 367c478bd9Sstevel@tonic-gate { 377c478bd9Sstevel@tonic-gate off_t rc; 38*2a93c375SAli Bahrami if (elf == NULL) 397c478bd9Sstevel@tonic-gate return (-1); 407c478bd9Sstevel@tonic-gate ELFRLOCK(elf) 417c478bd9Sstevel@tonic-gate rc = elf->ed_baseoff; 427c478bd9Sstevel@tonic-gate ELFUNLOCK(elf) 437c478bd9Sstevel@tonic-gate return (rc); 447c478bd9Sstevel@tonic-gate } 45*2a93c375SAli Bahrami 46*2a93c375SAli Bahrami /* 47*2a93c375SAli Bahrami * Private function to obtain the offset of the archive header for 48*2a93c375SAli Bahrami * this archive member. The header directly precedes the base offset, 49*2a93c375SAli Bahrami * which is available via elf_getbase(), but we wish to isolate the 50*2a93c375SAli Bahrami * caller from implementation details that might change. 51*2a93c375SAli Bahrami * 52*2a93c375SAli Bahrami * Returns the offset on success, and -1 on failure. 53*2a93c375SAli Bahrami */ 54*2a93c375SAli Bahrami off_t _elf_getarhdrbase(Elf * elf)55*2a93c375SAli Bahrami_elf_getarhdrbase(Elf *elf) 56*2a93c375SAli Bahrami { 57*2a93c375SAli Bahrami off_t rc; 58*2a93c375SAli Bahrami if (elf == NULL) 59*2a93c375SAli Bahrami return (-1); 60*2a93c375SAli Bahrami ELFRLOCK(elf) 61*2a93c375SAli Bahrami if (elf->ed_parent == NULL) { 62*2a93c375SAli Bahrami _elf_seterr(EREQ_AR, 0); 63*2a93c375SAli Bahrami ELFUNLOCK(elf); 64*2a93c375SAli Bahrami return (-1); 65*2a93c375SAli Bahrami } 66*2a93c375SAli Bahrami rc = elf->ed_baseoff - sizeof (struct ar_hdr); 67*2a93c375SAli Bahrami ELFUNLOCK(elf) 68*2a93c375SAli Bahrami return (rc); 69*2a93c375SAli Bahrami } 70