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