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 * This module is compiled twice, the second time having
39 * -D_ELF64 defined. The following set of macros, along
40 * with machelf.h, represent the differences between the
41 * two compilations. Be careful *not* to add any class-
42 * dependent code (anything that has elf32 or elf64 in the
43 * name) to this code without hiding it behind a switch-
44 * able macro like these.
48 #define ELFCLASS ELFCLASS64
49 #define _elf_ehdr_init _elf64_ehdr_init
50 #define elf_newehdr elf64_newehdr
51 #define getehdr elf64_getehdr
53 #else /* else ELF32 */
55 #define ELFCLASS ELFCLASS32
56 #define _elf_ehdr_init _elf32_ehdr_init
57 #define elf_newehdr elf32_newehdr
58 #define getehdr elf32_getehdr
64 elf_newehdr(Elf
* elf
)
72 * If reading file, return its hdr
76 if (elf
->ed_myflags
& EDF_READ
) {
78 if ((eh
= (Ehdr
*)getehdr(elf
)) != 0) {
80 elf
->ed_ehflags
|= ELF_F_DIRTY
;
90 if (elf
->ed_class
== ELFCLASSNONE
)
91 elf
->ed_class
= ELFCLASS
;
92 else if (elf
->ed_class
!= ELFCLASS
) {
93 _elf_seterr(EREQ_CLASS
, 0);
98 if ((eh
= (Ehdr
*)getehdr(elf
)) != 0) { /* this cooks if necessary */
100 elf
->ed_ehflags
|= ELF_F_DIRTY
;
106 if ((eh
= (Ehdr
*)malloc(sizeof (Ehdr
))) == 0) {
107 _elf_seterr(EMEM_EHDR
, errno
);
111 *eh
= _elf_ehdr_init
;
112 elf
->ed_myflags
|= EDF_EHALLOC
;
113 elf
->ed_ehflags
|= ELF_F_DIRTY
;