2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "DynamicBackendUtils.hpp"
11 void* DynamicBackendUtils::OpenHandle(const std::string& sharedObjectPath)
13 if (sharedObjectPath.empty())
15 throw RuntimeException("OpenHandle error: shared object path must not be empty");
18 void* sharedObjectHandle = dlopen(sharedObjectPath.c_str(), RTLD_LAZY | RTLD_GLOBAL);
19 if (!sharedObjectHandle)
21 throw RuntimeException(boost::str(boost::format("OpenHandle error: %1%") % GetDlError()));
24 return sharedObjectHandle;
27 void DynamicBackendUtils::CloseHandle(const void* sharedObjectHandle)
29 if (!sharedObjectHandle)
34 dlclose(const_cast<void*>(sharedObjectHandle));
37 std::string DynamicBackendUtils::GetDlError()
39 const char* errorMessage = dlerror();
45 return std::string(errorMessage);