4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
38 elf_strptr(Elf
* elf
, size_t ndx
, size_t off
)
46 if ((s
= elf_getscn(elf
, ndx
)) == 0) {
47 _elf_seterr(EREQ_STRSCN
, 0);
51 if (elf
->ed_class
== ELFCLASS32
) {
52 Elf32_Shdr
* sh
= (Elf32_Shdr
*)s
->s_shdr
;
54 if ((sh
== 0) || (sh
->sh_type
!= SHT_STRTAB
)) {
55 _elf_seterr(EREQ_STRSCN
, 0);
59 } else if (elf
->ed_class
== ELFCLASS64
) {
60 Elf64_Shdr
* sh
= (Elf64_Shdr
*)s
->s_shdr
;
62 if ((sh
== 0) || (sh
->sh_type
!= SHT_STRTAB
)) {
63 _elf_seterr(EREQ_STRSCN
, 0);
68 _elf_seterr(EREQ_STRSCN
, 0);
75 * If the layout bit is set, use the offsets and
76 * sizes in the data buffers. Otherwise, take
77 * data buffers in order.
81 if (elf
->ed_uflags
& ELF_F_LAYOUT
) {
82 while ((d
= _elf_locked_getdata(s
, d
)) != 0) {
85 if ((off
>= d
->d_off
) &&
86 (off
< d
->d_off
+ d
->d_size
)) {
87 rc
= (char *)d
->d_buf
+ off
- d
->d_off
;
94 while ((d
= _elf_locked_getdata(s
, d
)) != 0) {
95 if (((j
= d
->d_align
) > 1) && (sz
% j
!= 0)) {
103 if (off
< d
->d_size
) {
104 rc
= (char *)d
->d_buf
+ off
;
115 _elf_seterr(EREQ_STROFF
, 0);