2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_SYMBOLS_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_SYMBOLS_H_
|
2022-08-11 19:13:18 +00:00
|
|
|
#include "libc/intrin/bits.h"
|
2020-10-11 04:18:53 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
2020-06-15 14:18:57 +00:00
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
2022-03-23 13:31:55 +00:00
|
|
|
#define SYMBOLS_MAGIC READ32LE("SYMT")
|
|
|
|
#define SYMBOLS_ABI 1
|
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
struct Symbol {
|
2021-09-28 05:58:51 +00:00
|
|
|
unsigned x; /* start (relative to addr_base) */
|
|
|
|
unsigned y; /* start + size - 1 (inclusive) */
|
2020-06-15 14:18:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SymbolTable {
|
2022-03-23 13:31:55 +00:00
|
|
|
uint32_t magic; /* 0xFEEDABEE little endian */
|
|
|
|
uint32_t abi; /* 1 */
|
|
|
|
uint64_t count; /* of `symbols` */
|
|
|
|
uint64_t size; /* file size */
|
|
|
|
uint64_t mapsize; /* of this object */
|
|
|
|
int64_t addr_base; /* IMAGE_BASE_VIRTUAL */
|
|
|
|
int64_t addr_end; /* _end - 1 */
|
|
|
|
uint32_t *names; /* relative to `name_base` */
|
|
|
|
char *name_base; /* double-nul terminated w/ empty first */
|
|
|
|
uint32_t names_offset; /* for file loading */
|
|
|
|
uint32_t name_base_offset; /* for file loading */
|
|
|
|
struct Symbol symbols[]; /* sorted and non-overlapping intervals */
|
2020-06-15 14:18:57 +00:00
|
|
|
};
|
|
|
|
|
2020-10-11 04:18:53 +00:00
|
|
|
struct SymbolTable *GetSymbolTable(void);
|
|
|
|
const char *FindComBinary(void);
|
|
|
|
const char *FindDebugBinary(void);
|
2021-10-04 10:23:31 +00:00
|
|
|
struct SymbolTable *OpenSymbolTable(const char *);
|
2020-10-11 04:18:53 +00:00
|
|
|
int CloseSymbolTable(struct SymbolTable **);
|
2021-10-08 15:11:51 +00:00
|
|
|
int __hook(void *, struct SymbolTable *);
|
2021-10-14 00:27:13 +00:00
|
|
|
int __get_symbol(struct SymbolTable *, intptr_t);
|
|
|
|
char *__get_symbol_name(struct SymbolTable *, int);
|
2021-09-28 05:58:51 +00:00
|
|
|
|
2020-06-15 14:18:57 +00:00
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_SYMBOLS_H_ */
|