8 #include <botan/dyn_load.h>
9 #include <botan/build.h>
10 #include <botan/exceptn.h>
12 #if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
14 #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
23 void raise_runtime_loader_exception(
const std::string& lib_name,
26 throw Exception(
"Failed to load " + lib_name +
": " +
27 (msg ? msg :
"Unknown error"));
33 const std::string& library) :
34 m_lib_name(library), m_lib(nullptr)
36 #if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
37 m_lib = ::dlopen(m_lib_name.c_str(), RTLD_LAZY);
40 raise_runtime_loader_exception(m_lib_name, dlerror());
42 #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
43 m_lib = ::LoadLibraryA(m_lib_name.c_str());
46 raise_runtime_loader_exception(m_lib_name,
"LoadLibrary failed");
50 raise_runtime_loader_exception(m_lib_name,
"Dynamic load not supported");
55 #if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
57 #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
58 ::FreeLibrary((HMODULE)m_lib);
66 #if defined(BOTAN_TARGET_OS_HAS_DLOPEN)
67 addr = ::dlsym(m_lib, symbol.c_str());
68 #elif defined(BOTAN_TARGET_OS_HAS_LOADLIBRARY)
69 addr =
reinterpret_cast<void*
>(::GetProcAddress((HMODULE)m_lib,
74 throw Exception(
"Failed to resolve symbol " + symbol +
Dynamically_Loaded_Library(const std::string &lib_name)
~Dynamically_Loaded_Library()
void * resolve_symbol(const std::string &symbol)