Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
6 files changed
+15
-18
No files matched your search
@@ -2,8 +2,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
namespace vl::mod {
|
namespace vl::mod {
|
||||||
|
|
||||||
void* LoadLibrary(const std::string& path, bool isGlobal);
|
void* LoadModLibrary(const std::string& path, bool isGlobal);
|
||||||
bool CloseLibrary(void* handle);
|
bool CloseModLibrary(void* handle);
|
||||||
void* LoadSymbol(void* handle, const std::string& name);
|
void* LoadModSymbol(void* handle, const std::string& name);
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -35,7 +35,7 @@ namespace vl::Agent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vl::mod::LoadLibrary(mods.at("VoidLoaderApi.vlmod").string(), true);
|
vl::mod::LoadModLibrary(mods.at("VoidLoaderApi.vlmod").string(), true);
|
||||||
mods.erase("VoidLoaderApi.vlmod");
|
mods.erase("VoidLoaderApi.vlmod");
|
||||||
mods.erase("VoidLoader.vlmod");
|
mods.erase("VoidLoader.vlmod");
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,18 @@
|
|||||||
#if defined(unix)
|
|
||||||
|
|
||||||
#include <Mods/LoadLibrary.hpp>
|
#include <Mods/LoadLibrary.hpp>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
namespace vl::mod {
|
namespace vl::mod {
|
||||||
void* LoadLibrary(const std::string& path, bool isGlobal)
|
void* LoadModLibrary(const std::string& path, bool isGlobal)
|
||||||
{
|
{
|
||||||
dlerror();
|
dlerror();
|
||||||
return dlopen(path.c_str(), isGlobal ? RTLD_NOW | RTLD_GLOBAL : RTLD_NOW);
|
return dlopen(path.c_str(), isGlobal ? RTLD_NOW | RTLD_GLOBAL : RTLD_NOW);
|
||||||
}
|
}
|
||||||
bool CloseLibrary(void* handle)
|
bool CloseModLibrary(void* handle)
|
||||||
{
|
{
|
||||||
return dlclose(handle) == 0;
|
return dlclose(handle) == 0;
|
||||||
}
|
}
|
||||||
void* LoadSymbol(void* handle, const std::string& name)
|
void* LoadModSymbol(void* handle, const std::string& name)
|
||||||
{
|
{
|
||||||
dlerror();
|
dlerror();
|
||||||
return dlsym(handle, name.c_str());
|
return dlsym(handle, name.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
@@ -87,7 +87,7 @@ namespace vl::mod {
|
|||||||
assert(w_target_len == 0);
|
assert(w_target_len == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* LoadLibrary(const std::string& path, bool isGlobal)
|
void* LoadModLibrary(const std::string& path, bool isGlobal)
|
||||||
{
|
{
|
||||||
WCHAR filename_w[32768];
|
WCHAR filename_w[32768];
|
||||||
ssize_t r;
|
ssize_t r;
|
||||||
@@ -102,11 +102,11 @@ namespace vl::mod {
|
|||||||
|
|
||||||
return LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
return LoadLibraryExW(filename_w, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
|
||||||
}
|
}
|
||||||
bool CloseLibrary(void* handle)
|
bool CloseModLibrary(void* handle)
|
||||||
{
|
{
|
||||||
return FreeLibrary(static_cast<HMODULE>(handle)) != 0;
|
return FreeLibrary(static_cast<HMODULE>(handle)) != 0;
|
||||||
}
|
}
|
||||||
void* LoadSymbol(void* handle, const std::string& name)
|
void* LoadModSymbol(void* handle, const std::string& name)
|
||||||
{
|
{
|
||||||
return (void*)(uintptr_t) GetProcAddress(static_cast<HMODULE>(handle), name.c_str());
|
return (void*)(uintptr_t) GetProcAddress(static_cast<HMODULE>(handle), name.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,7 @@
|
|||||||
namespace vl::mod {
|
namespace vl::mod {
|
||||||
|
|
||||||
std::size_t ModLoader::loadModule(const std::string& path, const Context& ctx, bool isGlobal) {
|
std::size_t ModLoader::loadModule(const std::string& path, const Context& ctx, bool isGlobal) {
|
||||||
void* handle = LoadLibrary(path, isGlobal);
|
void* handle = LoadModLibrary(path, isGlobal);
|
||||||
if (!handle) throw std::runtime_error(std::string("dlopen failed: "));
|
if (!handle) throw std::runtime_error(std::string("dlopen failed: "));
|
||||||
handles_.push_back(handle);
|
handles_.push_back(handle);
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ void ModLoader::stopAll() {
|
|||||||
void ModLoader::unloadAll() {
|
void ModLoader::unloadAll() {
|
||||||
stopAll();
|
stopAll();
|
||||||
instances_.clear();
|
instances_.clear();
|
||||||
for (auto* h : handles_) if (h) CloseLibrary(h);
|
for (auto* h : handles_) if (h) CloseModLibrary(h);
|
||||||
handles_.clear();
|
handles_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ std::vector<Registry::Entry>& Registry::mutableAll() {
|
|||||||
std::size_t Registry::addFromModule(void* soHandle) {
|
std::size_t Registry::addFromModule(void* soHandle) {
|
||||||
#if defined(__ELF__)
|
#if defined(__ELF__)
|
||||||
using BoundPtr = const Registration*;
|
using BoundPtr = const Registration*;
|
||||||
auto symStart = LoadSymbol(soHandle, "__start_vlmods");
|
auto symStart = LoadModSymbol(soHandle, "__start_vlmods");
|
||||||
auto symStop = LoadSymbol(soHandle, "__stop_vlmods");
|
auto symStop = LoadModSymbol(soHandle, "__stop_vlmods");
|
||||||
if ((symStart == nullptr) || (symStop == nullptr))
|
if ((symStart == nullptr) || (symStop == nullptr))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in new issue
Block a user