Skip to content

Commit 02e8551

Browse files
committed
check plugin version
- 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
1 parent 100b0da commit 02e8551

File tree

6 files changed

+76
-17
lines changed

6 files changed

+76
-17
lines changed

xmrstak/backend/amd/minethd.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "xmrstak/misc/environment.hpp"
3636
#include "xmrstak/params.hpp"
3737
#include "xmrstak/backend/cpu/hwlocMemory.hpp"
38+
#include "xmrstak/version.hpp"
3839

3940
#include <assert.h>
4041
#include <cmath>
@@ -80,6 +81,14 @@ std::vector<iBackend*>* xmrstak_start_backend(uint32_t threadOffset, miner_work&
8081
environment::inst(&env);
8182
return amd::minethd::thread_starter(threadOffset, pWork);
8283
}
84+
85+
#ifdef WIN32
86+
__declspec(dllexport)
87+
#endif
88+
std::string xmrstak_version_backend()
89+
{
90+
return XMR_STAK_VERSION;
91+
}
8392
} // extern "C"
8493

8594
bool minethd::init_gpus()

xmrstak/backend/backendConnector.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "xmrstak/misc/environment.hpp"
3030
#include "xmrstak/misc/console.hpp"
3131
#include "xmrstak/params.hpp"
32+
#include "xmrstak/version.hpp"
3233

3334
#include "cpu/minethd.hpp"
3435
#ifndef CONF_NO_CUDA
@@ -67,21 +68,43 @@ std::vector<iBackend*>* BackendConnector::thread_starter(miner_work& pWork)
6768
if(params::inst().useNVIDIA)
6869
{
6970
plugin nvidiaplugin("NVIDIA", "xmrstak_cuda_backend");
70-
std::vector<iBackend*>* nvidiaThreads = nvidiaplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
71-
pvThreads->insert(std::end(*pvThreads), std::begin(*nvidiaThreads), std::end(*nvidiaThreads));
72-
if(nvidiaThreads->size() == 0)
73-
printer::inst()->print_msg(L0, "WARNING: backend NVIDIA disabled.");
71+
if(nvidiaplugin.getVersion() == XMR_STAK_VERSION)
72+
{
73+
std::vector<iBackend*>* nvidiaThreads = nvidiaplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
74+
pvThreads->insert(std::end(*pvThreads), std::begin(*nvidiaThreads), std::end(*nvidiaThreads));
75+
if(nvidiaThreads->size() == 0)
76+
printer::inst()->print_msg(L0, "WARNING: backend NVIDIA disabled.");
77+
}
78+
else
79+
{
80+
printer::inst()->print_msg(L0,
81+
"WARNING: backend NVIDIA disabled. Version conflict, miner version is '%s' and backend is '%s'",
82+
XMR_STAK_VERSION,
83+
nvidiaplugin.getVersion().c_str()
84+
);
85+
}
7486
}
7587
#endif
7688

7789
#ifndef CONF_NO_OPENCL
7890
if(params::inst().useAMD)
7991
{
8092
plugin amdplugin("AMD", "xmrstak_opencl_backend");
81-
std::vector<iBackend*>* amdThreads = amdplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
82-
pvThreads->insert(std::end(*pvThreads), std::begin(*amdThreads), std::end(*amdThreads));
83-
if(amdThreads->size() == 0)
84-
printer::inst()->print_msg(L0, "WARNING: backend AMD disabled.");
93+
if(amdplugin.getVersion() == XMR_STAK_VERSION)
94+
{
95+
std::vector<iBackend*>* amdThreads = amdplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
96+
pvThreads->insert(std::end(*pvThreads), std::begin(*amdThreads), std::end(*amdThreads));
97+
if(amdThreads->size() == 0)
98+
printer::inst()->print_msg(L0, "WARNING: backend AMD disabled.");
99+
}
100+
else
101+
{
102+
printer::inst()->print_msg(L0,
103+
"WARNING: backend AMD disabled. Version conflict, miner version is '%s' and backend is '%s'",
104+
XMR_STAK_VERSION,
105+
amdplugin.getVersion().c_str()
106+
);
107+
}
85108
}
86109
#endif
87110

