diff --git a/userspace/libraries/LibC/dlfcn.cpp b/userspace/libraries/LibC/dlfcn.cpp index 114b0b49..87312634 100644 --- a/userspace/libraries/LibC/dlfcn.cpp +++ b/userspace/libraries/LibC/dlfcn.cpp @@ -1,5 +1,13 @@ #include +extern "C" int __dladdr(const void*, Dl_info_t*) __attribute__((weak)); +int dladdr(const void* __restrict addr, Dl_info_t* __restrict dlip) +{ + if (&__dladdr == nullptr) [[unlikely]] + return 0; + return __dladdr(addr, dlip); +} + extern "C" int __dlclose(void*) __attribute__((weak)); int dlclose(void* handle) { diff --git a/userspace/libraries/LibC/include/dlfcn.h b/userspace/libraries/LibC/include/dlfcn.h index 274edf16..9522ecba 100644 --- a/userspace/libraries/LibC/include/dlfcn.h +++ b/userspace/libraries/LibC/include/dlfcn.h @@ -15,6 +15,18 @@ __BEGIN_DECLS #define RTLD_NEXT ((void*)-1) #define RTLD_DEFAULT ((void*) 0) +struct Dl_info +{ + const char* dli_fname; /* Pathname of mapped object file. */ + void* dli_fbase; /* Base of mapped address range. */ + const char* dli_sname; /* Sumbol name or null pointer. */ + void* dli_saddr; /* Symbol address or null pointer. */ +}; + +typedef struct Dl_info Dl_info_t; /* POSIX type */ +typedef struct Dl_info Dl_info; /* Linux type */ + +int dladdr(const void* __restrict addr, Dl_info_t* __restrict dlip); int dlclose(void* handle); char* dlerror(void); void* dlopen(const char* file, int mode);