diff --git a/plugins/apitracing/src/lib/ApiTracing.cpp b/plugins/apitracing/src/lib/ApiTracing.cpp index 5cfa0dcb..ce9fdc2e 100644 --- a/plugins/apitracing/src/lib/ApiTracing.cpp +++ b/plugins/apitracing/src/lib/ApiTracing.cpp @@ -99,8 +99,8 @@ namespace ApiTracing } } -std::unique_ptr -VmiCore::Plugin::init(PluginInterface* pluginInterface, +extern "C" std::unique_ptr +VmiCore::Plugin::init_plugin(PluginInterface* pluginInterface, std::shared_ptr config, // NOLINT(performance-unnecessary-value-param) std::vector args) { diff --git a/plugins/inmemoryscanner/src/lib/InMemory.cpp b/plugins/inmemoryscanner/src/lib/InMemory.cpp index f68c626f..5329318c 100644 --- a/plugins/inmemoryscanner/src/lib/InMemory.cpp +++ b/plugins/inmemoryscanner/src/lib/InMemory.cpp @@ -66,8 +66,8 @@ namespace InMemoryScanner } } -std::unique_ptr -VmiCore::Plugin::init(PluginInterface* pluginInterface, +extern "C" std::unique_ptr +VmiCore::Plugin::init_plugin(PluginInterface* pluginInterface, std::shared_ptr config, // NOLINT(performance-unnecessary-value-param) std::vector args) { diff --git a/plugins/template/src/lib/Template.cpp b/plugins/template/src/lib/Template.cpp index c2a10465..4ac314f7 100755 --- a/plugins/template/src/lib/Template.cpp +++ b/plugins/template/src/lib/Template.cpp @@ -51,10 +51,11 @@ namespace Template } } -// This is the init function. It is called by VmiCore and is responsible for creating an instance of a plugin. +// This is the init function. It is linked and called dynamically at runtime by +// VmiCore and is responsible for creating an instance of a plugin. // All plugins have to inherit from IPlugin. -std::unique_ptr -VmiCore::Plugin::init(PluginInterface* pluginInterface, +extern "C" std::unique_ptr +VmiCore::Plugin::init_plugin(PluginInterface* pluginInterface, std::shared_ptr config, // NOLINT(performance-unnecessary-value-param) std::vector args) { diff --git a/vmicore/src/include/vmicore/plugins/IPlugin.h b/vmicore/src/include/vmicore/plugins/IPlugin.h index 9b6aef11..f158db47 100644 --- a/vmicore/src/include/vmicore/plugins/IPlugin.h +++ b/vmicore/src/include/vmicore/plugins/IPlugin.h @@ -44,8 +44,8 @@ namespace VmiCore::Plugin * @param args Commandline arguments passed to this specific plugin. Elements are whitespace separated. * @return An instance of the plugin. Has to implement the IPlugin interface. Lifetime will be managed by VMICore. */ - extern std::unique_ptr - init(PluginInterface* pluginInterface, std::shared_ptr config, std::vector args); + extern "C" std::unique_ptr + init_plugin(PluginInterface* pluginInterface, std::shared_ptr config, std::vector args); } #endif // APITRACING_IPLUGIN_H diff --git a/vmicore/src/lib/plugins/PluginSystem.cpp b/vmicore/src/lib/plugins/PluginSystem.cpp index cba1bed3..3a687d57 100644 --- a/vmicore/src/lib/plugins/PluginSystem.cpp +++ b/vmicore/src/lib/plugins/PluginSystem.cpp @@ -161,10 +161,8 @@ namespace VmiCore Plugin::PluginInterface::API_VERSION)); } - auto pluginInitFunction = std::bit_cast( - dlsym(libraryHandle, - "_ZN7VmiCore6Plugin4initEPNS0_15PluginInterfaceENSt3__110shared_ptrINS0_13IPluginConfigEEENS3_" - "6vectorINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENSB_ISD_EEEE")); + auto pluginInitFunction = + std::bit_cast(dlsym(libraryHandle, PLUGIN_INIT_FUNCTION.data())); dlErrorMessage = dlerror(); if (dlErrorMessage != nullptr) { @@ -172,6 +170,10 @@ namespace VmiCore } auto plugin = pluginInitFunction(dynamic_cast(this), std::move(config), args); + if (plugin == nullptr) + { + throw PluginException(pluginName, "init function returned null"); + } plugins.emplace_back(pluginName, std::move(plugin)); } diff --git a/vmicore/src/lib/plugins/PluginSystem.h b/vmicore/src/lib/plugins/PluginSystem.h index c8be60c0..9b8e0b26 100644 --- a/vmicore/src/lib/plugins/PluginSystem.h +++ b/vmicore/src/lib/plugins/PluginSystem.h @@ -17,6 +17,8 @@ namespace VmiCore { + constexpr std::string_view PLUGIN_INIT_FUNCTION = "init_plugin"; + class IPluginSystem : public Plugin::PluginInterface { public: