BACKENDS: Migrate plugins to Path API

This commit is contained in:
Le Philousophe 2023-11-26 19:07:11 +01:00 committed by Eugene Sandulenko
parent 339cff9358
commit b3fbce7782
13 changed files with 78 additions and 77 deletions

View File

@ -68,7 +68,7 @@ protected:
virtual VoidFunc findSymbol(const char *symbol) {
void *func = dlsym(_dlHandle, symbol);
if (!func)
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror());
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.toString(Common::Path::kNativeSeparator).c_str(), dlerror());
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
// standard and POSIX: ISO C++ disallows casting between function pointers
@ -83,19 +83,19 @@ protected:
void checkDisc(const DiscLabel &);
public:
DCPlugin(const Common::String &filename)
DCPlugin(const Common::Path &filename)
: DynamicPlugin(filename), _dlHandle(0) {}
bool loadPlugin() {
assert(!_dlHandle);
DiscLabel original;
checkDisc(_label);
drawPluginProgress(_filename);
_dlHandle = dlopen(_filename.c_str(), RTLD_LAZY);
drawPluginProgress(_filename.toString(Common::Path::kNativeSeparator));
_dlHandle = dlopen(_filename.toString(Common::Path::kNativeSeparator).c_str(), RTLD_LAZY);
if (!_dlHandle) {
checkDisc(original);
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror());
warning("Failed loading plugin '%s' (%s)", _filename.toString(Common::Path::kNativeSeparator).c_str(), dlerror());
return false;
}
@ -112,7 +112,7 @@ public:
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
if (dlclose(_dlHandle) != 0)
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
warning("Failed unloading plugin '%s' (%s)", _filename.toString(Common::Path::kNativeSeparator).c_str(), dlerror());
_dlHandle = 0;
}
}

View File

@ -34,10 +34,10 @@ protected:
virtual VoidFunc findSymbol(const char *symbol) = 0;
const Common::String _filename;
const Common::Path _filename;
public:
DynamicPlugin(const Common::String &filename) :
DynamicPlugin(const Common::Path &filename) :
_filename(filename) {}
virtual bool loadPlugin() {
@ -100,8 +100,8 @@ public:
delete _pluginObject;
}
virtual const char *getFileName() const {
return _filename.c_str();
virtual Common::Path getFileName() const override {
return _filename;
}
};

View File

