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

Try loading alternative SO files on 32 bit Linux #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
85 changes: 65 additions & 20 deletions source/vst/hosting/module_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class LinuxModule : public Module
}
}

static Optional<Path> getSOPath (const std::string& inPath)
static Optional<Path> getSOPath (const std::string& inPath, const std::string& machine)
{
Path modulePath {inPath};
if (!filesystem::is_directory (modulePath))
Expand All @@ -155,12 +155,7 @@ class LinuxModule : public Module
if (!filesystem::is_directory (modulePath))
return {};

// use the Machine Hardware Name (from uname cmd-line) as prefix for "-linux"
auto machine = getCurrentMachineName ();
if (!machine)
return {};

modulePath /= *machine + "-linux";
modulePath /= machine + "-linux";
if (!filesystem::is_directory (modulePath))
return {};

Expand All @@ -171,61 +166,111 @@ class LinuxModule : public Module

bool load (const std::string& inPath, std::string& errorDescription) override
{
auto modulePath = getSOPath (inPath);
// use the Machine Hardware Name (from uname cmd-line) as prefix for "-linux"
auto machine = getCurrentMachineName ();
if (!machine)
{
errorDescription = "uname failed.";
return false;
}

errorDescription = "";

#if SMTG_PLATFORM_64
return tryLoad (inPath, errorDescription, *machine);
#else
if (tryLoad (inPath, errorDescription, *machine))
{
return true;
}

// 64 bit kernel may be runnig a 32 bit application, or uname reported i386 when
// we should be looking for i686 or vica-versa, so let's try possible options.
// Note: this logic assumes that the host will never run on a CPU which actually
// doesn't support i686 instructions.

if (*machine != "i686")
{
errorDescription += '\n';
if (tryLoad (inPath, errorDescription, "i686"))
{
errorDescription = "";
return true;
}
}

if (*machine != "i386")
{
errorDescription += '\n';
if (tryLoad (inPath, errorDescription, "i386"))
{
errorDescription = "";
return true;
}
}

return false;
#endif
}

void* mModule {nullptr};

private:
bool tryLoad (const std::string& inPath, std::string& errorDescription, const std::string& machine)
{
auto modulePath = getSOPath (inPath, machine);
if (!modulePath)
{
errorDescription = inPath + " is not a module directory.";
errorDescription += inPath + " is not a module directory (" + machine + ").";
return false;
}

mModule = dlopen (reinterpret_cast<const char*> (modulePath->generic_string ().data ()),
RTLD_LAZY);
if (!mModule)
{
errorDescription = "dlopen failed.\n";
errorDescription += "dlopen failed (" + machine + ").\n";
errorDescription += dlerror ();
return false;
}
// ModuleEntry is mandatory
auto moduleEntry = getFunctionPointer<ModuleEntryFunc> ("ModuleEntry");
if (!moduleEntry)
{
errorDescription =
"The shared library does not export the required 'ModuleEntry' function";
errorDescription +=
"The shared library does not export the required 'ModuleEntry' function (" + machine + ").";
return false;
}
// ModuleExit is mandatory
auto moduleExit = getFunctionPointer<ModuleExitFunc> ("ModuleExit");
if (!moduleExit)
{
errorDescription =
"The shared library does not export the required 'ModuleExit' function";
errorDescription +=
"The shared library does not export the required 'ModuleExit' function (" + machine + ").";
return false;
}
auto factoryProc = getFunctionPointer<GetFactoryProc> ("GetPluginFactory");
if (!factoryProc)
{
errorDescription =
"The shared library does not export the required 'GetPluginFactory' function";
errorDescription +=
"The shared library does not export the required 'GetPluginFactory' function (" + machine + ").";
return false;
}

if (!moduleEntry (mModule))
{
errorDescription = "Calling 'ModuleEntry' failed";
errorDescription += "Calling 'ModuleEntry' failed (" + machine + ").";
return false;
}
auto f = Steinberg::FUnknownPtr<Steinberg::IPluginFactory> (owned (factoryProc ()));
if (!f)
{
errorDescription = "Calling 'GetPluginFactory' returned nullptr";
errorDescription += "Calling 'GetPluginFactory' returned nullptr (" + machine + ").";
return false;
}
factory = PluginFactory (f);
return true;
}

void* mModule {nullptr};
};

//------------------------------------------------------------------------
Expand Down