1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:37:34 +00:00

LibC+LibELF: Implement dladdr()

This implements the dladdr() function which lets the caller look up
the symbol name, symbol address as well as library name and library
base address for an arbitrary address.
This commit is contained in:
Gunnar Beutner 2021-06-06 17:40:11 +02:00 committed by Andreas Kling
parent f82aa87d14
commit 89a38b72b7
5 changed files with 73 additions and 0 deletions

View file

@ -60,3 +60,15 @@ void* dlsym(void* handle, const char* symbol_name)
}
return result.value();
}
int dladdr(void* addr, Dl_info* info)
{
auto result = __dladdr(addr, info);
if (result.is_error()) {
// FIXME: According to the man page glibc does _not_ make the error
// available via dlerror(), however we do. Does this break anything?
store_error(result.error().text);
return 0;
}
return 1;
}

View file

@ -16,9 +16,17 @@ __BEGIN_DECLS
#define RTLD_GLOBAL 8
#define RTLD_LOCAL 16
typedef struct __Dl_info {
const char* dli_fname;
void* dli_fbase;
const char* dli_sname;
void* dli_saddr;
} Dl_info;
int dlclose(void*);
char* dlerror();
void* dlopen(const char*, int);
void* dlsym(void*, const char*);
int dladdr(void*, Dl_info*);
__END_DECLS

View file

@ -23,12 +23,17 @@ struct DlErrorMessage {
String text;
};
struct __Dl_info;
typedef struct __Dl_info Dl_info;
typedef Result<void, DlErrorMessage> (*DlCloseFunction)(void*);
typedef Result<void*, DlErrorMessage> (*DlOpenFunction)(const char*, int);
typedef Result<void*, DlErrorMessage> (*DlSymFunction)(void*, const char*);
typedef Result<void, DlErrorMessage> (*DlAddrFunction)(void*, Dl_info*);
extern "C" {
extern DlCloseFunction __dlclose;
extern DlOpenFunction __dlopen;
extern DlSymFunction __dlsym;
extern DlAddrFunction __dladdr;
}