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
commit 89a38b72b7
Notes: sideshowbarker 2024-07-18 12:43:58 +09:00
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;
}