51 std::string m_libraryPath;
56 std::string m_nativeLibraryPath;
59 const std::string&
libraryPath,
const std::string& symbolName) {
64 if(
nullptr != nlp ) {
65 return std::string(nlp);
81 return m_dynLink.
lookupSymbol(m_libraryHandle, funcName);
95 bool isValid() const noexcept {
return m_nativeLibraryPath.size() > 0; }
98 bool isOpen() const noexcept {
return nullptr != m_libraryHandle; }
104 const std::string&
libraryPath() const noexcept {
return m_libraryPath; }
117 if (
nullptr != m_libraryHandle ) {
119 m_libraryHandle =
nullptr;
127 return "NativeLibrary[path[given '" + m_libraryPath +
"', native '"+m_nativeLibraryPath+
"'], 0x" +
130 return "NativeLibrary[invalid, path[given '" + m_libraryPath +
"'], 0x" +
153 const bool searchSystemPath,
154 const bool searchSystemPathFirst,
155 const bool global)
noexcept {
156 return open(libName, searchSystemPath, searchSystemPathFirst, global,
"");
181 const bool searchSystemPath,
182 const bool searchSystemPathFirst,
183 const bool global,
const std::string& symbolName)
noexcept {
189 for (
const std::string& path : paths ) {
190 DBG_PRINT(
"NativeLibrary.open(global %d): Trying to load %s", global, path.c_str());
202 DBG_PRINT(
"NativeLibrary.open: Failed to open '%s', last error %s",
206 DBG_PRINT(
"NativeLibrary.open(global %d): Did not succeed in loading: '%s' within '%s'",
208 return NativeLibrary(m_dynLink,
nullptr, libName, global, symbolName);
static environment & get(const std::string &root_prefix_domain="jau") noexcept
Static singleton initialization of this project's environment with the given global root prefix_domai...
Low level secure dynamic linker access.
static DynamicLinker & get() noexcept
Returns static singleton instance of DynamicLinker.
symhandle_t lookupSymbolGlobal(const std::string &symbolName) noexcept
static std::vector< std::string > enumerateLibraryPaths(const std::string &libName, bool searchSystemPath=false, bool searchSystemPathFirst=false) noexcept
Returns list of potential absolute library filenames.
symhandle_t lookupSymbol(libhandle_t handle, const std::string &symbolName) noexcept
void * symhandle_t
symbol handle within a library
libhandle_t openLibraryGlobal(const std::string &pathname) noexcept
Opens the named library, allowing system wide access for other users.
void * libhandle_t
library handle
const char * lookupLibraryPathname(libhandle_t handle, const std::string &symbolName) noexcept
std::string getLastError() noexcept
Returns a string containing the last error.
libhandle_t openLibraryLocal(const std::string &pathname) noexcept
Opens the named library, restricting access to this process.
void closeLibrary(libhandle_t handle) noexcept
Security checks are implicit by previous call of openLibraryLocal(const std::string_view&,...
Interface callers may use ProcAddressHelper's reset helper method to install function pointers into a...
Runtime libary dynamic library (RTLD) access.
DynamicLinker & dynamicLinker() const noexcept
Returns the used DynamicLinker reference.
bool isValid() const noexcept
Returns true if this instance is valid, i.e.
void close() noexcept
Closes this native library.
DynamicLinker::symhandle_t dynamicLookupFunctionGlobal(const std::string &funcName) const noexcept override
Returns the function handle for function funcName gathered globally within all loaded libraries.
const std::string & resolvedLibraryPath() const noexcept
Returns the resolved native path of the opened native library, might be libraryPath() if not supporte...
const std::string & libraryPath() const noexcept
Returns the path of the opened native library file.
DynamicLinker::symhandle_t dynamicLookupFunction(const std::string &funcName) const noexcept override
Returns the function handle for function funcName gathered within the associated native library.
std::string toString() const noexcept
DynamicLinker::libhandle_t libraryHandle() const noexcept
Returns the native library handle if valid and not closed, otherwise nullptr.
bool isOpen() const noexcept
Returns true if this instance isValid() and not close()'ed, otherwise false.
static NativeLibrary open(const std::string &libName, const bool searchSystemPath, const bool searchSystemPathFirst, const bool global, const std::string &symbolName) noexcept
Opens the given native library, assuming it has the same base name on all platforms.
static NativeLibrary open(const std::string &libName, const bool searchSystemPath, const bool searchSystemPathFirst, const bool global) noexcept
Opens the given native library, assuming it has the same base name on all platforms.
#define DBG_PRINT(...)
Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] De...
std::string to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
std::string to_string(const alphabet &v) noexcept
std::string to_hexstring(value_type const &v) noexcept
Produce a lower-case hexadecimal string representation of the given pointer.
Author: Sven Gothel sgothel@jausoft.com Copyright (c) 2024 Gothel Software e.K.