26 #if defined(__linux__)
42 #define LIB_DEFAULT ((void *) 0)
45 namespace jau::os::impl {
51 void*
const m_lib_default;
52 void*
const m_lib_next;
54 int const m_flag_lazy;
56 int const m_flag_local;
57 int const m_flag_global;
60 UnixDynamicLinker(
void*
const lib_default,
void*
const lib_next,
61 int const flag_lazy,
int const flag_now,
int const flag_local,
int const flag_global)
62 : m_lib_default(lib_default), m_lib_next(lib_next),
63 m_flag_lazy(flag_lazy), m_flag_now(flag_now), m_flag_local(flag_local), m_flag_global(flag_global)
69 libhandle_t openLibraryGlobalImpl(
const std::string& pathname)
noexcept override {
70 return ::dlopen((
char *) pathname.c_str(), m_flag_lazy | m_flag_global);
73 libhandle_t openLibraryLocalImpl(
const std::string& pathname)
noexcept override {
74 return ::dlopen((
char *) pathname.c_str(), m_flag_lazy | m_flag_local);
77 const char* lookupLibraryPathnameImpl(
libhandle_t handle,
const std::string& symbolName)
noexcept override {
78 if(
nullptr != handle && symbolName.length() > 0 ) {
79 symhandle_t addr = ::dlsym(handle, symbolName.c_str());
80 if(
nullptr != addr ) {
82 if( 0 != ::dladdr(addr, &info) ) {
83 return info.dli_fname;
92 symhandle_t lookupSymbolGlobalImpl(
const std::string& symbolName)
noexcept override {
93 return ::dlsym(m_lib_default, symbolName.c_str());
97 if(
nullptr != handle ) {
98 return ::dlsym(handle, symbolName.c_str());
104 void closeLibraryImpl(
libhandle_t handle)
noexcept override {
105 if(
nullptr != handle ) {
110 std::string getLastErrorImpl()
noexcept override {
111 const char * res = ::dlerror();
112 if(
nullptr != res ) {
113 return std::string(res);
115 return std::string();
123 class PosixDynamicLinker :
public UnixDynamicLinker {
125 constexpr static void*
const LIB_DEFAULT =
nullptr;
126 inline static void*
const LIB_NEXT =
reinterpret_cast<void *
>( -1l );
128 constexpr static int const FLAG_LAZY = 0x00001;
129 constexpr static int const FLAG_NOW = 0x00002;
130 constexpr static int const FLAG_LOCAL = 0x00000;
131 constexpr static int const FLAG_GLOBAL = 0x00100;
134 PosixDynamicLinker() noexcept
135 : UnixDynamicLinker(
LIB_DEFAULT, LIB_NEXT, FLAG_LAZY, FLAG_NOW, FLAG_LOCAL, FLAG_GLOBAL) {}
141 class DarwinDynamicLinker :
public UnixDynamicLinker {
143 inline static void*
const LIB_DEFAULT =
reinterpret_cast<void *
>( -2l );
144 inline static void*
const LIB_NEXT =
reinterpret_cast<void *
>( -1l );
146 constexpr static int const FLAG_LAZY = 0x00001;
147 constexpr static int const FLAG_NOW = 0x00002;
148 constexpr static int const FLAG_LOCAL = 0x00004;
149 constexpr static int const FLAG_GLOBAL = 0x00008;
152 DarwinDynamicLinker() noexcept
153 : UnixDynamicLinker(
LIB_DEFAULT, LIB_NEXT, FLAG_LAZY, FLAG_NOW, FLAG_LOCAL, FLAG_GLOBAL) {}
161 class Bionic32DynamicLinker :
public UnixDynamicLinker {
163 inline static void*
const LIB_DEFAULT =
reinterpret_cast<void *
>( 0xfffffffful );
164 inline static void*
const LIB_NEXT =
reinterpret_cast<void *
>( 0xfffffffeul );
166 constexpr static int const FLAG_LAZY = 0x00001;
167 constexpr static int const FLAG_NOW = 0x00000;
168 constexpr static int const FLAG_LOCAL = 0x00000;
169 constexpr static int const FLAG_GLOBAL = 0x00002;
173 Bionic32DynamicLinker() noexcept
174 : UnixDynamicLinker(
LIB_DEFAULT, LIB_NEXT, FLAG_LAZY, FLAG_NOW, FLAG_LOCAL, FLAG_GLOBAL) {}
180 return new jau::os::impl::Bionic32DynamicLinker();
182 return new jau::os::impl::DarwinDynamicLinker();
184 return new jau::os::impl::PosixDynamicLinker();
Low level secure dynamic linker access.
void * symhandle_t
symbol handle within a library
void * libhandle_t
library handle
constexpr bool is_darwin() noexcept
Evaluates true if platform os_type::native contains os_type::Darwin.
constexpr bool is_android() noexcept
Evaluates true if platform os_type::native contains os_type::Android.
constexpr size_t pointer_bit_size() noexcept
Returns the compile time pointer architecture size in bits.
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2024 Gothel Software e.K.
#define LIB_DEFAULT
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2024 Gothel Software e.K.