1164190Sjkoshy/*-
2164190Sjkoshy * Copyright (c) 2006 Joseph Koshy
3164190Sjkoshy * All rights reserved.
4164190Sjkoshy *
5164190Sjkoshy * Redistribution and use in source and binary forms, with or without
6164190Sjkoshy * modification, are permitted provided that the following conditions
7164190Sjkoshy * are met:
8164190Sjkoshy * 1. Redistributions of source code must retain the above copyright
9164190Sjkoshy *    notice, this list of conditions and the following disclaimer.
10164190Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright
11164190Sjkoshy *    notice, this list of conditions and the following disclaimer in the
12164190Sjkoshy *    documentation and/or other materials provided with the distribution.
13164190Sjkoshy *
14164190Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15164190Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16164190Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17164190Sjkoshy * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18164190Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19164190Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20164190Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21164190Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22164190Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23164190Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24164190Sjkoshy * SUCH DAMAGE.
25164190Sjkoshy *
26164190Sjkoshy * $FreeBSD$
27164190Sjkoshy */
28164190Sjkoshy
29164190Sjkoshy#ifndef	_GELF_H_
30164190Sjkoshy#define	_GELF_H_
31164190Sjkoshy
32164190Sjkoshy#include <sys/cdefs.h>
33164190Sjkoshy
34164190Sjkoshy#include <libelf.h>
35164190Sjkoshy#include <osreldate.h>
36164190Sjkoshy
37164190Sjkoshytypedef Elf64_Addr	GElf_Addr;	/* Addresses */
38164190Sjkoshytypedef Elf64_Half	GElf_Half;	/* Half words (16 bit) */
39164190Sjkoshytypedef Elf64_Off	GElf_Off;	/* Offsets */
40164190Sjkoshytypedef Elf64_Sword	GElf_Sword;	/* Signed words (32 bit) */
41164190Sjkoshytypedef Elf64_Sxword	GElf_Sxword;	/* Signed long words (64 bit) */
42164190Sjkoshytypedef Elf64_Word	GElf_Word;	/* Unsigned words (32 bit) */
43164190Sjkoshytypedef Elf64_Xword	GElf_Xword;	/* Unsigned long words (64 bit) */
44164190Sjkoshy
45164190Sjkoshytypedef Elf64_Dyn	GElf_Dyn;	/* ".dynamic" section entries */
46164190Sjkoshytypedef Elf64_Ehdr	GElf_Ehdr;	/* ELF header */
47164190Sjkoshytypedef Elf64_Phdr	GElf_Phdr;	/* Program header */
48164190Sjkoshytypedef Elf64_Shdr	GElf_Shdr;	/* Section header */
49164190Sjkoshytypedef Elf64_Sym	GElf_Sym;	/* Symbol table entries */
50164190Sjkoshytypedef Elf64_Rel	GElf_Rel;	/* Relocation entries */
51164190Sjkoshytypedef Elf64_Rela	GElf_Rela;	/* Relocation entries with addend */
52164190Sjkoshy
53165317Sjkoshy#if	__FreeBSD_version >= 700025
54164190Sjkoshytypedef	Elf64_Cap	GElf_Cap;	/* SW/HW capabilities */
55164190Sjkoshytypedef Elf64_Move	GElf_Move;	/* Move entries */
56164190Sjkoshytypedef Elf64_Syminfo	GElf_Syminfo;	/* Symbol information */
57164190Sjkoshy#endif
58164190Sjkoshy
59167315Sjkoshy#define	GELF_M_INFO			ELF64_M_INFO
60167315Sjkoshy#define	GELF_M_SIZE			ELF64_M_SIZE
61167315Sjkoshy#define	GELF_M_SYM			ELF64_M_SYM
62167315Sjkoshy
63167315Sjkoshy#define	GELF_R_INFO			ELF64_R_INFO
64167315Sjkoshy#define	GELF_R_SYM			ELF64_R_SYM
65167315Sjkoshy#define	GELF_R_TYPE			ELF64_R_TYPE
66167315Sjkoshy#define	GELF_R_TYPE_DATA		ELF64_R_TYPE_DATA
67167315Sjkoshy#define	GELF_R_TYPE_ID			ELF64_R_TYPE_ID
68167315Sjkoshy#define	GELF_R_TYPE_INFO		ELF64_R_TYPE_INFO
69167315Sjkoshy
70167315Sjkoshy#define	GELF_ST_BIND			ELF64_ST_BIND
71167315Sjkoshy#define	GELF_ST_INFO			ELF64_ST_INFO
72167315Sjkoshy#define	GELF_ST_TYPE			ELF64_ST_TYPE
73167315Sjkoshy#define	GELF_ST_VISIBILITY		ELF64_ST_VISIBILITY
74167315Sjkoshy
75164190Sjkoshy__BEGIN_DECLS
76164190Sjkoshylong		gelf_checksum(Elf *_elf);
77164190Sjkoshysize_t		gelf_fsize(Elf *_elf, Elf_Type _type, size_t _count,
78164190Sjkoshy			unsigned int _version);
79164190Sjkoshyint		gelf_getclass(Elf *_elf);
80164190SjkoshyGElf_Dyn	*gelf_getdyn(Elf_Data *_data, int _index, GElf_Dyn *_dst);
81164190SjkoshyGElf_Ehdr	*gelf_getehdr(Elf *_elf, GElf_Ehdr *_dst);
82164190SjkoshyGElf_Phdr	*gelf_getphdr(Elf *_elf, int _index, GElf_Phdr *_dst);
83164190SjkoshyGElf_Rel	*gelf_getrel(Elf_Data *_src, int _index, GElf_Rel *_dst);
84164190SjkoshyGElf_Rela	*gelf_getrela(Elf_Data *_src, int _index, GElf_Rela *_dst);
85164190SjkoshyGElf_Shdr	*gelf_getshdr(Elf_Scn *_scn, GElf_Shdr *_dst);
86164190SjkoshyGElf_Sym	*gelf_getsym(Elf_Data *_src, int _index, GElf_Sym *_dst);
87164190SjkoshyGElf_Sym	*gelf_getsymshndx(Elf_Data *_src, Elf_Data *_shindexsrc,
88164190Sjkoshy			int _index, GElf_Sym *_dst, Elf32_Word *_shindexdst);
89164190Sjkoshyvoid *		gelf_newehdr(Elf *_elf, int _class);
90164190Sjkoshyvoid *		gelf_newphdr(Elf *_elf, size_t _phnum);
91164190Sjkoshyint		gelf_update_dyn(Elf_Data *_dst, int _index, GElf_Dyn *_src);
92164190Sjkoshyint		gelf_update_ehdr(Elf *_elf, GElf_Ehdr *_src);
93164190Sjkoshyint		gelf_update_phdr(Elf *_elf, int _index, GElf_Phdr *_src);
94164190Sjkoshyint		gelf_update_rel(Elf_Data *_dst, int _index, GElf_Rel *_src);
95164190Sjkoshyint		gelf_update_rela(Elf_Data *_dst, int _index, GElf_Rela *_src);
96164190Sjkoshyint		gelf_update_shdr(Elf_Scn *_dst, GElf_Shdr *_src);
97164190Sjkoshyint		gelf_update_sym(Elf_Data *_dst, int _index, GElf_Sym *_src);
98164190Sjkoshyint		gelf_update_symshndx(Elf_Data *_symdst, Elf_Data *_shindexdst,
99164190Sjkoshy			int _index, GElf_Sym *_symsrc, Elf32_Word _shindexsrc);
100164190SjkoshyElf_Data 	*gelf_xlatetof(Elf *_elf, Elf_Data *_dst, const Elf_Data *_src, unsigned int _encode);
101164190SjkoshyElf_Data 	*gelf_xlatetom(Elf *_elf, Elf_Data *_dst, const Elf_Data *_src, unsigned int _encode);
102164190Sjkoshy
103165317Sjkoshy#if	__FreeBSD_version >= 700025
104164190SjkoshyGElf_Cap	*gelf_getcap(Elf_Data *_data, int _index, GElf_Cap *_cap);
105164190SjkoshyGElf_Move	*gelf_getmove(Elf_Data *_src, int _index, GElf_Move *_dst);
106164190SjkoshyGElf_Syminfo	*gelf_getsyminfo(Elf_Data *_src, int _index, GElf_Syminfo *_dst);
107164190Sjkoshyint		gelf_update_cap(Elf_Data *_dst, int _index, GElf_Cap *_src);
108164190Sjkoshyint		gelf_update_move(Elf_Data *_dst, int _index, GElf_Move *_src);
109164190Sjkoshyint		gelf_update_syminfo(Elf_Data *_dst, int _index, GElf_Syminfo *_src);
110164190Sjkoshy#endif
111164190Sjkoshy__END_DECLS
112164190Sjkoshy
113164190Sjkoshy#endif	/* _GELF_H_ */
114