Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin-interface: use extern "C" for plugin init function #150

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions plugins/apitracing/src/lib/ApiTracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ namespace ApiTracing
}
}

std::unique_ptr<IPlugin>
VmiCore::Plugin::init(PluginInterface* pluginInterface,
std::shared_ptr<IPluginConfig> config, // NOLINT(performance-unnecessary-value-param)
std::vector<std::string> args)
extern "C" std::unique_ptr<IPlugin> VmiCore::Plugin::vmicore_plugin_init(
PluginInterface* pluginInterface,
std::shared_ptr<IPluginConfig> config, // NOLINT(performance-unnecessary-value-param)
std::vector<std::string> args)
{
return std::make_unique<ApiTracing::ApiTracing>(pluginInterface, *config, args);
}
8 changes: 4 additions & 4 deletions plugins/inmemoryscanner/src/lib/InMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ namespace InMemoryScanner
}
}

std::unique_ptr<IPlugin>
VmiCore::Plugin::init(PluginInterface* pluginInterface,
std::shared_ptr<IPluginConfig> config, // NOLINT(performance-unnecessary-value-param)
std::vector<std::string> args)
extern "C" std::unique_ptr<IPlugin> VmiCore::Plugin::vmicore_plugin_init(
PluginInterface* pluginInterface,
std::shared_ptr<IPluginConfig> config, // NOLINT(performance-unnecessary-value-param)
std::vector<std::string> args)
{
return std::make_unique<InMemoryScanner::InMemory>(pluginInterface, *config, args);
}
11 changes: 6 additions & 5 deletions plugins/template/src/lib/Template.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ 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<IPlugin>
VmiCore::Plugin::init(PluginInterface* pluginInterface,
std::shared_ptr<IPluginConfig> config, // NOLINT(performance-unnecessary-value-param)
std::vector<std::string> args)
extern "C" std::unique_ptr<IPlugin> VmiCore::Plugin::vmicore_plugin_init(
PluginInterface* pluginInterface,
std::shared_ptr<IPluginConfig> config, // NOLINT(performance-unnecessary-value-param)
std::vector<std::string> args)
{
return std::make_unique<Template::Template>(pluginInterface, *config, args);
}
5 changes: 3 additions & 2 deletions vmicore/src/include/vmicore/plugins/IPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ 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<IPlugin>
init(PluginInterface* pluginInterface, std::shared_ptr<IPluginConfig> config, std::vector<std::string> args);
extern "C" std::unique_ptr<IPlugin> vmicore_plugin_init(PluginInterface* pluginInterface,
std::shared_ptr<IPluginConfig> config,
std::vector<std::string> args);
}

#endif // APITRACING_IPLUGIN_H
6 changes: 2 additions & 4 deletions vmicore/src/lib/plugins/PluginSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,8 @@ namespace VmiCore
Plugin::PluginInterface::API_VERSION));
}

auto pluginInitFunction = std::bit_cast<decltype(Plugin::init)*>(
dlsym(libraryHandle,
"_ZN7VmiCore6Plugin4initEPNS0_15PluginInterfaceENSt3__110shared_ptrINS0_13IPluginConfigEEENS3_"
"6vectorINS3_12basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEENSB_ISD_EEEE"));
auto pluginInitFunction =
std::bit_cast<decltype(Plugin::vmicore_plugin_init)*>(dlsym(libraryHandle, PLUGIN_INIT_FUNCTION.data()));
dlErrorMessage = dlerror();
if (dlErrorMessage != nullptr)
{
Expand Down
2 changes: 2 additions & 0 deletions vmicore/src/lib/plugins/PluginSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace VmiCore
{
constexpr std::string_view PLUGIN_INIT_FUNCTION = "vmicore_plugin_init";

class IPluginSystem : public Plugin::PluginInterface
{
public:
Expand Down
Loading