RandomX: correct memcpy size for JIT initialization

No buffer overflow, better fix for `_FORTIFY_SOURCE`
This commit is contained in:
SChernykh 2024-04-14 09:13:00 +02:00
parent c7c26d97fe
commit caae7c64f0
5 changed files with 5 additions and 6 deletions

View file

@ -1078,6 +1078,6 @@ void JitCompilerA64::h_NOP(Instruction& instr, uint32_t& codePos)
{ {
} }
InstructionGeneratorA64 JitCompilerA64::engine[257] = {}; InstructionGeneratorA64 JitCompilerA64::engine[256] = {};
} }

View file

@ -74,7 +74,7 @@ namespace randomx {
void enableWriting() const; void enableWriting() const;
void enableExecution() const; void enableExecution() const;
static InstructionGeneratorA64 engine[257]; static InstructionGeneratorA64 engine[256];
private: private:
const bool hugePages; const bool hugePages;

View file

@ -1443,6 +1443,6 @@ namespace randomx {
emitByte(0x90, code, codePos); emitByte(0x90, code, codePos);
} }
alignas(64) InstructionGeneratorX86 JitCompilerX86::engine[257] = {}; alignas(64) InstructionGeneratorX86 JitCompilerX86::engine[256] = {};
} }

View file

@ -81,7 +81,7 @@ namespace randomx {
void enableWriting() const; void enableWriting() const;
void enableExecution() const; void enableExecution() const;
alignas(64) static InstructionGeneratorX86 engine[257]; alignas(64) static InstructionGeneratorX86 engine[256];
private: private:
int registerUsage[RegistersCount] = {}; int registerUsage[RegistersCount] = {};

View file

@ -260,8 +260,7 @@ typedef void(randomx::JitCompilerX86::* InstructionGeneratorX86_2)(const randomx
#define JIT_HANDLE(x, prev) do { \ #define JIT_HANDLE(x, prev) do { \
const InstructionGeneratorX86_2 p = &randomx::JitCompilerX86::h_##x; \ const InstructionGeneratorX86_2 p = &randomx::JitCompilerX86::h_##x; \
static_assert(sizeof(p) == sizeof(randomx::JitCompilerX86::engine[k]), "Pointer size mismatch"); \ memcpy(randomx::JitCompilerX86::engine + k, &p, sizeof(randomx::JitCompilerX86::engine[k])); \
memcpy(randomx::JitCompilerX86::engine + k, &p, sizeof(p)); \
} while (0) } while (0)
#elif (XMRIG_ARM == 8) #elif (XMRIG_ARM == 8)