diff options
Diffstat (limited to 'Userland/Libraries/LibDl')
-rw-r--r-- | Userland/Libraries/LibDl/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibDl/dlfcn.cpp | 74 | ||||
-rw-r--r-- | Userland/Libraries/LibDl/dlfcn.h | 32 | ||||
-rw-r--r-- | Userland/Libraries/LibDl/dlfcn_integration.h | 40 |
4 files changed, 4 insertions, 152 deletions
diff --git a/Userland/Libraries/LibDl/CMakeLists.txt b/Userland/Libraries/LibDl/CMakeLists.txt index 16199b9388..b86c5f768e 100644 --- a/Userland/Libraries/LibDl/CMakeLists.txt +++ b/Userland/Libraries/LibDl/CMakeLists.txt @@ -1,6 +1,4 @@ -set(SOURCES - dlfcn.cpp -) - -serenity_libc(LibDl dl) -target_link_libraries(LibDl LibC) +# Provide a dummy target and a linker script that tells everything to link against LibC instead. +add_library(LibDl INTERFACE) +target_link_libraries(LibDl INTERFACE LibC) +file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libdl.so" "INPUT(libc.so)") diff --git a/Userland/Libraries/LibDl/dlfcn.cpp b/Userland/Libraries/LibDl/dlfcn.cpp deleted file mode 100644 index 076d0e17ec..0000000000 --- a/Userland/Libraries/LibDl/dlfcn.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2021, Gunnar Beutner <gunnar@beutner.name> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <AK/String.h> -#include <AK/Types.h> -#include <dlfcn.h> -#include <dlfcn_integration.h> -#include <string.h> - -// FIXME: use thread_local and a String once TLS works -__thread char* s_dlerror_text = NULL; -__thread bool s_dlerror_retrieved = false; - -static void store_error(String const& error) -{ - free(s_dlerror_text); - s_dlerror_text = strdup(error.characters()); - s_dlerror_retrieved = false; -} - -int dlclose(void* handle) -{ - auto result = __dlclose(handle); - if (result.is_error()) { - store_error(result.error().text); - return -1; - } - return 0; -} - -char* dlerror() -{ - if (s_dlerror_retrieved) { - free(s_dlerror_text); - s_dlerror_text = nullptr; - } - s_dlerror_retrieved = true; - return const_cast<char*>(s_dlerror_text); -} - -void* dlopen(char const* filename, int flags) -{ - auto result = __dlopen(filename, flags); - if (result.is_error()) { - store_error(result.error().text); - return nullptr; - } - return result.value(); -} - -void* dlsym(void* handle, char const* symbol_name) -{ - auto result = __dlsym(handle, symbol_name); - if (result.is_error()) { - store_error(result.error().text); - return nullptr; - } - 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; -} diff --git a/Userland/Libraries/LibDl/dlfcn.h b/Userland/Libraries/LibDl/dlfcn.h deleted file mode 100644 index 99f2c68e67..0000000000 --- a/Userland/Libraries/LibDl/dlfcn.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <sys/cdefs.h> - -__BEGIN_DECLS - -#define RTLD_DEFAULT 0 -#define RTLD_LAZY 2 -#define RTLD_NOW 4 -#define RTLD_GLOBAL 8 -#define RTLD_LOCAL 16 - -typedef struct __Dl_info { - char const* dli_fname; - void* dli_fbase; - char const* dli_sname; - void* dli_saddr; -} Dl_info; - -int dlclose(void*); -char* dlerror(void); -void* dlopen(char const*, int); -void* dlsym(void*, char const*); -int dladdr(void*, Dl_info*); - -__END_DECLS diff --git a/Userland/Libraries/LibDl/dlfcn_integration.h b/Userland/Libraries/LibDl/dlfcn_integration.h deleted file mode 100644 index bf5a20ae60..0000000000 --- a/Userland/Libraries/LibDl/dlfcn_integration.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021, Gunnar Beutner <gunnar@beutner.name> - * Copyright (c) 2022, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <AK/Result.h> -#include <AK/String.h> - -struct DlErrorMessage { - DlErrorMessage(String&& other) - : text(move(other)) - { - } - - // The virtual destructor is required because we're passing this - // struct to the dynamic loader - whose operator delete differs - // from the one in libc.so - virtual ~DlErrorMessage() = default; - - String text; -}; - -struct __Dl_info; -typedef struct __Dl_info Dl_info; - -typedef Result<void, DlErrorMessage> (*DlCloseFunction)(void*); -typedef Result<void*, DlErrorMessage> (*DlOpenFunction)(char const*, int); -typedef Result<void*, DlErrorMessage> (*DlSymFunction)(void*, char const*); -typedef Result<void, DlErrorMessage> (*DlAddrFunction)(void*, Dl_info*); - -extern "C" { -extern DlCloseFunction __dlclose; -extern DlOpenFunction __dlopen; -extern DlSymFunction __dlsym; -extern DlAddrFunction __dladdr; -} |