Fixed RandomX initialization for VS debug builds

This commit is contained in:
SChernykh 2020-07-21 10:10:07 +02:00
parent 70c7f33a20
commit 5bc89fdc8b

View file

@ -165,32 +165,43 @@ RandomX_ConfigurationBase::RandomX_ConfigurationBase()
fillAes4Rx4_Key[6] = rx_set_int_vec_i128(0xf63befa7, 0x2ba9660a, 0xf765a38b, 0xf273c9e7);
fillAes4Rx4_Key[7] = rx_set_int_vec_i128(0xc0b0762d, 0x0c06d1fd, 0x915839de, 0x7a7cd609);
// Workaround for Visual Studio placing trampoline in debug builds.
auto addr = [](void (*func)()) {
const uint8_t* p = reinterpret_cast<const uint8_t*>(func);
# if defined(_MSC_VER)
if (p[0] == 0xE9) {
p += *(const int32_t*)(p + 1) + 5;
}
# endif
return p;
};
#if defined(_M_X64) || defined(__x86_64__)
{
const uint8_t* a = (const uint8_t*)&randomx_sshash_prefetch;
const uint8_t* b = (const uint8_t*)&randomx_sshash_end;
const uint8_t* a = addr(randomx_sshash_prefetch);
const uint8_t* b = addr(randomx_sshash_end);
memcpy(codeShhPrefetchTweaked, a, b - a);
}
{
const uint8_t* a = (const uint8_t*)&randomx_program_read_dataset;
const uint8_t* b = (const uint8_t*)&randomx_program_read_dataset_ryzen;
const uint8_t* a = addr(randomx_program_read_dataset);
const uint8_t* b = addr(randomx_program_read_dataset_ryzen);
memcpy(codeReadDatasetTweaked, a, b - a);
codeReadDatasetTweakedSize = b - a;
}
{
const uint8_t* a = (const uint8_t*)&randomx_program_read_dataset_ryzen;
const uint8_t* b = (const uint8_t*)&randomx_program_read_dataset_sshash_init;
const uint8_t* a = addr(randomx_program_read_dataset_ryzen);
const uint8_t* b = addr(randomx_program_read_dataset_sshash_init);
memcpy(codeReadDatasetRyzenTweaked, a, b - a);
codeReadDatasetRyzenTweakedSize = b - a;
}
{
const uint8_t* a = (const uint8_t*)&randomx_program_read_dataset_sshash_init;
const uint8_t* b = (const uint8_t*)&randomx_program_read_dataset_sshash_fin;
const uint8_t* a = addr(randomx_program_read_dataset_sshash_init);
const uint8_t* b = addr(randomx_program_read_dataset_sshash_fin);
memcpy(codeReadDatasetLightSshInitTweaked, a, b - a);
}
{
const uint8_t* a = (const uint8_t*)&randomx_prefetch_scratchpad;
const uint8_t* b = (const uint8_t*)&randomx_prefetch_scratchpad_end;
const uint8_t* a = addr(randomx_prefetch_scratchpad);
const uint8_t* b = addr(randomx_prefetch_scratchpad_end);
memcpy(codePrefetchScratchpadTweaked, a, b - a);
}
#endif