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"
39 elf_rawdata(Elf_Scn
* scn
, Elf_Data
* data
)
41 Dnode
* d
= (Dnode
*)data
;
50 if ((scn
->s_myflags
& SF_READY
) == 0) {
51 UPGRADELOCKS(elf
, scn
)
52 if ((scn
->s_myflags
& SF_READY
) == 0)
53 (void) _elf_cookscn(scn
);
54 DOWNGRADELOCKS(elf
, scn
)
67 if (d
->db_scn
!= scn
) {
68 _elf_seterr(EREQ_DATA
, 0);
74 * The data may come from a previously constructed Dbuf,
75 * from the file's raw memory image, or the file system.
76 * "Empty" regions get an empty buffer.
80 rc
= &d
->db_raw
->db_data
;
85 if ((raw
= _elf_dnode()) == 0) {
89 raw
->db_myflags
|= DBF_READY
;
90 if ((d
->db_off
== 0) || (d
->db_fsz
== 0)) {
92 raw
->db_data
.d_size
= d
->db_shsz
;
102 if ((d
->db_off
< 0) ||
103 (d
->db_off
>= elf
->ed_fsz
) ||
104 (elf
->ed_fsz
- d
->db_off
< d
->db_fsz
)) {
105 _elf_seterr(EFMT_DATA
, 0);
107 READUNLOCKS(elf
, scn
)
110 raw
->db_data
.d_size
= d
->db_fsz
;
111 if (elf
->ed_raw
!= 0) {
112 raw
->db_data
.d_buf
= (Elf_Void
*)(elf
->ed_raw
+ d
->db_off
);
115 READUNLOCKS(elf
, scn
)
118 raw
->db_buf
= (Elf_Void
*)_elf_read(elf
->ed_fd
,
119 elf
->ed_baseoff
+ d
->db_off
, d
->db_fsz
);
120 if (raw
->db_buf
== 0) {
122 READUNLOCKS(elf
, scn
)
125 raw
->db_data
.d_buf
= raw
->db_buf
;
128 READUNLOCKS(elf
, scn
)