xmrstak/backend/nvidia/minethd.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "xmrstak/backend/cpu/hwlocMemory.hpp"
3535
#include "xmrstak/backend/cryptonight.hpp"
3636
#include "xmrstak/misc/utility.hpp"
37+
#include "xmrstak/version.hpp"
3738

3839
#include <assert.h>
3940
#include <cmath>
@@ -138,6 +139,14 @@ std::vector<iBackend*>* xmrstak_start_backend(uint32_t threadOffset, miner_work&
138139
environment::inst(&env);
139140
return nvidia::minethd::thread_starter(threadOffset, pWork);
140141
}
142+
143+
#ifdef WIN32
144+
__declspec(dllexport)
145+
#endif
146+
std::string xmrstak_version_backend()
147+
{
148+
return XMR_STAK_VERSION;
149+
}
141150
} // extern "C"
142151

143152
std::vector<iBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_work& pWork)

xmrstak/backend/plugin.hpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace xmrstak
2727
struct plugin
2828
{
2929

30-
plugin(const std::string backendName, const std::string libName) : fn_starterBackend(nullptr), m_backendName(backendName)
30+
plugin(const std::string backendName, const std::string libName) : m_backendName(backendName)
3131
{
3232
#ifdef WIN32
3333
libBackend = LoadLibrary(TEXT((libName + ".dll").c_str()));
@@ -61,18 +61,23 @@ struct plugin
6161
#ifdef WIN32
6262
fn_starterBackend = (starterBackend_t) GetProcAddress(libBackend, "xmrstak_start_backend");
6363
if (!fn_starterBackend)
64-
{
6564
std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_start_backend': " <<GetLastError()<< std::endl;
66-
}
65+
fn_versionBackend = (versionBackend_t) GetProcAddress(libBackend, "xmrstak_version_backend");
66+
if (!fn_versionBackend)
67+
std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_version_backend': " <<GetLastError()<< std::endl;
6768
#else
6869
// reset last error
6970
dlerror();
7071
fn_starterBackend = (starterBackend_t) dlsym(libBackend, "xmrstak_start_backend");
7172
const char* dlsym_error = dlerror();
7273
if(dlsym_error)
73-
{
7474
std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_start_backend': " << dlsym_error << std::endl;
75-
}
75+
dlerror();
76+
fn_versionBackend = (versionBackend_t) dlsym(libBackend, "xmrstak_version_backend");
77+
dlsym_error = dlerror();
78+
if(dlsym_error)
79+
std::cerr << "WARNING: backend plugin " << libName << " contains no entry 'xmrstak_version_backend': " << dlsym_error << std::endl;
80+
7681
#endif
7782
}
7883

@@ -88,11 +93,24 @@ struct plugin
8893
return fn_starterBackend(threadOffset, pWork, env);
8994
}
9095

96+
std::string getVersion()
97+
{
98+
if(fn_starterBackend == nullptr)
99+
{
100+
printer::inst()->print_msg(L1, "WARNING: extension %s has no version number, please update all miner files.", m_backendName.c_str());
101+
return std::string("unknown plugin version");
102+
}
103+
104+
return fn_versionBackend();
105+
}
106+
91107
std::string m_backendName;
92108

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

95-
starterBackend_t fn_starterBackend;
112+
starterBackend_t fn_starterBackend = nullptr;
113+
versionBackend_t fn_versionBackend = nullptr;
96114

97115
#ifdef WIN32
98116
HINSTANCE libBackend;

xmrstak/version.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#define BACKEND_TYPE unknown
1818
#endif
1919

20-
#define XMR_STAK_NAME "xmr-stak"
21-
#define XMR_STAK_VERSION "2.4.2"
22-
2320
#if defined(_WIN32)
2421
#define OS_TYPE "win"
2522
#elif defined(__APPLE__)

xmrstak/version.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <string>
55
#include "donate-level.hpp"
66

7+
#define XMR_STAK_NAME "xmr-stak"
8+
#define XMR_STAK_VERSION "2.4.2"
9+
710
extern const char ver_long[];
811
extern const char ver_short[];
912
extern const char ver_html[];

0 commit comments

Comments
 (0)