libdragon
Loading...
Searching...
No Matches
dlfcn.h
Go to the documentation of this file.
1
6#ifndef __LIBDRAGON_DLFCN_H
7#define __LIBDRAGON_DLFCN_H
8
10#define RTLD_LAZY 0x0
12#define RTLD_NOW 0x0
14#define RTLD_GLOBAL 0x1
16#define RTLD_LOCAL 0x0
18#define RTLD_NODELETE 0x2
20#define RTLD_NOLOAD 0x4
21
23#define RTLD_DEFAULT ((void *)-1)
25#define RTLD_NEXT ((void *)-2)
26
28typedef struct {
30 const char *dli_fname;
32 void *dli_fbase;
34 const char *dli_sname;
36 void *dli_saddr;
37} Dl_info;
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43// Embedded GDB script to auto-load DSO symbols
44#ifndef N64_DSO
46asm(
47".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
48".byte 4\n"
49".ascii \"gdb.inlined-script-dso-autoload\\n\"\n"
50".ascii \"import gdb\\n\"\n"
51".ascii \"class BreakpointDsoLoad(gdb.Breakpoint):\\n\"\n"
52".ascii \" def stop(self):\\n\"\n"
53".ascii \" frame = gdb.selected_frame()\\n\"\n"
54".ascii \" src_elf = gdb.execute('printf \\\"%s\\\", module->src_elf', False, True)\\n\"\n"
55".ascii \" prog_base = int(gdb.execute('printf \\\"%x\\\", module->prog_base', False, True), 16)\\n\"\n"
56".ascii \" print(\\\"Loading overlay: \\\", src_elf, \\\"(text:\\\", hex(prog_base), \\\")\\\")\\n\"\n"
57".ascii \" gdb.execute(\\\"add-symbol-file -readnow \\\" + src_elf + \\\" \\\" + hex(prog_base), False, True)\\n\"\n"
58".ascii \" return False\\n\"\n"
59".ascii \"class BreakpointDsoFree(gdb.Breakpoint):\\n\"\n"
60".ascii \" def stop(self):\\n\"\n"
61".ascii \" frame = gdb.selected_frame()\\n\"\n"
62".ascii \" src_elf = gdb.execute('printf \\\"%s\\\", module->src_elf', False, True)\\n\"\n"
63".ascii \" prog_base = int(gdb.execute('printf \\\"%x\\\", module->prog_base', False, True), 16)\\n\"\n"
64".ascii \" print(\\\"Unloading overlay: \\\", src_elf, \\\"(text:\\\", hex(prog_base), \\\")\\\")\\n\"\n"
65".ascii \" gdb.execute(\\\"remove-symbol-file -a \\\" + hex(prog_base), False, True)\\n\"\n"
66".ascii \" return False\\n\"\n"
67".ascii \"bp_load = BreakpointDsoLoad(\\\"__dl_insert_module\\\")\\n\"\n"
68".ascii \"bp_load.silent = True\\n\"\n"
69".ascii \"bl_free = BreakpointDsoFree(\\\"__dl_remove_module\\\")\\n\"\n"
70".ascii \"bl_free.silent = True\\n\"\n"
71".byte 0\n"
72".popsection\n"
73);
75#endif
76
84void *dlopen(const char *filename, int mode);
85
93void *dlsym(void *handle, const char *symbol);
94
101int dlclose(void *handle);
102
110int dladdr(const void *addr, Dl_info *info);
111
117char *dlerror(void);
118
119#ifdef __cplusplus
120}
121#endif
122
123#endif
void * dli_saddr
Exact address of symbol named in dli_sname.
Definition dlfcn.h:36
const char * dli_sname
Name of symbol whose definition overlaps addr.
Definition dlfcn.h:34
const char * dli_fname
Pathname of shared object that contains address.
Definition dlfcn.h:30
void * dli_fbase
Base address at which shared object is loaded.
Definition dlfcn.h:32
dl_addr info structure
Definition dlfcn.h:28
void * dlopen(const char *filename, int mode)
Open dynamic library.
Definition dlfcn.c:401
char * dlerror(void)
Return last error that occurred in dynamic linker.
Definition dlfcn.c:630
void * dlsym(void *handle, const char *symbol)
Grab symbol from loaded dynamic library.
Definition dlfcn.c:466
int dladdr(const void *addr, Dl_info *info)
Convert address to symbol.
Definition dlfcn.c:595
int dlclose(void *handle)
Close loaded dynamic library.
Definition dlfcn.c:569