Blame libasm/libasm.h

Packit 032894
/* Interface for libasm.
Packit 032894
   Copyright (C) 2002, 2005, 2008 Red Hat, Inc.
Packit 032894
   This file is part of elfutils.
Packit 032894
Packit 032894
   This file is free software; you can redistribute it and/or modify
Packit 032894
   it under the terms of either
Packit 032894
Packit 032894
     * the GNU Lesser General Public License as published by the Free
Packit 032894
       Software Foundation; either version 3 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or
Packit 032894
Packit 032894
     * the GNU General Public License as published by the Free
Packit 032894
       Software Foundation; either version 2 of the License, or (at
Packit 032894
       your option) any later version
Packit 032894
Packit 032894
   or both in parallel, as here.
Packit 032894
Packit 032894
   elfutils is distributed in the hope that it will be useful, but
Packit 032894
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 032894
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 032894
   General Public License for more details.
Packit 032894
Packit 032894
   You should have received copies of the GNU General Public License and
Packit 032894
   the GNU Lesser General Public License along with this program.  If
Packit 032894
   not, see <http://www.gnu.org/licenses/>.  */
Packit 032894
Packit 032894
#ifndef _LIBASM_H
Packit 032894
#define _LIBASM_H 1
Packit 032894
Packit 032894
#include <stdbool.h>
Packit 032894
#include <stdint.h>
Packit 032894
Packit Service 35cfd5
typedef struct ebl Ebl;
Packit 032894
Packit 032894
Packit 032894
/* Opaque type for the assembler context descriptor.  */
Packit 032894
typedef struct AsmCtx AsmCtx_t;
Packit 032894
Packit 032894
/* Opaque type for a section.  */
Packit 032894
typedef struct AsmScn AsmScn_t;
Packit 032894
Packit 032894
/* Opaque type for a section group.  */
Packit 032894
typedef struct AsmScnGrp AsmScnGrp_t;
Packit 032894
Packit 032894
/* Opaque type for a symbol.  */
Packit 032894
typedef struct AsmSym AsmSym_t;
Packit 032894
Packit 032894
Packit 032894
/* Opaque type for the disassembler context descriptor.  */
Packit 032894
typedef struct DisasmCtx DisasmCtx_t;
Packit 032894
Packit 032894
/* Type used for callback functions to retrieve symbol name.  The
Packit 032894
   symbol reference is in the section designated by the second parameter
Packit 032894
   at an offset described by the first parameter.  The value is the
Packit 032894
   third parameter.  */
Packit 032894
typedef int (*DisasmGetSymCB_t) (GElf_Addr, Elf32_Word, GElf_Addr, char **,
Packit 032894
				 size_t *, void *);
