MCPcopy Create free account
hub / github.com/WayfireWM/wayfire / check_plugin_api_version

Function check_plugin_api_version

src/core/plugin-loader.cpp:82–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82static bool check_plugin_api_version(const std::string& path, bool can_unload_so)
83{
84 // First, open everything just locally and in a lazy way.
85 // We want to check just the API/ABI version.
86 // If we load with RTLD_NOW, if the API/ABI version is wrong, we may get a crash just by
87 // dlopen()-ing the plugin.
88 void *handle = dlopen(path.c_str(), RTLD_LOCAL | RTLD_LAZY);
89 if (handle == NULL)
90 {
91 LOGE("error loading plugin [", path, "]: ", dlerror());
92 return false;
93 }
94
95 /* Check plugin version */
96 auto version_func_ptr = dlsym(handle, "getWayfireVersion");
97 if (version_func_ptr == NULL)
98 {
99 LOGE(path, ": missing getWayfireVersion()", path.c_str());
100 dlclose(handle);
101 return false;
102 }
103
104 auto version_func = wf::union_cast<void*, wayfire_plugin_version_func>(version_func_ptr);
105 int32_t plugin_abi_version = version_func();
106
107 if (version_func() != WAYFIRE_API_ABI_VERSION)
108 {
109 LOGE(path, ": API/ABI version mismatch: Wayfire is ",
110 WAYFIRE_API_ABI_VERSION, ", plugin built with ", plugin_abi_version);
111 dlclose(handle);
112 return false;
113 }
114
115 if (can_unload_so)
116 {
117 dlclose(handle);
118 }
119
120 return true;
121}
122
123std::pair<void*, void*> wf::get_new_instance_handle(const std::string& path, bool can_unload_so)
124{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected