Plugin: load shared libraries on Windows
Add a private dlopen/dlsym/dlclose compatibility shim over LoadLibraryW / GetProcAddress and use it from the loader, host and manager. Allowlist Plugin for the Windows target. Verified with the Windows cross build under Wine 11 (x86_64-w64-mingw32 GCC 16.2): Plugin suite 6 tests, 5 passed, 1 skipped, 0 failed.
This commit is contained in:
1 parent
6fa77eed93
commit
b6e2181f0e
5 files changed
+86
No files matched your search
@@ -72,6 +72,7 @@ set(VOID_WINDOWS_MODULES
|
|||||||
Messaging
|
Messaging
|
||||||
Observability
|
Observability
|
||||||
ObservabilityHooks
|
ObservabilityHooks
|
||||||
|
Plugin
|
||||||
Scheduler
|
Scheduler
|
||||||
Service
|
Service
|
||||||
Sqlite
|
Sqlite
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Minimal dlopen/dlsym/dlclose compatibility for Windows (LoadLibrary).
|
||||||
|
// Private to the Plugin module; included instead of <dlfcn.h> on Windows.
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
#ifndef NOMINMAX
|
||||||
|
#define NOMINMAX
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#ifndef RTLD_NOW
|
||||||
|
#define RTLD_NOW 0
|
||||||
|
#endif
|
||||||
|
#ifndef RTLD_LOCAL
|
||||||
|
#define RTLD_LOCAL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace void_dl
|
||||||
|
{
|
||||||
|
inline std::string& error_slot() noexcept
|
||||||
|
{
|
||||||
|
static thread_local std::string error;
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void* open_wide(const wchar_t* path)
|
||||||
|
{
|
||||||
|
const HMODULE module = ::LoadLibraryW(path);
|
||||||
|
if (module == nullptr) {
|
||||||
|
error_slot() = "LoadLibrary failed (" +
|
||||||
|
std::to_string(::GetLastError()) + ")";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return reinterpret_cast<void*>(module);
|
||||||
|
}
|
||||||
|
} // namespace void_dl
|
||||||
|
|
||||||
|
inline void* dlopen(const wchar_t* path, int)
|
||||||
|
{
|
||||||
|
return void_dl::open_wide(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void* dlopen(const char* path, int)
|
||||||
|
{
|
||||||
|
const std::u8string utf8{reinterpret_cast<const char8_t*>(path)};
|
||||||
|
const std::filesystem::path wide{utf8};
|
||||||
|
return void_dl::open_wide(wide.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void* dlsym(void* handle, const char* symbol)
|
||||||
|
{
|
||||||
|
return reinterpret_cast<void*>(
|
||||||
|
::GetProcAddress(static_cast<HMODULE>(handle), symbol));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int dlclose(void* handle)
|
||||||
|
{
|
||||||
|
return ::FreeLibrary(static_cast<HMODULE>(handle)) != 0 ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline char* dlerror()
|
||||||
|
{
|
||||||
|
return void_dl::error_slot().empty()
|
||||||
|
? nullptr
|
||||||
|
: const_cast<char*>(void_dl::error_slot().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _WIN32
|
||||||
@@ -6,6 +6,9 @@
|
|||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#define VOID_HOST_HAS_DLOPEN 1
|
#define VOID_HOST_HAS_DLOPEN 1
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include "DlCompat.hpp"
|
||||||
|
#define VOID_HOST_HAS_DLOPEN 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#define VOID_HAS_DLOPEN 1
|
#define VOID_HAS_DLOPEN 1
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include "DlCompat.hpp"
|
||||||
|
#define VOID_HAS_DLOPEN 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#define VOID_HAS_DLOPEN 1
|
#define VOID_HAS_DLOPEN 1
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include "DlCompat.hpp"
|
||||||
|
#define VOID_HAS_DLOPEN 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|||||||
Reference in new issue
Block a user