dynamic-dso/dynso.h

51 lines
1.7 KiB
C

#ifndef DYNSO_H_
#define DYNSO_H_
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* for Lmid_t */
#endif
#include <dlfcn.h>
#include <link.h>
struct dynso_lib;
enum dynso_err {
dynso_ok = 0,
dynso_argument, // invalid argument
dynso_oom, // out-of-memory
dynso_bound, // the library is already bound
dynso_removed, // the library is already removed
dynso_ldso_not_found, // can't find ld.so in link map
//dynso_ldso_not_elf, // ld.so is not an ELF file, somehow
//dynso_ldso_cant_open, // can't open ld.so for reading
dynso_ldso_ioerr, // IO error whie parsing ld.so
dynso_ldso_stripped, // ld.so is stripped
dysno_ldso_no_symtab, // can't find ld.so's symbol table
dynso_no_ldso_syms, // can't resolve ld.so-internal symbols
dynso_no_newobj, // can't create a new symbol
dynso_no_priv2, // can't find the offset of the priv2 part of a struct link_map
dynso_no_priv3, // can't find the offset of the priv3 part of a struct link_map
};
// create a library
enum dynso_err dynso_create(struct dynso_lib** l, size_t address, /* leave at 0 unless you know what you're doing */
char* realname, const char* libname, struct link_map* owner,
Lmid_t ns); // owner can be NULL. if so, the main executable will be used (_r_debug.r_map)
// add a symbol to a not-yet-bound library
enum dynso_err dynso_add_sym_ex(struct dynso_lib* l, const char* name, void* value, int type, size_t size);
inline static enum dynso_err dynso_add_sym(struct dynso_lib* l, const char* name, void* value) {
return dynso_add_sym_ex(l, name, value, 0, 0);
}
// bind the library to the runtime. will perform hacks!
enum dynso_err dynso_bind(struct dynso_lib* l);
// remove the library from places. it'll be useless after this
void dynso_remove(struct dynso_lib* l);
#endif