Packit 032894
Packit 032894
/* Output function callback.  */
Packit 032894
typedef int (*DisasmOutputCB_t) (char *, size_t, void *);
Packit 032894
Packit 032894
Packit 032894
#ifdef __cplusplus
Packit 032894
extern "C" {
Packit 032894
#endif
Packit 032894
Packit 032894
/* Create output file and return descriptor for assembler context.  If
Packit 032894
   TEXTP is true the output is an assembler format text file.
Packit 032894
   Otherwise an object file is created.  The MACHINE parameter
Packit 032894
   corresponds to an EM_ constant from <elf.h>, KLASS specifies the
Packit 032894
   class (32- or 64-bit), and DATA specifies the byte order (little or
Packit 032894
   big endian).  */
Packit 032894
extern AsmCtx_t *asm_begin (const char *fname, Ebl *ebl, bool textp);
Packit 032894
Packit 032894
/* Abort the operation on the assembler context and free all resources.  */
Packit 032894
extern int asm_abort (AsmCtx_t *ctx);
Packit 032894
Packit 032894
/* Finalize output file and free all resources.  */
Packit 032894
extern int asm_end (AsmCtx_t *ctx);
Packit 032894
Packit 032894
Packit 032894
/* Return handle for the named section.  If it was not used before
Packit 032894
   create it.  */
Packit 032894
extern AsmScn_t *asm_newscn (AsmCtx_t *ctx, const char *scnname,
Packit 032894
			     GElf_Word type, GElf_Xword flags);
Packit 032894
Packit 032894
Packit 032894
/* Similar to 'asm_newscn', but make it part of section group GRP.  */
Packit 032894
extern AsmScn_t *asm_newscn_ingrp (AsmCtx_t *ctx, const char *scnname,
Packit 032894
				   GElf_Word type, GElf_Xword flags,
Packit 032894
				   AsmScnGrp_t *grp);
Packit 032894
Packit 032894
/* Create new subsection NR in the given section.  */
Packit 032894
extern AsmScn_t *asm_newsubscn (AsmScn_t *asmscn, unsigned int nr);
Packit 032894
Packit 032894
Packit 032894
/* Return handle for new section group.  The signature symbol can be
Packit 032894
   set later.  */
Packit 032894
extern AsmScnGrp_t *asm_newscngrp (AsmCtx_t *ctx, const char *grpname,
Packit 032894
				   AsmSym_t *signature, Elf32_Word flags);
Packit 032894
Packit 032894
/* Set or overwrite signature symbol for group.  */
Packit 032894
extern int asm_scngrp_newsignature (AsmScnGrp_t *grp, AsmSym_t *signature);
Packit 032894
Packit 032894
Packit 032894
/* Add zero terminated string STR of size LEN to (sub)section ASMSCN.  */
Packit 032894
extern int asm_addstrz (AsmScn_t *asmscn, const char *str, size_t len);
Packit 032894
Packit 032894
/* Add 8-bit signed integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_addint8 (AsmScn_t *asmscn, int8_t num);
Packit 032894
Packit 032894
/* Add 8-bit unsigned integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_adduint8 (AsmScn_t *asmscn, uint8_t num);
Packit 032894
Packit 032894
/* Add 16-bit signed integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_addint16 (AsmScn_t *asmscn, int16_t num);
Packit 032894
Packit 032894
/* Add 16-bit unsigned integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_adduint16 (AsmScn_t *asmscn, uint16_t num);
Packit 032894
Packit 032894
/* Add 32-bit signed integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_addint32 (AsmScn_t *asmscn, int32_t num);
Packit 032894
Packit 032894
/* Add 32-bit unsigned integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_adduint32 (AsmScn_t *asmscn, uint32_t num);
Packit 032894
Packit 032894
/* Add 64-bit signed integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_addint64 (AsmScn_t *asmscn, int64_t num);
Packit 032894
Packit 032894
/* Add 64-bit unsigned integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_adduint64 (AsmScn_t *asmscn, uint64_t num);
Packit 032894
Packit 032894
Packit 032894
/* Add signed little endian base 128 integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_addsleb128 (AsmScn_t *asmscn, int32_t num);
Packit 032894
Packit 032894
/* Add unsigned little endian base 128 integer NUM to (sub)section ASMSCN.  */
Packit 032894
extern int asm_adduleb128 (AsmScn_t *asmscn, uint32_t num);
Packit 032894
Packit 032894
Packit 032894
/* Define new symbol NAME for current position in given section ASMSCN.  */
Packit 032894
extern AsmSym_t *asm_newsym (AsmScn_t *asmscn, const char *name,
Packit 032894
			     GElf_Xword size, int type, int binding);
Packit 032894
Packit 032894
Packit 032894
/* Define new common symbol NAME with given SIZE and alignment.  */
Packit 032894
extern AsmSym_t *asm_newcomsym (AsmCtx_t *ctx, const char *name,
Packit 032894
				GElf_Xword size, GElf_Addr align);
Packit 032894
Packit 032894
/* Define new common symbol NAME with given SIZE, VALUE, TYPE, and BINDING.  */
Packit 032894
extern AsmSym_t *asm_newabssym (AsmCtx_t *ctx, const char *name,
Packit 032894
				GElf_Xword size, GElf_Addr value,
Packit 032894
				int type, int binding);
Packit 032894
Packit 032894
Packit 032894
/* Align (sub)section offset according to VALUE.  */
Packit 032894
extern int asm_align (AsmScn_t *asmscn, GElf_Word value);
Packit 032894
Packit 032894
/* Set the byte pattern used to fill gaps created by alignment.  */
Packit 032894
extern int asm_fill (AsmScn_t *asmscn, void *bytes, size_t len);
Packit 032894
Packit 032894
Packit 032894
/* Return ELF descriptor created for the output file of the given context.  */
Packit 032894
extern Elf *asm_getelf (AsmCtx_t *ctx);
Packit 032894
Packit 032894
Packit 032894
/* Return error code of last failing function call.  This value is kept
Packit 032894
   separately for each thread.  */
Packit 032894
extern int asm_errno (void);
Packit 032894
Packit 032894
/* Return error string for ERROR.  If ERROR is zero, return error string
Packit 032894
   for most recent error or NULL is none occurred.  If ERROR is -1 the
Packit 032894
   behaviour is similar to the last case except that not NULL but a legal
Packit 032894
   string is returned.  */
Packit 032894
extern const char *asm_errmsg (int __error);
Packit 032894
Packit 032894
Packit 032894
/* Create context descriptor for disassembler.  */
Packit 032894
extern DisasmCtx_t *disasm_begin (Ebl *ebl, Elf *elf, DisasmGetSymCB_t symcb);
Packit 032894
Packit 032894
/* Release descriptor for disassembler.  */
Packit 032894
extern int disasm_end (DisasmCtx_t *ctx);
Packit 032894
Packit 032894
/* Produce of disassembly output for given memory, store text in
Packit 032894
   provided buffer.  */
Packit 032894
extern int disasm_str (DisasmCtx_t *ctx, const uint8_t **startp,
Packit 032894
		       const uint8_t *end, GElf_Addr addr, const char *fmt,
Packit 032894
		       char **bufp, size_t len, void *symcbarg);
Packit 032894
Packit 032894
/* Produce disassembly output for given memory and output it using the
Packit 032894
   given callback functions.  */
Packit 032894
extern int disasm_cb (DisasmCtx_t *ctx, const uint8_t **startp,
Packit 032894
		      const uint8_t *end, GElf_Addr addr, const char *fmt,
Packit 032894
		      DisasmOutputCB_t outcb, void *outcbarg, void *symcbarg);
Packit 032894
Packit 032894
#ifdef __cplusplus
Packit 032894
}
Packit 032894
#endif
Packit 032894
Packit 032894
#endif	/* libasm.h */