xref: /titanic_41/usr/src/head/gelf.h (revision b509e89b2befbaa42939abad9da1d7f5a8c6aaae)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_GELF_H
28 #define	_GELF_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/feature_tests.h>
33 
34 #include <libelf.h>
35 #include <sys/link.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 
42 #if !defined(_INT64_TYPE)
43 #error "64-bit integer types are required by gelf."
44 #endif
45 
46 /*
47  * Class-independent ELF API for Elf utilities.  This is
48  * for manipulating Elf32 and Elf64 specific information
49  * in a format common to both classes.
50  */
51 
52 typedef Elf64_Addr	GElf_Addr;
53 typedef Elf64_Half	GElf_Half;
54 typedef Elf64_Off	GElf_Off;
55 typedef Elf64_Sword	GElf_Sword;
56 typedef Elf64_Sxword	GElf_Sxword;
57 typedef Elf64_Word	GElf_Word;
58 typedef Elf64_Xword	GElf_Xword;
59 
60 typedef Elf64_Ehdr	GElf_Ehdr;
61 typedef	Elf64_Move	GElf_Move;
62 typedef Elf64_Phdr	GElf_Phdr;
63 typedef Elf64_Shdr	GElf_Shdr;
64 typedef Elf64_Sym	GElf_Sym;
65 typedef	Elf64_Syminfo	GElf_Syminfo;
66 typedef Elf64_Rela	GElf_Rela;
67 typedef Elf64_Rel	GElf_Rel;
68 typedef Elf64_Dyn	GElf_Dyn;
69 typedef Elf64_Cap	GElf_Cap;
70 
71 /*
72  * The processing of versioning information can stay the
73  * same because both the Elf32 and Elf64 structures are
74  * of equal sizes.
75  */
76 typedef Elf64_Verdef	GElf_Verdef;
77 typedef Elf64_Verdaux	GElf_Verdaux;
78 typedef Elf64_Verneed	GElf_Verneed;
79 typedef Elf64_Vernaux	GElf_Vernaux;
80 typedef Elf64_Versym	GElf_Versym;
81 
82 /*
83  * move.m_info is encoded using the 64bit fields in Gelf.
84  */
85 #define	GELF_M_SYM	ELF64_M_SYM
86 #define	GELF_M_SIZE	ELF64_M_SIZE
87 
88 /*
89  * sym.st_info field is same size for Elf32 and Elf64.
90  */
91 #define	GELF_ST_BIND	ELF64_ST_BIND
92 #define	GELF_ST_TYPE	ELF64_ST_TYPE
93 #define	GELF_ST_INFO	ELF64_ST_INFO
94 
95 
96 /*
97  * Elf64 r_info may have data field in type id's word,
98  * so GELF_R_TYPE is defined as ELF64_R_TYPE_ID in order
99  * to isolate the proper bits for the true type id.
100  */
101 #define	GELF_R_TYPE		ELF64_R_TYPE_ID
102 #define	GELF_R_SYM		ELF64_R_SYM
103 #define	GELF_R_INFO		ELF64_R_INFO
104 #define	GELF_R_TYPE_DATA	ELF64_R_TYPE_DATA
105 #define	GELF_R_TYPE_ID		ELF64_R_TYPE_ID
106 #define	GELF_R_TYPE_INFO	ELF64_R_TYPE_INFO
107 
108 
109 
110 int		gelf_getclass(Elf*);
111 size_t		gelf_fsize(Elf *, Elf_Type, size_t, uint_t);
112 GElf_Ehdr *	gelf_getehdr(Elf *, GElf_Ehdr *);
113 int		gelf_update_ehdr(Elf *, GElf_Ehdr *);
114 unsigned long	gelf_newehdr(Elf *, int);
115 GElf_Phdr *	gelf_getphdr(Elf *, int, GElf_Phdr *);
116 int		gelf_update_phdr(Elf *, int, GElf_Phdr *);
117 unsigned long	gelf_newphdr(Elf *, size_t);
118 GElf_Shdr *	gelf_getshdr(Elf_Scn *,  GElf_Shdr *);
119 int		gelf_update_shdr(Elf_Scn *, GElf_Shdr *);
120 Elf_Data *	gelf_xlatetof(Elf *, Elf_Data *, const Elf_Data *, uint_t);
121 Elf_Data *	gelf_xlatetom(Elf *, Elf_Data *, const Elf_Data *, uint_t);
122 GElf_Sym *	gelf_getsym(Elf_Data *, int, GElf_Sym *);
123 int		gelf_update_sym(Elf_Data *, int, GElf_Sym *);
124 GElf_Sym *	gelf_getsymshndx(Elf_Data *, Elf_Data *, int, GElf_Sym *,
125 		    Elf32_Word *);
126 int		gelf_update_symshndx(Elf_Data *, Elf_Data *, int, GElf_Sym *,
127 		    Elf32_Word);
128 GElf_Syminfo *	gelf_getsyminfo(Elf_Data *, int, GElf_Syminfo *);
129 int		gelf_update_syminfo(Elf_Data *, int, GElf_Syminfo *);
130 GElf_Move *	gelf_getmove(Elf_Data *, int, GElf_Move *);
131 int		gelf_update_move(Elf_Data *, int, GElf_Move *);
132 GElf_Dyn *	gelf_getdyn(Elf_Data *, int, GElf_Dyn *);
133 int		gelf_update_dyn(Elf_Data *, int, GElf_Dyn *);
134 GElf_Rela *	gelf_getrela(Elf_Data *, int, GElf_Rela *);
135 int		gelf_update_rela(Elf_Data *, int, GElf_Rela *);
136 GElf_Rel *	gelf_getrel(Elf_Data *, int, GElf_Rel *);
137 int		gelf_update_rel(Elf_Data *, int, GElf_Rel *);
138 long		gelf_checksum(Elf *);
139 GElf_Cap *	gelf_getcap(Elf_Data *, int, GElf_Cap *);
140 int		gelf_update_cap(Elf_Data *, int, GElf_Cap *);
141 
142 
143 #ifdef	__cplusplus
144 }
145 #endif
146 
147 #endif	/* _GELF_H */
148