From dab63b80a8666de13d52df1ac7dfb751167fb53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20dos=20Santos=20Oliveira?= Date: Thu, 22 Aug 2024 08:10:58 -0300 Subject: [PATCH] Add constructor taking native_handle_t Calls to dlopen() will always fail on FreeBSD if ambient authority is disabled (i.e. process is in capsicum mode). For these cases, FreeBSD offers fdlopen(). The new constructor allows the user to explicitly call fdlopen() and then use Boost.DLL to manage the loaded plugin. Android's libc (Bionic) also has fdlopen(), but under a different name: android_dlopen_ext(). As Linux implements a sandboxing model closer to Capsicum (that's already planned in the roadmap for the Landlock subsystem), similar restrictions will hit glibc and we might see fdlopen() in glibc as well. --- include/boost/dll/detail/posix/shared_library_impl.hpp | 4 ++++ include/boost/dll/detail/windows/shared_library_impl.hpp | 4 ++++ include/boost/dll/shared_library.hpp | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/include/boost/dll/detail/posix/shared_library_impl.hpp b/include/boost/dll/detail/posix/shared_library_impl.hpp index c8858f37..e3f12f79 100644 --- a/include/boost/dll/detail/posix/shared_library_impl.hpp +++ b/include/boost/dll/detail/posix/shared_library_impl.hpp @@ -53,6 +53,10 @@ class shared_library_impl { sl.handle_ = NULL; } + shared_library_impl(native_handle_t handle) + : handle_(handle) + {} + shared_library_impl & operator=(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT { swap(sl); return *this; diff --git a/include/boost/dll/detail/windows/shared_library_impl.hpp b/include/boost/dll/detail/windows/shared_library_impl.hpp index 865265dc..17a80728 100644 --- a/include/boost/dll/detail/windows/shared_library_impl.hpp +++ b/include/boost/dll/detail/windows/shared_library_impl.hpp @@ -45,6 +45,10 @@ class shared_library_impl { sl.handle_ = NULL; } + shared_library_impl(native_handle_t handle) + : handle_(handle) + {} + shared_library_impl & operator=(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT { swap(sl); return *this; diff --git a/include/boost/dll/shared_library.hpp b/include/boost/dll/shared_library.hpp index dd76b019..3666ca3a 100644 --- a/include/boost/dll/shared_library.hpp +++ b/include/boost/dll/shared_library.hpp @@ -137,6 +137,15 @@ class shared_library shared_library::load(lib_path, mode, ec); } + /*! + * Takes ownership of a loaded library. + * + * \param handle The native handle. + */ + explicit shared_library(native_handle_t handle) + : base_t(handle) + {} + /*! * Assignment operator. If this->is_loaded() then calls this->unload(). Does not invalidate existing symbols and functions loaded from lib. *