Skip to content

Commit

Permalink
check plugin version
Browse files Browse the repository at this point in the history
- move define version number and name of xmr-stak to `version.hpp`
- add for gpu backends the interface function `xmrstak_version_backend`
- handle wrong version of miner and backends
  • Loading branch information
psychocrypt committed Apr 14, 2018
1 parent 100b0da commit 02e8551
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 17 deletions.
9 changes: 9 additions & 0 deletions xmrstak/backend/amd/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "xmrstak/misc/environment.hpp"
#include "xmrstak/params.hpp"
#include "xmrstak/backend/cpu/hwlocMemory.hpp"
#include "xmrstak/version.hpp"

#include <assert.h>
#include <cmath>
Expand Down Expand Up @@ -80,6 +81,14 @@ std::vector<iBackend*>* xmrstak_start_backend(uint32_t threadOffset, miner_work&
environment::inst(&env);
return amd::minethd::thread_starter(threadOffset, pWork);
}

#ifdef WIN32
__declspec(dllexport)
#endif
std::string xmrstak_version_backend()
{
return XMR_STAK_VERSION;
}
} // extern "C"

bool minethd::init_gpus()
Expand Down
39 changes: 31 additions & 8 deletions xmrstak/backend/backendConnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "xmrstak/misc/environment.hpp"
#include "xmrstak/misc/console.hpp"
#include "xmrstak/params.hpp"
#include "xmrstak/version.hpp"

#include "cpu/minethd.hpp"
#ifndef CONF_NO_CUDA
Expand Down Expand Up @@ -67,21 +68,43 @@ std::vector<iBackend*>* BackendConnector::thread_starter(miner_work& pWork)
if(params::inst().useNVIDIA)
{
plugin nvidiaplugin("NVIDIA", "xmrstak_cuda_backend");
std::vector<iBackend*>* nvidiaThreads = nvidiaplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
pvThreads->insert(std::end(*pvThreads), std::begin(*nvidiaThreads), std::end(*nvidiaThreads));
if(nvidiaThreads->size() == 0)
printer::inst()->print_msg(L0, "WARNING: backend NVIDIA disabled.");
if(nvidiaplugin.getVersion() == XMR_STAK_VERSION)
{
std::vector<iBackend*>* nvidiaThreads = nvidiaplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
pvThreads->insert(std::end(*pvThreads), std::begin(*nvidiaThreads), std::end(*nvidiaThreads));
if(nvidiaThreads->size() == 0)
printer::inst()->print_msg(L0, "WARNING: backend NVIDIA disabled.");
}
else
{
printer::inst()->print_msg(L0,
"WARNING: backend NVIDIA disabled. Version conflict, miner version is '%s' and backend is '%s'",
XMR_STAK_VERSION,
nvidiaplugin.getVersion().c_str()
);
}
}
#endif

#ifndef CONF_NO_OPENCL
if(params::inst().useAMD)
{
plugin amdplugin("AMD", "xmrstak_opencl_backend");
std::vector<iBackend*>* amdThreads = amdplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
pvThreads->insert(std::end(*pvThreads), std::begin(*amdThreads), std::end(*amdThreads));
if(amdThreads->size() == 0)
printer::inst()->print_msg(L0, "WARNING: backend AMD disabled.");
if(amdplugin.getVersion() == XMR_STAK_VERSION)
{
std::vector<iBackend*>* amdThreads = amdplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
pvThreads->insert(std::end(*pvThreads), std::begin(*amdThreads), std::end(*amdThreads));
if(amdThreads->size() == 0)
printer::inst()->print_msg(L0, "WARNING: backend AMD disabled.");
}
else
{
printer::inst()->print_msg(L0,
"WARNING: backend AMD disabled. Version conflict, miner version is '%s' and backend is '%s'",
XMR_STAK_VERSION,
amdplugin.getVersion().c_str()
);
}
}
#endif

Expand Down
9 changes: 9 additions & 0 deletions xmrstak/backend/nvidia/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "xmrstak/backend/cpu/hwlocMemory.hpp"
#include "xmrstak/backend/cryptonight.hpp"
#include "xmrstak/misc/utility.hpp"
#include "xmrstak/version.hpp"

#include <assert.h>
#include <cmath>
Expand Down Expand Up @@ -138,6 +139,14 @@ std::vector<iBackend*>* xmrstak_start_backend(uint32_t threadOffset, miner_work&
environment::inst(&env);
return nvidia::minethd::thread_starter(threadOffset, pWork);
}

#ifdef WIN32
__declspec(dllexport)
#endif
std::string xmrstak_version_backend()
{
return XMR_STAK_VERSION;
}
} // extern "C"

std::vector<iBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_work& pWork)
Expand Down
30 changes: 24 additions & 6 deletions xmrstak/backend/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace xmrstak
struct plugin
{

plugin(const std::string backendName, const std::string libName) : fn_starterBackend(nullptr), m_backendName(backendName)
plugin(const std::string backendName, const std::string libName) : m_backendName(backendName)
{
#ifdef WIN32
libBackend = LoadLibrary(TEXT((libName + ".dll").c_str()));
Expand Down Expand Up @@ -61,18 +61,23 @@ struct plugin
#ifdef WIN32
fn_starterBackend = (starterBackend_t) GetProcAddress(libBackend, "xmrstak_start_backend");
if (!fn_starterBackend)
{
std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_start_backend': " <<GetLastError()<< std::endl;
}
fn_versionBackend = (versionBackend_t) GetProcAddress(libBackend, "xmrstak_version_backend");
if (!fn_versionBackend)
std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_version_backend': " <<GetLastError()<< std::endl;
#else
// reset last error
dlerror();
fn_starterBackend = (starterBackend_t) dlsym(libBackend, "xmrstak_start_backend");
const char* dlsym_error = dlerror();
if(dlsym_error)
{
std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_start_backend': " << dlsym_error << std::endl;
}
dlerror();
fn_versionBackend = (versionBackend_t) dlsym(libBackend, "xmrstak_version_backend");
dlsym_error = dlerror();
if(dlsym_error)
std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_version_backend': " << dlsym_error << std::endl;

#endif
}

Expand All @@ -88,11 +93,24 @@ struct plugin
return fn_starterBackend(threadOffset, pWork, env);
}

std::string getVersion()
{
if(fn_starterBackend == nullptr)
{
printer::inst()->print_msg(L1, "WARNING: extension %s has no version number, please update all miner files.", m_backendName.c_str());
return std::string("unknown plugin version");
}

return fn_versionBackend();
}

std::string m_backendName;

typedef std::vector<iBackend*>* (*starterBackend_t)(uint32_t threadOffset, miner_work& pWork, environment& env);
typedef std::string (*versionBackend_t)();

starterBackend_t fn_starterBackend;
starterBackend_t fn_starterBackend = nullptr;
versionBackend_t fn_versionBackend = nullptr;

#ifdef WIN32
HINSTANCE libBackend;
Expand Down
3 changes: 0 additions & 3 deletions xmrstak/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#define BACKEND_TYPE unknown
#endif

#define XMR_STAK_NAME "xmr-stak"
#define XMR_STAK_VERSION "2.4.2"

#if defined(_WIN32)
#define OS_TYPE "win"
#elif defined(__APPLE__)
Expand Down
3 changes: 3 additions & 0 deletions xmrstak/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <string>
#include "donate-level.hpp"

#define XMR_STAK_NAME "xmr-stak"
#define XMR_STAK_VERSION "2.4.2"

extern const char ver_long[];
extern const char ver_short[];
extern const char ver_html[];
Expand Down

0 comments on commit 02e8551

Please sign in to comment.