Fixed a potential crash in JitCompilerX86

This commit is contained in:
tevador 2018-12-27 21:42:38 +01:00
parent 5bc26348f1
commit 39c569ae44
2 changed files with 13 additions and 4 deletions

View file

@ -81,6 +81,11 @@ namespace RandomX {
*/
constexpr uint8_t ic3 = (InstructionCount >> 24);
constexpr uint8_t ic2 = (InstructionCount >> 16);
constexpr uint8_t ic1 = (InstructionCount >> 8);
constexpr uint8_t ic0 = (InstructionCount >> 0);
const uint8_t prologue[] = {
0x53, //push rbx
0x55, //push rbp
@ -108,7 +113,7 @@ namespace RandomX {
0x48, 0x8b, 0xcf, //mov rcx, rdi
#endif
0x48, 0x8b, 0xec, //mov rbp,rsp
0x48, 0xc7, 0xc7, 0x00, 0x00, 0x10, 0x00, //mov rdi,0x100000
0x48, 0xc7, 0xc7, ic0, ic1, ic2, ic3, //mov rdi, "InstructionCount"
0x4c, 0x8b, 0x01, //mov r8,QWORD PTR[rcx]
0x4c, 0x8b, 0x49, 0x08, //mov r9,QWORD PTR[rcx+0x8]
0x4c, 0x8b, 0x51, 0x10, //mov r10,QWORD PTR[rcx+0x10]
@ -209,11 +214,15 @@ namespace RandomX {
throw std::runtime_error("mmap failed");
#endif
memcpy(code, prologue, sizeof(prologue));
if (startOffsetAligned - sizeof(prologue) > 4) {
codePos = sizeof(prologue);
if (startOffsetAligned - codePos > 4) {
emitByte(0xeb);
emitByte(startOffsetAligned - (codePos + 1));
}
else {
while (codePos < startOffsetAligned)
emitByte(0x90); //nop
}
memcpy(code + readDatasetSubOffset, readDatasetSub, sizeof(readDatasetSub));
memcpy(code + epilogueOffset, epilogue, sizeof(epilogue));
}

View file

@ -62,7 +62,7 @@ namespace RandomX {
};
constexpr int ProgramLength = 512;
constexpr int InstructionCount = 1024 * 1024;
constexpr uint32_t InstructionCount = 1024 * 1024;
constexpr uint32_t ScratchpadSize = 256 * 1024;
constexpr uint32_t ScratchpadLength = ScratchpadSize / sizeof(convertible_t);
constexpr uint32_t ScratchpadL1 = ScratchpadSize / 16 / sizeof(convertible_t);