From 6425c53d61d848fe073d12e97438e284f272003f Mon Sep 17 00:00:00 2001 From: SChernykh Date: Wed, 16 Jan 2019 00:09:00 +0100 Subject: [PATCH] Fixed crash in patchCode() on Linux --- src/crypto/asm/cn_main_loop.S | 20 ++++---------------- src/crypto/asm/cn_main_loop.asm | 20 ++++---------------- src/crypto/asm/win64/cn_main_loop.S | 20 ++++---------------- src/crypto/asm/win64/cn_main_loop.asm | 20 ++++---------------- src/workers/CpuThread.cpp | 3 ++- 5 files changed, 18 insertions(+), 65 deletions(-) diff --git a/src/crypto/asm/cn_main_loop.S b/src/crypto/asm/cn_main_loop.S index 1e5610d15..1d52f206d 100644 --- a/src/crypto/asm/cn_main_loop.S +++ b/src/crypto/asm/cn_main_loop.S @@ -23,10 +23,7 @@ FN_PREFIX(cnv2_mainloop_ivybridge_asm): #include "cn2/cnv2_main_loop_ivybridge.inc" add rsp, 48 ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE ALIGN(64) FN_PREFIX(cnv2_mainloop_ryzen_asm): @@ -35,10 +32,7 @@ FN_PREFIX(cnv2_mainloop_ryzen_asm): #include "cn2/cnv2_main_loop_ryzen.inc" add rsp, 48 ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE ALIGN(64) FN_PREFIX(cnv2_mainloop_bulldozer_asm): @@ -47,10 +41,7 @@ FN_PREFIX(cnv2_mainloop_bulldozer_asm): #include "cn2/cnv2_main_loop_bulldozer.inc" add rsp, 48 ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE ALIGN(64) FN_PREFIX(cnv2_double_mainloop_sandybridge_asm): @@ -60,7 +51,4 @@ FN_PREFIX(cnv2_double_mainloop_sandybridge_asm): #include "cn2/cnv2_double_main_loop_sandybridge.inc" add rsp, 48 ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE diff --git a/src/crypto/asm/cn_main_loop.asm b/src/crypto/asm/cn_main_loop.asm index 47b4df9e4..2b7a1f469 100644 --- a/src/crypto/asm/cn_main_loop.asm +++ b/src/crypto/asm/cn_main_loop.asm @@ -8,40 +8,28 @@ ALIGN(64) cnv2_mainloop_ivybridge_asm PROC INCLUDE cn2/cnv2_main_loop_ivybridge.inc ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE cnv2_mainloop_ivybridge_asm ENDP ALIGN(64) cnv2_mainloop_ryzen_asm PROC INCLUDE cn2/cnv2_main_loop_ryzen.inc ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE cnv2_mainloop_ryzen_asm ENDP ALIGN(64) cnv2_mainloop_bulldozer_asm PROC INCLUDE cn2/cnv2_main_loop_bulldozer.inc ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE cnv2_mainloop_bulldozer_asm ENDP ALIGN(64) cnv2_double_mainloop_sandybridge_asm PROC INCLUDE cn2/cnv2_double_main_loop_sandybridge.inc ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE cnv2_double_mainloop_sandybridge_asm ENDP _TEXT_CNV2_MAINLOOP ENDS diff --git a/src/crypto/asm/win64/cn_main_loop.S b/src/crypto/asm/win64/cn_main_loop.S index 90e43470c..bb0a581d1 100644 --- a/src/crypto/asm/win64/cn_main_loop.S +++ b/src/crypto/asm/win64/cn_main_loop.S @@ -10,34 +10,22 @@ ALIGN(64) cnv2_mainloop_ivybridge_asm: #include "../cn2/cnv2_main_loop_ivybridge.inc" ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE ALIGN(64) cnv2_mainloop_ryzen_asm: #include "../cn2/cnv2_main_loop_ryzen.inc" ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE ALIGN(64) cnv2_mainloop_bulldozer_asm: #include "../cn2/cnv2_main_loop_bulldozer.inc" ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE ALIGN(64) cnv2_double_mainloop_sandybridge_asm: #include "../cn2/cnv2_double_main_loop_sandybridge.inc" ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE diff --git a/src/crypto/asm/win64/cn_main_loop.asm b/src/crypto/asm/win64/cn_main_loop.asm index 9c8a6ea9c..40cb1cac8 100644 --- a/src/crypto/asm/win64/cn_main_loop.asm +++ b/src/crypto/asm/win64/cn_main_loop.asm @@ -8,40 +8,28 @@ ALIGN 64 cnv2_mainloop_ivybridge_asm PROC INCLUDE cn2/cnv2_main_loop_ivybridge.inc ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE cnv2_mainloop_ivybridge_asm ENDP ALIGN 64 cnv2_mainloop_ryzen_asm PROC INCLUDE cn2/cnv2_main_loop_ryzen.inc ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE cnv2_mainloop_ryzen_asm ENDP ALIGN 64 cnv2_mainloop_bulldozer_asm PROC INCLUDE cn2/cnv2_main_loop_bulldozer.inc ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE cnv2_mainloop_bulldozer_asm ENDP ALIGN 64 cnv2_double_mainloop_sandybridge_asm PROC INCLUDE cn2/cnv2_double_main_loop_sandybridge.inc ret 0 - nop - nop - nop - nop + mov eax, 0xDEADC0DE cnv2_double_mainloop_sandybridge_asm ENDP _TEXT_CNV2_MAINLOOP ENDS diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 5b7016e42..082effe2d 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -69,9 +69,10 @@ static void patchCode(T dst, U src, const uint32_t iterations, const uint32_t ma # endif size_t size = 0; - while (*(uint32_t*)(p + size) != 0x90909090) { + while (*(uint32_t*)(p + size) != 0xDEADC0DE) { ++size; } + size += sizeof(uint32_t); memcpy((void*) dst, (const void*) src, size);