@ -325,12 +325,11 @@ void DLObject::relocateSymbols(ptrdiff_t offset) {
// Track the size of the plugin through memory manager without loading
// the plugin into memory.
//
void DLObject::trackSize(const char *path) {
void DLObject::trackSize(const Common::Path &path) {
_file = Common::FSNode(path).createReadStream();
if (!_file) {
warning("elfloader: File %s not found.", path);
warning("elfloader: File %s not found.", path.toString(Common::Path::kNativeSeparator).c_str());
return;
}
@ -415,19 +414,21 @@ bool DLObject::load() {
return true;
}
bool DLObject::open(const char *path) {
bool DLObject::open(const Common::Path &path) {
Common::String pathS(path.toString(Common::Path::kNativeSeparator));
void *ctors_start, *ctors_end;
debug(2, "elfloader: open(\"%s\")", path);
debug(2, "elfloader: open(\"%s\")", pathS.c_str());
_file = Common::FSNode(path).createReadStream();
if (!_file) {
warning("elfloader: File %s not found.", path);
warning("elfloader: File %s not found.", pathS.c_str());
return false;
}
debug(2, "elfloader: %s found!", path);
debug(2, "elfloader: %s found!", pathS.c_str());
/*Try to load and relocate*/
if (!load()) {
@ -458,7 +459,7 @@ bool DLObject::open(const char *path) {
for (void (**f)(void) = (void (**)(void))ctors_start; f != ctors_end; f++)
(**f)();
debug(2, "elfloader: %s opened ok.", path);
debug(2, "elfloader: %s opened ok.", pathS.c_str());
return true;
}

View File

@ -95,8 +95,8 @@ public:
* Test the size of the plugin in memory using the memory manager.
* @param path Path of file
*/
void trackSize(const char *path);
bool open(const char *path);
void trackSize(const Common::Path &path);
bool open(const Common::Path &path);
bool close();
void *symbol(const char *name);
void discardSymtab();

View File

@ -78,9 +78,9 @@ DynamicPlugin::VoidFunc ELFPlugin::findSymbol(const char *symbol) {
if (!func) {
if (!_dlHandle)
warning("elfloader: Failed loading symbol '%s' from plugin '%s' (Handle is NULL)", symbol, _filename.c_str());
warning("elfloader: Failed loading symbol '%s' from plugin '%s' (Handle is NULL)", symbol, _filename.toString(Common::Path::kNativeSeparator).c_str());
else
warning("elfloader: Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
warning("elfloader: Failed loading symbol '%s' from plugin '%s'", symbol, _filename.toString(Common::Path::kNativeSeparator).c_str());
}
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
@ -100,7 +100,7 @@ void ELFPlugin::trackSize() {
// All we need to do is create our object, track its size, then delete it
DLObject *obj = makeDLObject();
obj->trackSize(_filename.c_str());
obj->trackSize(_filename);
delete obj;
}
@ -108,7 +108,7 @@ bool ELFPlugin::loadPlugin() {
assert(!_dlHandle);
DLObject *obj = makeDLObject();
if (obj->open(_filename.c_str())) {
if (obj->open(_filename)) {
_dlHandle = obj;
} else {
delete obj;
@ -116,20 +116,20 @@ bool ELFPlugin::loadPlugin() {
}
if (!_dlHandle) {
warning("elfloader: Failed loading plugin '%s'", _filename.c_str());
warning("elfloader: Failed loading plugin '%s'", _filename.toString(Common::Path::kNativeSeparator).c_str());
return false;
}
CharFunc buildDateFunc = (CharFunc)findSymbol("PLUGIN_getBuildDate");
if (!buildDateFunc) {
unloadPlugin();
warning("elfloader: plugin '%s' is missing symbols", _filename.c_str());
warning("elfloader: plugin '%s' is missing symbols", _filename.toString(Common::Path::kNativeSeparator).c_str());
return false;
}
if (strncmp(gScummVMPluginBuildDate, buildDateFunc(), strlen(gScummVMPluginBuildDate))) {
unloadPlugin();
warning("elfloader: plugin '%s' has a different build date", _filename.c_str());
warning("elfloader: plugin '%s' has a different build date", _filename.toString(Common::Path::kNativeSeparator).c_str());
return false;
}
@ -163,7 +163,7 @@ void ELFPlugin::unloadPlugin() {
#endif
if (!_dlHandle->close())
warning("elfloader: Failed unloading plugin '%s'", _filename.c_str());
warning("elfloader: Failed unloading plugin '%s'", _filename.toString(Common::Path::kNativeSeparator).c_str());
delete _dlHandle;
_dlHandle = 0;
@ -198,7 +198,7 @@ PluginList ELFPluginProvider::getPlugins() {
bool ELFPluginProvider::isPluginFilename(const Common::FSNode &node) const {
// Check the plugin suffix
Common::String filename = node.getName();
Common::String filename = node.getFileName();
if (!filename.hasSuffix(".PLG") && !filename.hasSuffix(".plg") &&
!filename.hasSuffix(".PLUGIN") && !filename.hasSuffix(".plugin"))

View File

@ -49,7 +49,7 @@ protected:
virtual VoidFunc findSymbol(const char *symbol);
public:
ELFPlugin(const Common::String &filename) :
ELFPlugin(const Common::Path &filename) :
DynamicPlugin(filename),
_dlHandle(0),
_dso_handle(0) {
@ -70,7 +70,7 @@ public:
template<class T>
class TemplatedELFPlugin : public ELFPlugin {
public:
TemplatedELFPlugin(const Common::String &filename) :
TemplatedELFPlugin(const Common::Path &filename) :
ELFPlugin(filename) {
}

View File

@ -46,19 +46,19 @@ protected:
}
public:
KolibriOSPlugin(const Common::String &filename)
KolibriOSPlugin(const Common::Path &filename)
: DynamicPlugin(filename), _dlHandle(0) {}
bool loadPlugin() override {
if (_dlHandle)
return true;
_dlHandle = load_library(_filename.c_str());
_dlHandle = load_library(_filename.toString(Common::Path::kNativeSeparator).c_str());
if (!_dlHandle) {
debug("Failed loading plugin '%s' (error code %d)", _filename.c_str(), errno);
debug("Failed loading plugin '%s' (error code %d)", _filename.toString(Common::Path::kNativeSeparator).c_str(), errno);
return false;
} else {
debug(1, "Success loading plugin '%s', handle %p", _filename.c_str(), _dlHandle);
debug(1, "Success loading plugin '%s', handle %p", _filename.toString(Common::Path::kNativeSeparator).c_str(), _dlHandle);
}
return DynamicPlugin::loadPlugin();

View File

@ -37,7 +37,7 @@ protected:
virtual VoidFunc findSymbol(const char *symbol) {
void *func = dlsym(_dlHandle, symbol);
if (!func)
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror());
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.toString(Common::Path::kNativeSeparator).c_str(), dlerror());
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
// standard and POSIX: ISO C++ disallows casting between function pointers
@ -50,15 +50,15 @@ protected:
}
public:
POSIXPlugin(const Common::String &filename)
POSIXPlugin(const Common::Path &filename)
: DynamicPlugin(filename), _dlHandle(0) {}
bool loadPlugin() {
assert(!_dlHandle);
_dlHandle = dlopen(_filename.c_str(), RTLD_LAZY);
_dlHandle = dlopen(_filename.toString(Common::Path::kNativeSeparator).c_str(), RTLD_LAZY);
if (!_dlHandle) {
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror());
warning("Failed loading plugin '%s' (%s)", _filename.toString(Common::Path::kNativeSeparator).c_str(), dlerror());
return false;
}
@ -69,7 +69,7 @@ public:
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
if (dlclose(_dlHandle) != 0)
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
warning("Failed unloading plugin '%s' (%s)", _filename.toString(Common::Path::kNativeSeparator).c_str(), dlerror());
_dlHandle = 0;
}
}

View File

@ -62,10 +62,10 @@ void *forceLinkFunctions[] = {
class PSP2Plugin final : public Plugin {
protected:
SceUID _modId;
const Common::String _filename;
const Common::Path _filename;
public:
PSP2Plugin(const Common::String &filename)
PSP2Plugin(const Common::Path &filename)
: _filename(filename), _modId(0) {}
bool loadPlugin() override {
@ -74,23 +74,23 @@ public:
PSP2FunctionPointers **arg = &functions;
int status = 0;
_modId = sceKernelLoadStartModule(_filename.c_str(), sizeof( arg ), &arg, 0, NULL, &status );
_modId = sceKernelLoadStartModule(_filename.toString(Common::Path::kNativeSeparator).c_str(), sizeof( arg ), &arg, 0, NULL, &status );
if (!_modId) {
debug("Failed loading plugin '%s' (error code %d)", _filename.c_str(), status);
debug("Failed loading plugin '%s' (error code %d)", _filename.toString(Common::Path::kNativeSeparator).c_str(), status);
return false;
} else {
debug(1, "Success loading plugin '%s', handle %08x", _filename.c_str(), _modId);
debug(1, "Success loading plugin '%s', handle %08x", _filename.toString(Common::Path::kNativeSeparator).c_str(), _modId);
}
// Validate the Vita version
if (!functions) {
debug("Failed loading plugin '%s': no pointer", _filename.c_str());
debug("Failed loading plugin '%s': no pointer", _filename.toString(Common::Path::kNativeSeparator).c_str());
unloadPlugin();
return false;
}
if (functions->version != PSP2FunctionPointers_VERSION) {
debug("Failed loading plugin '%s': unexpected version %d", _filename.c_str(), functions->version);
debug("Failed loading plugin '%s': unexpected version %d", _filename.toString(Common::Path::kNativeSeparator).c_str(), functions->version);
unloadPlugin();
return false;
}
@ -127,7 +127,7 @@ public:
return false;
}
debug(1, "Successfully loaded plugin '%s'", _filename.c_str());
debug(1, "Successfully loaded plugin '%s'", _filename.toString(Common::Path::kNativeSeparator).c_str());
return true;
}
@ -138,14 +138,14 @@ public:
int status = 0;
int ret = sceKernelStopUnloadModule(_modId, 0, NULL, 0, NULL, &status);
if (ret != SCE_OK) {
debug("Failed unloading plugin '%s': %d/%d", _filename.c_str(), ret, status);
debug("Failed unloading plugin '%s': %d/%d", _filename.toString(Common::Path::kNativeSeparator).c_str(), ret, status);
}
_modId = 0;
}
}
virtual const char *getFileName() const {
return _filename.c_str();
Common::Path getFileName() const override {
return _filename;
}
};

View File

@ -37,7 +37,7 @@ protected:
virtual VoidFunc findSymbol(const char *symbol) {
void *func = SDL_LoadFunction(_dlHandle, symbol);
if (!func)
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), SDL_GetError());
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.toString(Common::Path::kNativeSeparator).c_str(), SDL_GetError());
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
// standard and POSIX: ISO C++ disallows casting between function pointers
@ -50,15 +50,15 @@ protected:
}
public:
SDLPlugin(const Common::String &filename)
SDLPlugin(const Common::Path &filename)
: DynamicPlugin(filename), _dlHandle(0) {}
bool loadPlugin() {
assert(!_dlHandle);
_dlHandle = SDL_LoadObject(_filename.c_str());
_dlHandle = SDL_LoadObject(_filename.toString(Common::Path::kNativeSeparator).c_str());
if (!_dlHandle) {
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), SDL_GetError());
warning("Failed loading plugin '%s' (%s)", _filename.toString(Common::Path::kNativeSeparator).c_str(), SDL_GetError());
return false;
}

View File

@ -43,13 +43,13 @@ protected:
VoidFunc findSymbol(const char *symbol) override {
FARPROC func = GetProcAddress((HMODULE)_dlHandle, symbol);
if (!func)
debug("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
debug("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.toString(Common::Path::kNativeSeparator).c_str());
return (void (*)())func;
}
public:
Win32Plugin(const Common::String &filename)
Win32Plugin(const Common::Path &filename)
: DynamicPlugin(filename), _dlHandle(0) {}
bool loadPlugin() override {
@ -59,10 +59,10 @@ public:
free(tFilename);
if (!_dlHandle) {
warning("Failed loading plugin '%s' (error code %d)", _filename.c_str(), (int32) GetLastError());
warning("Failed loading plugin '%s' (error code %d)", _filename.toString(Common::Path::kNativeSeparator).c_str(), (int32) GetLastError());
return false;
} else {
debug(1, "Success loading plugin '%s', handle %p", _filename.c_str(), _dlHandle);
debug(1, "Success loading plugin '%s', handle %p", _filename.toString(Common::Path::kNativeSeparator).c_str(), _dlHandle);
}
return DynamicPlugin::loadPlugin();
@ -72,9 +72,9 @@ public:
DynamicPlugin::unloadPlugin();
if (_dlHandle) {
if (!FreeLibrary((HMODULE)_dlHandle))
warning("Failed unloading plugin '%s'", _filename.c_str());
warning("Failed unloading plugin '%s'", _filename.toString(Common::Path::kNativeSeparator).c_str());
else
debug(1, "Success unloading plugin '%s'", _filename.c_str());
debug(1, "Success unloading plugin '%s'", _filename.toString(Common::Path::kNativeSeparator).c_str());
_dlHandle = 0;
}
}

View File

@ -206,10 +206,10 @@ PluginList FilePluginProvider::getPlugins() {
// Scan for all plugins in this directory
Common::FSList files;
if (!dir->getChildren(files, Common::FSNode::kListFilesOnly)) {
debug(1, "Couldn't open plugin directory '%s'", dir->getPath().c_str());
debug(1, "Couldn't open plugin directory '%s'", dir->getPath().toString().c_str());
continue;
} else {
debug(1, "Reading plugins from plugin directory '%s'", dir->getPath().c_str());
debug(1, "Reading plugins from plugin directory '%s'", dir->getPath().toString().c_str());
}
for (Common::FSList::const_iterator i = files.begin(); i != files.end(); ++i) {
@ -296,7 +296,7 @@ const Plugin *PluginManager::getEngineFromMetaEngine(const Plugin *plugin) {
enginePlugin = PluginMan.findEnginePlugin(metaEnginePluginName);
if (enginePlugin) {
debug(9, "MetaEngine: %s \t matched to \t Engine: %s", plugin->get<MetaEngineDetection>().getEngineName(), enginePlugin->getFileName());
debug(9, "MetaEngine: %s \t matched to \t Engine: %s", plugin->get<MetaEngineDetection>().getEngineName(), enginePlugin->getFileName().toString().c_str());
return enginePlugin;
}
@ -325,11 +325,11 @@ const Plugin *PluginManager::getMetaEngineFromEngine(const Plugin *plugin) {
}
if (metaEngine) {
debug(9, "Engine: %s matched to MetaEngine: %s", plugin->getFileName(), metaEngine->get<MetaEngineDetection>().getEngineName());
debug(9, "Engine: %s matched to MetaEngine: %s", plugin->getFileName().toString().c_str(), metaEngine->get<MetaEngineDetection>().getEngineName());
return metaEngine;
}
debug(9, "Engine: %s couldn't find a match for a MetaEngine plugin.", plugin->getFileName());
debug(9, "Engine: %s couldn't find a match for a MetaEngine plugin.", plugin->getFileName().toString().c_str());
return nullptr;
}
@ -364,8 +364,8 @@ void PluginManagerUncached::init() {
// music or an engine plugin.
#ifndef DETECTION_STATIC
if (!foundDetectPlugin && (*pp)->isFilePluginProvider()) {
Common::String pName = (*p)->getFileName();
if (pName.hasSuffixIgnoreCase(detectPluginName)) {
Common::Path pName = (*p)->getFileName();
if (pName.baseName().hasSuffixIgnoreCase(detectPluginName)) {
_detectionPlugin = (*p);
foundDetectPlugin = true;
debug(9, "Detection plugin found!");
@ -398,7 +398,7 @@ bool PluginManagerUncached::loadPluginFromEngineId(const Common::String &engineI
if (domain) {
if (domain->contains(engineId)) {
Common::String filename = (*domain)[engineId];
Common::Path filename(Common::Path::fromConfig((*domain)[engineId]));
if (loadPluginByFileName(filename)) {
return true;
@ -412,8 +412,8 @@ bool PluginManagerUncached::loadPluginFromEngineId(const Common::String &engineI
tentativeEnginePluginFilename += PLUGIN_SUFFIX;
#endif
for (PluginList::iterator p = _allEnginePlugins.begin(); p != _allEnginePlugins.end(); ++p) {
Common::String filename = (*p)->getFileName();
if (filename.hasSuffixIgnoreCase(tentativeEnginePluginFilename)) {
Common::Path filename = (*p)->getFileName();
if (filename.baseName().hasSuffixIgnoreCase(tentativeEnginePluginFilename)) {
if (loadPluginByFileName(filename)) {
return true;
}
@ -425,7 +425,7 @@ bool PluginManagerUncached::loadPluginFromEngineId(const Common::String &engineI
/**
* Load a plugin with a filename taken from ConfigManager.
**/
bool PluginManagerUncached::loadPluginByFileName(const Common::String &filename) {
bool PluginManagerUncached::loadPluginByFileName(const Common::Path &filename) {
if (filename.empty())
return false;
@ -433,7 +433,7 @@ bool PluginManagerUncached::loadPluginByFileName(const Common::String &filename)
PluginList::iterator i;
for (i = _allEnginePlugins.begin(); i != _allEnginePlugins.end(); ++i) {
if (Common::String((*i)->getFileName()) == filename && (*i)->loadPlugin()) {
if ((*i)->getFileName() == filename && (*i)->loadPlugin()) {
addToPluginsInMemList(*i);
_currentPlugin = i;
return true;
@ -448,13 +448,13 @@ bool PluginManagerUncached::loadPluginByFileName(const Common::String &filename)
**/
void PluginManagerUncached::updateConfigWithFileName(const Common::String &engineId) {
// Check if we have a filename for the current plugin
if ((*_currentPlugin)->getFileName()) {
if (!(*_currentPlugin)->getFileName().empty()) {
if (!ConfMan.hasMiscDomain("engine_plugin_files"))
ConfMan.addMiscDomain("engine_plugin_files");
Common::ConfigManager::Domain *domain = ConfMan.getDomain("engine_plugin_files");
assert(domain);
(*domain).setVal(engineId, (*_currentPlugin)->getFileName());
(*domain).setVal(engineId, (*_currentPlugin)->getFileName().toConfig());
ConfMan.flushToDisk();
}

View File

@ -178,7 +178,7 @@ public:
* plugins that have files (ie. not static). It doesn't require the plugin
* object to be loaded into memory, unlike getName()
**/
virtual const char *getFileName() const { return 0; }
virtual Common::Path getFileName() const { return Common::Path(); }
};
class StaticPlugin : public Plugin {
@ -362,7 +362,7 @@ protected:
bool _isDetectionLoaded;
PluginManagerUncached() : _isDetectionLoaded(false), _detectionPlugin(nullptr) {}
bool loadPluginByFileName(const Common::String &filename);
bool loadPluginByFileName(const Common::Path &filename);
public:
void init() override;