From 5f88edcc5b5d290a8c35fed17e0f0ff6c7a52afd Mon Sep 17 00:00:00 2001 From: Rebekah Rowe Date: Fri, 21 Jun 2019 13:47:34 -0400 Subject: [PATCH] Fixed broken lib --- src/sharedlibrary.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/sharedlibrary.cpp b/src/sharedlibrary.cpp index 3bf4b8f..6655c3f 100644 --- a/src/sharedlibrary.cpp +++ b/src/sharedlibrary.cpp @@ -43,7 +43,7 @@ void SharedLibrary::Init(std::string_view _name){ if (!init_flag) { this->name = _name; if (this->name.empty()) - throw std::logic_error("SharedLibrary: no name avaiable."); + throw std::runtime_error("SharedLibrary: no name avaiable."); Passthrough pass; pass.name = '/' + std::string(_name) + '.'; if (!dl_iterate_phdr([](struct dl_phdr_info* info, size_t, void* _pass) { @@ -58,21 +58,23 @@ void SharedLibrary::Init(std::string_view _name){ }, reinterpret_cast(&pass))) throw std::runtime_error("SharedLibrary: Unable to find loaded library"); - this->lmap = static_cast( - dlopen(path.c_str(), RTLD_NOLOAD | RTLD_NOW | RTLD_LOCAL)); - if (const char* error = dlerror()) - throw std::runtime_error("SharedLibrary recieved dlerror: + error"); - this->path = pass.path; this->_begin = pass.begin; this->_end = mem::Offset(pass.begin, pass.size); this->_size = pass.size; + + this->lmap = static_cast(dlopen(this->path.c_str(), RTLD_NOLOAD)); + if (const char* error = dlerror()) + throw std::runtime_error("SharedLibrary recieved dlerror: " + std::string(error)); + this->init_flag = true; } } void SharedLibrary::ForceInit(std::string_view _name) { while(!this->init_flag) { - this->Init(); + try { + this->Init(); + } catch(...) {} } } std::string_view SharedLibrary::GetName() { @@ -100,7 +102,10 @@ void SharedLibrary::Clear(){ } void* SharedLibrary::GetSymInternal(SymStr name) { #if defined(__linux__) - return dlsym(this->GetLMap(), name); + void* symbol = dlsym(this->GetLMap(), name); + if (const char* error = dlerror()) + throw std::runtime_error("SharedLibrary recieved dlerror: " + std::string(error)); + return symbol; #elif defined(_WIN32) return GetProcAddress(this->GetLMap(), name); #endif