1da0c48c4Sopenharmony_ci/* Interface for libebl.
2da0c48c4Sopenharmony_ci   Copyright (C) 2000-2010, 2013, 2014, 2015, 2016, 2017 Red Hat, Inc.
3da0c48c4Sopenharmony_ci   This file is part of elfutils.
4da0c48c4Sopenharmony_ci
5da0c48c4Sopenharmony_ci   This file is free software; you can redistribute it and/or modify
6da0c48c4Sopenharmony_ci   it under the terms of either
7da0c48c4Sopenharmony_ci
8da0c48c4Sopenharmony_ci     * the GNU Lesser General Public License as published by the Free
9da0c48c4Sopenharmony_ci       Software Foundation; either version 3 of the License, or (at
10da0c48c4Sopenharmony_ci       your option) any later version
11da0c48c4Sopenharmony_ci
12da0c48c4Sopenharmony_ci   or
13da0c48c4Sopenharmony_ci
14da0c48c4Sopenharmony_ci     * the GNU General Public License as published by the Free
15da0c48c4Sopenharmony_ci       Software Foundation; either version 2 of the License, or (at
16da0c48c4Sopenharmony_ci       your option) any later version
17da0c48c4Sopenharmony_ci
18da0c48c4Sopenharmony_ci   or both in parallel, as here.
19da0c48c4Sopenharmony_ci
20da0c48c4Sopenharmony_ci   elfutils is distributed in the hope that it will be useful, but
21da0c48c4Sopenharmony_ci   WITHOUT ANY WARRANTY; without even the implied warranty of
22da0c48c4Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23da0c48c4Sopenharmony_ci   General Public License for more details.
24da0c48c4Sopenharmony_ci
25da0c48c4Sopenharmony_ci   You should have received copies of the GNU General Public License and
26da0c48c4Sopenharmony_ci   the GNU Lesser General Public License along with this program.  If
27da0c48c4Sopenharmony_ci   not, see <http://www.gnu.org/licenses/>.  */
28da0c48c4Sopenharmony_ci
29da0c48c4Sopenharmony_ci
30da0c48c4Sopenharmony_ci/* This is the interface for the Elfutils Backend Library.
31da0c48c4Sopenharmony_ci   It is a completely UNSUPPORTED interface.  Don't use any libebl
32da0c48c4Sopenharmony_ci   function directly.  These are only for internal elfutils backends
33da0c48c4Sopenharmony_ci   and tools.  There is NO source or binary compatible guarantee.  */
34da0c48c4Sopenharmony_ci
35da0c48c4Sopenharmony_ci
36da0c48c4Sopenharmony_ci#ifndef _LIBEBL_H
37da0c48c4Sopenharmony_ci#define _LIBEBL_H 1
38da0c48c4Sopenharmony_ci
39da0c48c4Sopenharmony_ci#include <gelf.h>
40da0c48c4Sopenharmony_ci#include "libdw.h"
41da0c48c4Sopenharmony_ci#include <stdbool.h>
42da0c48c4Sopenharmony_ci#include <stddef.h>
43da0c48c4Sopenharmony_ci#include <stdint.h>
44da0c48c4Sopenharmony_ci
45da0c48c4Sopenharmony_ci#include "elf-knowledge.h"
46da0c48c4Sopenharmony_ci
47da0c48c4Sopenharmony_ci
48da0c48c4Sopenharmony_ci/* Opaque type for the handle.  libasm.h defined the same thing.  */
49da0c48c4Sopenharmony_ci#ifndef _LIBASM_H
50da0c48c4Sopenharmony_citypedef struct ebl Ebl;
51da0c48c4Sopenharmony_ci#endif
52da0c48c4Sopenharmony_ci
53da0c48c4Sopenharmony_ci
54da0c48c4Sopenharmony_ci#ifdef __cplusplus
55da0c48c4Sopenharmony_ciextern "C" {
56da0c48c4Sopenharmony_ci#endif
57da0c48c4Sopenharmony_ci
58da0c48c4Sopenharmony_ci/* Get backend handle for object associated with ELF handle.  */
59da0c48c4Sopenharmony_ciextern Ebl *ebl_openbackend (Elf *elf);
60da0c48c4Sopenharmony_ci/* Similar but without underlying ELF file.  */
61da0c48c4Sopenharmony_ciextern Ebl *ebl_openbackend_machine (GElf_Half machine);
62da0c48c4Sopenharmony_ci/* Similar but with emulation name given.  */
63da0c48c4Sopenharmony_ciextern Ebl *ebl_openbackend_emulation (const char *emulation);
64da0c48c4Sopenharmony_ci
65da0c48c4Sopenharmony_ci/* Free resources allocated for backend handle.  */
66da0c48c4Sopenharmony_ciextern void ebl_closebackend (Ebl *bh);
67da0c48c4Sopenharmony_ci
68da0c48c4Sopenharmony_ci
69da0c48c4Sopenharmony_ci/* Information about the descriptor.  */
70da0c48c4Sopenharmony_ci
71da0c48c4Sopenharmony_ci/* Get ELF machine.  */
72da0c48c4Sopenharmony_ciextern int ebl_get_elfmachine (Ebl *ebl) __pure_attribute__;
73da0c48c4Sopenharmony_ci
74da0c48c4Sopenharmony_ci/* Get ELF class.  */
75da0c48c4Sopenharmony_ciextern int ebl_get_elfclass (Ebl *ebl) __pure_attribute__;
76da0c48c4Sopenharmony_ci
77da0c48c4Sopenharmony_ci/* Get ELF data encoding.  */
78da0c48c4Sopenharmony_ciextern int ebl_get_elfdata (Ebl *ebl) __pure_attribute__;
79da0c48c4Sopenharmony_ci
80da0c48c4Sopenharmony_ci
81da0c48c4Sopenharmony_ci/* Function to call the callback functions including default ELF
82da0c48c4Sopenharmony_ci   handling.  */
83da0c48c4Sopenharmony_ci
84da0c48c4Sopenharmony_ci/* Return backend name.  */
85da0c48c4Sopenharmony_ciextern const char *ebl_backend_name (Ebl *ebl);
86da0c48c4Sopenharmony_ci
87da0c48c4Sopenharmony_ci/* Return relocation type name.  */
88da0c48c4Sopenharmony_ciextern const char *ebl_reloc_type_name (Ebl *ebl, int reloc,
89da0c48c4Sopenharmony_ci					char *buf, size_t len);
90da0c48c4Sopenharmony_ci
91da0c48c4Sopenharmony_ci/* Check relocation type.  */
92da0c48c4Sopenharmony_ciextern bool ebl_reloc_type_check (Ebl *ebl, int reloc);
93da0c48c4Sopenharmony_ci
94da0c48c4Sopenharmony_ci/* Check relocation type use.  */
95da0c48c4Sopenharmony_ciextern bool ebl_reloc_valid_use (Ebl *ebl, int reloc);
96da0c48c4Sopenharmony_ci
97da0c48c4Sopenharmony_ci/* Check if relocation type is for simple absolute relocations.
98da0c48c4Sopenharmony_ci   Return ELF_T_{BYTE,HALF,SWORD,SXWORD} for a simple type, else ELF_T_NUM.
99da0c48c4Sopenharmony_ci   If the relocation type is an ADD or SUB relocation, set *ADDSUB to 1 or -1,
100da0c48c4Sopenharmony_ci   resp.  */
101da0c48c4Sopenharmony_ciextern Elf_Type ebl_reloc_simple_type (Ebl *ebl, int reloc, int *addsub);
102da0c48c4Sopenharmony_ci
103da0c48c4Sopenharmony_ci/* Return true if the symbol type is that referencing the GOT.  E.g.,
104da0c48c4Sopenharmony_ci   R_386_GOTPC.  */
105da0c48c4Sopenharmony_ciextern bool ebl_gotpc_reloc_check (Ebl *ebl, int reloc);
106da0c48c4Sopenharmony_ci
107da0c48c4Sopenharmony_ci/* Return segment type name.  */
108da0c48c4Sopenharmony_ciextern const char *ebl_segment_type_name (Ebl *ebl, int segment,
109da0c48c4Sopenharmony_ci					  char *buf, size_t len);
110da0c48c4Sopenharmony_ci
111da0c48c4Sopenharmony_ci/* Return section type name.  */
112da0c48c4Sopenharmony_ciextern const char *ebl_section_type_name (Ebl *ebl, int section,
113da0c48c4Sopenharmony_ci					  char *buf, size_t len);
114da0c48c4Sopenharmony_ci
115da0c48c4Sopenharmony_ci/* Return section name.  */
116da0c48c4Sopenharmony_ciextern const char *ebl_section_name (Ebl *ebl, int section, int xsection,
117da0c48c4Sopenharmony_ci				     char *buf, size_t len,
118da0c48c4Sopenharmony_ci				     const char *scnnames[], size_t shnum);
119da0c48c4Sopenharmony_ci
120da0c48c4Sopenharmony_ci/* Return machine flag names.  */
121da0c48c4Sopenharmony_ciextern const char *ebl_machine_flag_name (Ebl *ebl, GElf_Word flags,
122da0c48c4Sopenharmony_ci					  char *buf, size_t len);
123da0c48c4Sopenharmony_ci
124da0c48c4Sopenharmony_ci/* Check whether machine flag is valid.  */
125da0c48c4Sopenharmony_ciextern bool ebl_machine_flag_check (Ebl *ebl, GElf_Word flags);
126da0c48c4Sopenharmony_ci
127da0c48c4Sopenharmony_ci/* Check whether SHF_MASKPROC flags are valid.  */
128da0c48c4Sopenharmony_ciextern bool ebl_machine_section_flag_check (Ebl *ebl, GElf_Xword flags);
129da0c48c4Sopenharmony_ci
130da0c48c4Sopenharmony_ci/* Check whether the section with the given index, header, and name
131da0c48c4Sopenharmony_ci   is a special machine section that is valid despite a combination
132da0c48c4Sopenharmony_ci   of flags or other details that are not generically valid.  */
133da0c48c4Sopenharmony_ciextern bool ebl_check_special_section (Ebl *ebl, int ndx,
134da0c48c4Sopenharmony_ci				       const GElf_Shdr *shdr, const char *name);
135da0c48c4Sopenharmony_ci
136da0c48c4Sopenharmony_ci/* Return symbol type name.  */
137da0c48c4Sopenharmony_ciextern const char *ebl_symbol_type_name (Ebl *ebl, int symbol,
138da0c48c4Sopenharmony_ci					 char *buf, size_t len);
139da0c48c4Sopenharmony_ci
140da0c48c4Sopenharmony_ci/* Return symbol binding name.  */
141da0c48c4Sopenharmony_ciextern const char *ebl_symbol_binding_name (Ebl *ebl, int binding,
142da0c48c4Sopenharmony_ci					    char *buf, size_t len);
143da0c48c4Sopenharmony_ci
144da0c48c4Sopenharmony_ci/* Return dynamic tag name.  */
145da0c48c4Sopenharmony_ciextern const char *ebl_dynamic_tag_name (Ebl *ebl, int64_t tag,
146da0c48c4Sopenharmony_ci					 char *buf, size_t len);
147da0c48c4Sopenharmony_ci
148da0c48c4Sopenharmony_ci/* Check dynamic tag.  */
149da0c48c4Sopenharmony_ciextern bool ebl_dynamic_tag_check (Ebl *ebl, int64_t tag);
150da0c48c4Sopenharmony_ci
151da0c48c4Sopenharmony_ci/* Check whether given symbol's st_value and st_size are OK despite failing
152da0c48c4Sopenharmony_ci   normal checks.  */
153da0c48c4Sopenharmony_ciextern bool ebl_check_special_symbol (Ebl *ebl,
154da0c48c4Sopenharmony_ci				      const GElf_Sym *sym, const char *name,
155da0c48c4Sopenharmony_ci				      const GElf_Shdr *destshdr);
156da0c48c4Sopenharmony_ci
157da0c48c4Sopenharmony_ci/* Check if this is a data marker symbol.  e.g. '$d' symbols for ARM.  */
158da0c48c4Sopenharmony_ciextern bool ebl_data_marker_symbol (Ebl *ebl, const GElf_Sym *sym,
159da0c48c4Sopenharmony_ci				    const char *sname);
160da0c48c4Sopenharmony_ci
161da0c48c4Sopenharmony_ci/* Check whether only valid bits are set on the st_other symbol flag.  */
162da0c48c4Sopenharmony_ciextern bool ebl_check_st_other_bits (Ebl *ebl, unsigned char st_other);
163da0c48c4Sopenharmony_ci
164da0c48c4Sopenharmony_ci/* Return symbolic representation of OS ABI.  */
165da0c48c4Sopenharmony_ciextern const char *ebl_osabi_name (Ebl *ebl, int osabi, char *buf, size_t len);
166da0c48c4Sopenharmony_ci
167da0c48c4Sopenharmony_ci
168da0c48c4Sopenharmony_ci/* Return name of the note section type for a core file.  */
169da0c48c4Sopenharmony_ciextern const char *ebl_core_note_type_name (Ebl *ebl, uint32_t type, char *buf,
170da0c48c4Sopenharmony_ci					    size_t len);
171da0c48c4Sopenharmony_ci
172da0c48c4Sopenharmony_ci/* Return name of the note section type for an object file.  */
173da0c48c4Sopenharmony_ciextern const char *ebl_object_note_type_name (Ebl *ebl, const char *name,
174da0c48c4Sopenharmony_ci					      uint32_t type, GElf_Word descsz,
175da0c48c4Sopenharmony_ci					      char *buf, size_t len);
176da0c48c4Sopenharmony_ci
177da0c48c4Sopenharmony_ci/* Print information about object note if available.  */
178da0c48c4Sopenharmony_ciextern void ebl_object_note (Ebl *ebl, uint32_t namesz, const char *name,
179da0c48c4Sopenharmony_ci			     uint32_t type, uint32_t descsz, const char *desc);
180da0c48c4Sopenharmony_ci
181da0c48c4Sopenharmony_ci/* Check whether an attribute in a .gnu_attributes section is recognized.
182da0c48c4Sopenharmony_ci   Fills in *TAG_NAME with the name for this tag.
183da0c48c4Sopenharmony_ci   If VALUE is a known value for that tag, also fills in *VALUE_NAME.  */
184da0c48c4Sopenharmony_ciextern bool ebl_check_object_attribute (Ebl *ebl, const char *vendor,
185da0c48c4Sopenharmony_ci					int tag, uint64_t value,
186da0c48c4Sopenharmony_ci					const char **tag_name,
187da0c48c4Sopenharmony_ci					const char **value_name);
188da0c48c4Sopenharmony_ci
189da0c48c4Sopenharmony_ci/* Check whether a section type is a valid reloc target.  */
190da0c48c4Sopenharmony_ciextern bool ebl_check_reloc_target_type (Ebl *ebl, Elf64_Word sh_type);
191da0c48c4Sopenharmony_ci
192da0c48c4Sopenharmony_ci
193da0c48c4Sopenharmony_ci/* Check section name for being that of a debug informatino section.  */
194da0c48c4Sopenharmony_ciextern bool ebl_debugscn_p (Ebl *ebl, const char *name);
195da0c48c4Sopenharmony_ci
196da0c48c4Sopenharmony_ci/* Check whether given relocation is a copy relocation.  */
197da0c48c4Sopenharmony_ciextern bool ebl_copy_reloc_p (Ebl *ebl, int reloc);
198da0c48c4Sopenharmony_ci
199da0c48c4Sopenharmony_ci/* Check whether given relocation is a no-op relocation.  */
200da0c48c4Sopenharmony_ciextern bool ebl_none_reloc_p (Ebl *ebl, int reloc);
201da0c48c4Sopenharmony_ci
202da0c48c4Sopenharmony_ci/* Check whether given relocation is a relative relocation.  */
203da0c48c4Sopenharmony_ciextern bool ebl_relative_reloc_p (Ebl *ebl, int reloc);
204da0c48c4Sopenharmony_ci
205da0c48c4Sopenharmony_ci/* Check whether section should be stripped.  */
206da0c48c4Sopenharmony_ciextern bool ebl_section_strip_p (Ebl *ebl,
207da0c48c4Sopenharmony_ci				 const GElf_Shdr *shdr, const char *name,
208da0c48c4Sopenharmony_ci				 bool remove_comment, bool only_remove_debug);
209da0c48c4Sopenharmony_ci
210da0c48c4Sopenharmony_ci/* Check if backend uses a bss PLT in this file.  */
211da0c48c4Sopenharmony_ciextern bool ebl_bss_plt_p (Ebl *ebl);
212da0c48c4Sopenharmony_ci
213da0c48c4Sopenharmony_ci/* Return size of entry in SysV-style hash table.  */
214da0c48c4Sopenharmony_ciextern int ebl_sysvhash_entrysize (Ebl *ebl);
215da0c48c4Sopenharmony_ci
216da0c48c4Sopenharmony_ci/* Return location expression to find return value given a
217da0c48c4Sopenharmony_ci   DW_TAG_subprogram, DW_TAG_subroutine_type, or similar DIE describing
218da0c48c4Sopenharmony_ci   function itself (whose DW_AT_type attribute describes its return type).
219da0c48c4Sopenharmony_ci   Returns -1 for a libdw error (see dwarf_errno).
220da0c48c4Sopenharmony_ci   Returns -2 for an unrecognized type formation.
221da0c48c4Sopenharmony_ci   Returns zero if the function has no return value (e.g. "void" in C).
222da0c48c4Sopenharmony_ci   Otherwise, *LOCOPS gets a location expression to find the return value,
223da0c48c4Sopenharmony_ci   and returns the number of operations in the expression.  The pointer is
224da0c48c4Sopenharmony_ci   permanently allocated at least as long as the Ebl handle is open.  */
225da0c48c4Sopenharmony_ciextern int ebl_return_value_location (Ebl *ebl,
226da0c48c4Sopenharmony_ci				      Dwarf_Die *functypedie,
227da0c48c4Sopenharmony_ci				      const Dwarf_Op **locops);
228da0c48c4Sopenharmony_ci
229da0c48c4Sopenharmony_ci/* Fill in register information given DWARF register numbers.
230da0c48c4Sopenharmony_ci   If NAME is null, return the maximum REGNO + 1 that has a name.
231da0c48c4Sopenharmony_ci   Otherwise, store in NAME the name for DWARF register number REGNO
232da0c48c4Sopenharmony_ci   and return the number of bytes written (including '\0' terminator).
233da0c48c4Sopenharmony_ci   Return -1 if NAMELEN is too short or REGNO is negative or too large.
234da0c48c4Sopenharmony_ci   Return 0 if REGNO is unused (a gap in the DWARF number assignment).
235da0c48c4Sopenharmony_ci   On success, set *SETNAME to a description like "integer" or "FPU"
236da0c48c4Sopenharmony_ci   fit for "%s registers" title display, and *PREFIX to the string
237da0c48c4Sopenharmony_ci   that precedes NAME in canonical assembler syntax (e.g. "%" or "$").
238da0c48c4Sopenharmony_ci   The NAME string contains identifier characters only (maybe just digits).  */
239da0c48c4Sopenharmony_ciextern ssize_t ebl_register_info (Ebl *ebl,
240da0c48c4Sopenharmony_ci				  int regno, char *name, size_t namelen,
241da0c48c4Sopenharmony_ci				  const char **prefix, const char **setname,
242da0c48c4Sopenharmony_ci				  int *bits, int *type);
243da0c48c4Sopenharmony_ci
244da0c48c4Sopenharmony_ci/* Supply the ABI-specified state of DWARF CFI before CIE initial programs.
245da0c48c4Sopenharmony_ci
246da0c48c4Sopenharmony_ci   The DWARF 3.0 spec says that the default initial states of all registers
247da0c48c4Sopenharmony_ci   are "undefined", unless otherwise specified by the machine/compiler ABI.
248da0c48c4Sopenharmony_ci
249da0c48c4Sopenharmony_ci   This default is wrong for every machine with the CFI generated by GCC.
250da0c48c4Sopenharmony_ci   The EH unwinder does not really distinguish "same_value" and "undefined",
251da0c48c4Sopenharmony_ci   since it doesn't matter for unwinding (in either case there is no change
252da0c48c4Sopenharmony_ci   to make for that register).  GCC generates CFI that says nothing at all
253da0c48c4Sopenharmony_ci   about registers it hasn't spilled somewhere.  For our unwinder to give
254da0c48c4Sopenharmony_ci   the true story, the backend must supply an initial state that uses
255da0c48c4Sopenharmony_ci   "same_value" rules for all the callee-saves registers.
256da0c48c4Sopenharmony_ci
257da0c48c4Sopenharmony_ci   This can fill in the initial_instructions, initial_instructions_end
258da0c48c4Sopenharmony_ci   members of *ABI_INFO to point at a CFI instruction stream to process
259da0c48c4Sopenharmony_ci   before each CIE's initial instructions.  It should set the
260da0c48c4Sopenharmony_ci   data_alignment_factor member if it affects the initial instructions.
261da0c48c4Sopenharmony_ci
262da0c48c4Sopenharmony_ci   The callback should not use the register rules DW_CFA_expression or
263da0c48c4Sopenharmony_ci   DW_CFA_val_expression.  Defining the CFA using DW_CFA_def_cfa_expression
264da0c48c4Sopenharmony_ci   is allowed.  This is an implementation detail since register rules
265da0c48c4Sopenharmony_ci   store expressions as offsets from the .eh_frame or .debug_frame data.
266da0c48c4Sopenharmony_ci
267da0c48c4Sopenharmony_ci   As a shorthand for some common cases, for this instruction stream
268da0c48c4Sopenharmony_ci   we overload some CFI instructions that cannot be used in a CIE:
269da0c48c4Sopenharmony_ci
270da0c48c4Sopenharmony_ci	DW_CFA_restore		-- Change default rule for all unmentioned
271da0c48c4Sopenharmony_ci				   registers from undefined to same_value.
272da0c48c4Sopenharmony_ci
273da0c48c4Sopenharmony_ci   This function can also fill in ABI_INFO->return_address_register with the
274da0c48c4Sopenharmony_ci   DWARF register number that identifies the actual PC in machine state.
275da0c48c4Sopenharmony_ci   If there is no canonical DWARF register number with that meaning, it's
276da0c48c4Sopenharmony_ci   left unchanged (callers usually initialize with (Dwarf_Word) -1).
277da0c48c4Sopenharmony_ci   This value is not used by CFI per se.
278da0c48c4Sopenharmony_ci
279da0c48c4Sopenharmony_ci   Function returns 0 on success and -1 for error or unsupported by the
280da0c48c4Sopenharmony_ci   backend.  */
281da0c48c4Sopenharmony_ciextern int ebl_abi_cfi (Ebl *ebl, Dwarf_CIE *abi_info)
282da0c48c4Sopenharmony_ci  __nonnull_attribute__ (2);
283da0c48c4Sopenharmony_ci
284da0c48c4Sopenharmony_ci/* Register map info. */
285da0c48c4Sopenharmony_citypedef struct
286da0c48c4Sopenharmony_ci{
287da0c48c4Sopenharmony_ci  Dwarf_Half offset;		/* Byte offset in register data block.  */
288da0c48c4Sopenharmony_ci  Dwarf_Half regno;		/* DWARF register number.  */
289da0c48c4Sopenharmony_ci  uint8_t bits;			/* Bits of data for one register.  */
290da0c48c4Sopenharmony_ci  uint8_t pad;			/* Bytes of padding after register's data.  */
291da0c48c4Sopenharmony_ci  Dwarf_Half count;		/* Consecutive register numbers here.  */
292da0c48c4Sopenharmony_ci  bool pc_register;
293da0c48c4Sopenharmony_ci} Ebl_Register_Location;
294da0c48c4Sopenharmony_ci
295da0c48c4Sopenharmony_ci/* Non-register data items in core notes.  */
296da0c48c4Sopenharmony_citypedef struct
297da0c48c4Sopenharmony_ci{
298da0c48c4Sopenharmony_ci  const char *name;		/* Printable identifier.  */
299da0c48c4Sopenharmony_ci  const char *group;		/* Identifier for category of related items.  */
300da0c48c4Sopenharmony_ci  Dwarf_Half offset;		/* Byte offset in note data.  */
301da0c48c4Sopenharmony_ci  Dwarf_Half count;
302da0c48c4Sopenharmony_ci  Elf_Type type;
303da0c48c4Sopenharmony_ci  char format;
304da0c48c4Sopenharmony_ci  bool thread_identifier;
305da0c48c4Sopenharmony_ci  bool pc_register;
306da0c48c4Sopenharmony_ci} Ebl_Core_Item;
307da0c48c4Sopenharmony_ci
308da0c48c4Sopenharmony_ci/* Describe the format of a core file note with the given header and NAME.
309da0c48c4Sopenharmony_ci   NAME is not guaranteed terminated, it's NHDR->n_namesz raw bytes.  */
310da0c48c4Sopenharmony_ciextern int ebl_core_note (Ebl *ebl, const GElf_Nhdr *nhdr,
311da0c48c4Sopenharmony_ci			  const char *name, const char *desc,
312da0c48c4Sopenharmony_ci			  GElf_Word *regs_offset, size_t *nregloc,
313da0c48c4Sopenharmony_ci			  const Ebl_Register_Location **reglocs,
314da0c48c4Sopenharmony_ci			  size_t *nitems, const Ebl_Core_Item **items)
315da0c48c4Sopenharmony_ci  __nonnull_attribute__ (1, 2, 3, 4, 5, 6, 7, 8);
316da0c48c4Sopenharmony_ci
317da0c48c4Sopenharmony_ci/* Describe the auxv type number.  */
318da0c48c4Sopenharmony_ciextern int ebl_auxv_info (Ebl *ebl, GElf_Xword a_type,
319da0c48c4Sopenharmony_ci			  const char **name, const char **format)
320da0c48c4Sopenharmony_ci  __nonnull_attribute__ (1, 3, 4);
321da0c48c4Sopenharmony_ci
322da0c48c4Sopenharmony_ci/* Callback type for ebl_set_initial_registers_tid.
323da0c48c4Sopenharmony_ci   Register -1 is mapped to PC (if arch PC has no DWARF number).
324da0c48c4Sopenharmony_ci   If FIRSTREG is -1 then NREGS has to be 1.  */
325da0c48c4Sopenharmony_citypedef bool (ebl_tid_registers_t) (int firstreg, unsigned nregs,
326da0c48c4Sopenharmony_ci				    const Dwarf_Word *regs, void *arg)
327da0c48c4Sopenharmony_ci  __nonnull_attribute__ (3);
328da0c48c4Sopenharmony_ci
329da0c48c4Sopenharmony_ci/* Callback to fetch process data from live TID.
330da0c48c4Sopenharmony_ci   EBL architecture has to have EBL_FRAME_NREGS > 0, otherwise the
331da0c48c4Sopenharmony_ci   backend doesn't support unwinding and this function call may crash.  */
332da0c48c4Sopenharmony_ciextern bool ebl_set_initial_registers_tid (Ebl *ebl,
333da0c48c4Sopenharmony_ci					   pid_t tid,
334da0c48c4Sopenharmony_ci					   ebl_tid_registers_t *setfunc,
335da0c48c4Sopenharmony_ci					   void *arg)
336da0c48c4Sopenharmony_ci  __nonnull_attribute__ (1, 3);
337da0c48c4Sopenharmony_ci
338da0c48c4Sopenharmony_ci/* Number of registers to allocate for ebl_set_initial_registers_tid.
339da0c48c4Sopenharmony_ci   EBL architecture can unwind iff EBL_FRAME_NREGS > 0.  */
340da0c48c4Sopenharmony_ciextern size_t ebl_frame_nregs (Ebl *ebl)
341da0c48c4Sopenharmony_ci  __nonnull_attribute__ (1);
342da0c48c4Sopenharmony_ci
343da0c48c4Sopenharmony_ci/* Offset to apply to the value of the return_address_register, as
344da0c48c4Sopenharmony_ci   fetched from a Dwarf CFI.  This is used by some backends, where the
345da0c48c4Sopenharmony_ci   return_address_register actually contains the call address.  */
346da0c48c4Sopenharmony_ciextern int ebl_ra_offset (Ebl *ebl)
347da0c48c4Sopenharmony_ci  __nonnull_attribute__ (1);
348da0c48c4Sopenharmony_ci
349da0c48c4Sopenharmony_ci/* Mask to use for function symbol or unwind return addresses in case
350da0c48c4Sopenharmony_ci   the architecture adds some extra non-address bits to it.  This is
351da0c48c4Sopenharmony_ci   different from ebl_resolve_sym_value which only works for actual
352da0c48c4Sopenharmony_ci   symbol addresses (in non-ET_REL files) that might resolve to an
353da0c48c4Sopenharmony_ci   address in a different section.  ebl_func_addr_mask is called to
354da0c48c4Sopenharmony_ci   turn a given function value into the a real address or offset (the
355da0c48c4Sopenharmony_ci   original value might not be a real address).  This works for all
356da0c48c4Sopenharmony_ci   cases where an actual function address (or offset in ET_REL symbol
357da0c48c4Sopenharmony_ci   tables) is needed.  */
358da0c48c4Sopenharmony_ciextern GElf_Addr ebl_func_addr_mask (Ebl *ebl);
359da0c48c4Sopenharmony_ci
360da0c48c4Sopenharmony_ci/* Convert *REGNO as is in DWARF to a lower range suitable for
361da0c48c4Sopenharmony_ci   Dwarf_Frame->REGS indexing.  */
362da0c48c4Sopenharmony_ciextern bool ebl_dwarf_to_regno (Ebl *ebl, unsigned *regno)
363da0c48c4Sopenharmony_ci  __nonnull_attribute__ (1, 2);
364da0c48c4Sopenharmony_ci
365da0c48c4Sopenharmony_ci/* Modify PC as fetched from inferior data into valid PC.  */
366da0c48c4Sopenharmony_ciextern void ebl_normalize_pc (Ebl *ebl, Dwarf_Addr *pc)
367da0c48c4Sopenharmony_ci  __nonnull_attribute__ (1, 2);
368da0c48c4Sopenharmony_ci
369da0c48c4Sopenharmony_ci/* Callback type for ebl_unwind's parameter getfunc.  */
370da0c48c4Sopenharmony_citypedef bool (ebl_tid_registers_get_t) (int firstreg, unsigned nregs,
371da0c48c4Sopenharmony_ci					Dwarf_Word *regs, void *arg)
372da0c48c4Sopenharmony_ci  __nonnull_attribute__ (3);
373da0c48c4Sopenharmony_ci
374da0c48c4Sopenharmony_ci/* Callback type for ebl_unwind's parameter readfunc.  */
375da0c48c4Sopenharmony_citypedef bool (ebl_pid_memory_read_t) (Dwarf_Addr addr, Dwarf_Word *data,
376da0c48c4Sopenharmony_ci				      void *arg)
377da0c48c4Sopenharmony_ci  __nonnull_attribute__ (3);
378da0c48c4Sopenharmony_ci
379da0c48c4Sopenharmony_ci/* Get previous frame state for an existing frame state.  Method is called only
380da0c48c4Sopenharmony_ci   if unwinder could not find CFI for current PC.  PC is for the
381da0c48c4Sopenharmony_ci   existing frame.  SETFUNC sets register in the previous frame.  GETFUNC gets
382da0c48c4Sopenharmony_ci   register from the existing frame.  Note that GETFUNC vs. SETFUNC act on
383da0c48c4Sopenharmony_ci   a disjunct set of registers.  READFUNC reads memory.  ARG has to be passed
384da0c48c4Sopenharmony_ci   for SETFUNC, GETFUNC and READFUNC.  *SIGNAL_FRAMEP is initialized to false,
385da0c48c4Sopenharmony_ci   it can be set to true if existing frame is a signal frame.  SIGNAL_FRAMEP is
386da0c48c4Sopenharmony_ci   never NULL.  */
387da0c48c4Sopenharmony_ciextern bool ebl_unwind (Ebl *ebl, Dwarf_Addr pc, ebl_tid_registers_t *setfunc,
388da0c48c4Sopenharmony_ci			ebl_tid_registers_get_t *getfunc,
389da0c48c4Sopenharmony_ci			ebl_pid_memory_read_t *readfunc, void *arg,
390da0c48c4Sopenharmony_ci			bool *signal_framep)
391da0c48c4Sopenharmony_ci  __nonnull_attribute__ (1, 3, 4, 5, 7);
392da0c48c4Sopenharmony_ci
393da0c48c4Sopenharmony_ci/* Returns true if the value can be resolved to an address in an
394da0c48c4Sopenharmony_ci   allocated section, which will be returned in *ADDR
395da0c48c4Sopenharmony_ci   (e.g. function descriptor resolving)  */
396da0c48c4Sopenharmony_ciextern bool ebl_resolve_sym_value (Ebl *ebl, GElf_Addr *addr)
397da0c48c4Sopenharmony_ci   __nonnull_attribute__ (2);
398da0c48c4Sopenharmony_ci
399da0c48c4Sopenharmony_ci#ifdef __cplusplus
400da0c48c4Sopenharmony_ci}
401da0c48c4Sopenharmony_ci#endif
402da0c48c4Sopenharmony_ci
403da0c48c4Sopenharmony_ci#endif	/* libebl.h */
404