xref: /illumos-gate/usr/src/cmd/file/elf_read.h (revision c26bf377e2245534feb1f92b43f6d4ed32513c41)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _ELF_READ_H
27 #define	_ELF_READ_H
28 
29 #define	BUFSZ 128
30 typedef struct Elf_Info {
31 	boolean_t	dynamic;	/* dymanically linked? */
32 	unsigned	core_type;	/* core? what type of core? */
33 	unsigned	stripped;	/* symtab, debug info */
34 	unsigned	flags;		/* e_flags */
35 	unsigned	machine;	/* e_machine */
36 	unsigned	type;		/* e_type */
37 	int		elffd;		/* fd of file being processed */
38 	char		fname[PRFNSZ];	/* name of process that dumped core */
39 	char		cap_str[BUFSZ];	/* hw/sw capabilities */
40 	char		*file;		/* file being processed */
41 	boolean_t	kmod;
42 } Elf_Info;
43 
44 /* values for Elf_Info.stripped */
45 #define	E_DBGINF	0x01
46 #define	E_SYMTAB	0x02
47 #define	E_NOSTRIP	0x03
48 
49 /* values for Elf_Info.core_type; */
50 #define	EC_NOTCORE	0x0
51 #define	EC_OLDCORE	0x1
52 #define	EC_NEWCORE	0x2
53 
54 /* elf file processing errors */
55 #define	ELF_ERR_ELFCAP1		gettext("%s: %s zero size or zero entry ELF " \
56 	"section - ELF capabilities ignored\n")
57 #define	ELF_ERR_ELFCAP2		gettext("%s: %s: can't read ELF capabilities " \
58 	"data - ELF capabilities ignored\n")
59 #define	ELF_ERR_DYNAMIC1	gettext("%s: %s zero size or zero entry ELF " \
60 	"section - ELF dynamic tags ignored\n")
61 #define	ELF_ERR_DYNAMIC2	gettext("%s: %s: can't read ELF dynamic " \
62 	"data - ELF dynamic tags ignored\n")
63 
64 extern int is_in_list(char *str);
65 
66 /* return status for elf_read and its helper functions */
67 #define	ELF_READ_OKAY 1
68 #define	ELF_READ_FAIL 0
69 
70 #if defined(_ELF64)
71 
72 #define	Elf_Ehdr	Elf64_Ehdr
73 #define	Elf_Shdr	Elf64_Shdr
74 #define	Elf_Phdr	Elf64_Phdr
75 #define	Elf_Cap		Elf64_Cap
76 #define	Elf_Nhdr	Elf64_Nhdr
77 #define	Elf_Word	Elf64_Word
78 #define	Elf_Dyn		Elf64_Dyn
79 
80 #define	elf_read	elf_read64
81 #define	elf_xlatetom	elf64_xlatetom
82 #define	elf_fsize	elf64_fsize
83 #define	get_class	get_class64
84 #define	get_version	get_version64
85 #define	get_format	get_format64
86 
87 #else
88 
89 #define	Elf_Ehdr	Elf32_Ehdr
90 #define	Elf_Shdr	Elf32_Shdr
91 #define	Elf_Phdr	Elf32_Phdr
92 #define	Elf_Cap		Elf32_Cap
93 #define	Elf_Nhdr	Elf32_Nhdr
94 #define	Elf_Word	Elf32_Word
95 #define	Elf_Dyn		Elf32_Dyn
96 
97 #define	elf_read	elf_read32
98 #define	elf_xlatetom	elf32_xlatetom
99 #define	elf_fsize	elf32_fsize
100 #define	get_class	get_class32
101 #define	get_version	get_version32
102 #define	get_format	get_format32
103 
104 #endif
105 
106 /* so lint can understand elf_read64 is defined */
107 #ifdef lint
108 #define	elf_read64	elf_read
109 #endif /* lint */
110 
111 #endif /* _ELF_READ_H */
112