github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/include/jit/jit-elf.h (about) 1 /* 2 * <jit/jit-elf.h> - Routines to read and write ELF-format binaries. 3 * 4 * Copyright (C) 2004 Southern Storm Software, Pty Ltd. 5 * 6 * The libjit library is free software: you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation, either version 2.1 of 9 * the License, or (at your option) any later version. 10 * 11 * The libjit library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with the libjit library. If not, see 18 * <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef _JIT_ELF_H 22 #define _JIT_ELF_H 23 24 #include <jit/jit-common.h> 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* 31 * Opaque types that represent a loaded ELF binary in read or write mode. 32 */ 33 typedef struct jit_readelf *jit_readelf_t; 34 typedef struct jit_writeelf *jit_writeelf_t; 35 36 /* 37 * Flags for "jit_readelf_open". 38 */ 39 #define JIT_READELF_FLAG_FORCE (1 << 0) /* Force file to load */ 40 #define JIT_READELF_FLAG_DEBUG (1 << 1) /* Print debugging information */ 41 42 /* 43 * Result codes from "jit_readelf_open". 44 */ 45 #define JIT_READELF_OK 0 /* File was opened successfully */ 46 #define JIT_READELF_CANNOT_OPEN 1 /* Could not open the file */ 47 #define JIT_READELF_NOT_ELF 2 /* Not an ELF-format binary */ 48 #define JIT_READELF_WRONG_ARCH 3 /* Wrong architecture for local system */ 49 #define JIT_READELF_BAD_FORMAT 4 /* ELF file, but badly formatted */ 50 #define JIT_READELF_MEMORY 5 /* Insufficient memory to load the file */ 51 52 /* 53 * External function declarations. 54 */ 55 int jit_readelf_open 56 (jit_readelf_t *readelf, const char *filename, int flags) JIT_NOTHROW; 57 void jit_readelf_close(jit_readelf_t readelf) JIT_NOTHROW; 58 const char *jit_readelf_get_name(jit_readelf_t readelf) JIT_NOTHROW; 59 void *jit_readelf_get_symbol 60 (jit_readelf_t readelf, const char *name) JIT_NOTHROW; 61 void *jit_readelf_get_section 62 (jit_readelf_t readelf, const char *name, jit_nuint *size) JIT_NOTHROW; 63 void *jit_readelf_get_section_by_type 64 (jit_readelf_t readelf, jit_int type, jit_nuint *size) JIT_NOTHROW; 65 void *jit_readelf_map_vaddr 66 (jit_readelf_t readelf, jit_nuint vaddr) JIT_NOTHROW; 67 unsigned int jit_readelf_num_needed(jit_readelf_t readelf) JIT_NOTHROW; 68 const char *jit_readelf_get_needed 69 (jit_readelf_t readelf, unsigned int index) JIT_NOTHROW; 70 void jit_readelf_add_to_context 71 (jit_readelf_t readelf, jit_context_t context) JIT_NOTHROW; 72 int jit_readelf_resolve_all 73 (jit_context_t context, int print_failures) JIT_NOTHROW; 74 int jit_readelf_register_symbol 75 (jit_context_t context, const char *name, 76 void *value, int after) JIT_NOTHROW; 77 78 jit_writeelf_t jit_writeelf_create(const char *library_name) JIT_NOTHROW; 79 void jit_writeelf_destroy(jit_writeelf_t writeelf) JIT_NOTHROW; 80 int jit_writeelf_write 81 (jit_writeelf_t writeelf, const char *filename) JIT_NOTHROW; 82 int jit_writeelf_add_function 83 (jit_writeelf_t writeelf, jit_function_t func, 84 const char *name) JIT_NOTHROW; 85 int jit_writeelf_add_needed 86 (jit_writeelf_t writeelf, const char *library_name) JIT_NOTHROW; 87 int jit_writeelf_write_section 88 (jit_writeelf_t writeelf, const char *name, jit_int type, 89 const void *buf, unsigned int len, int discardable) JIT_NOTHROW; 90 91 #ifdef __cplusplus 92 }; 93 #endif 94 95 #endif /* _JIT_ELF_H */