tevador / RandomX

Proof of work algorithm based on random code execution
BSD 3-Clause "New" or "Revised" License
1.38k stars 292 forks source link

Crash on Apple Silicon #293

Closed dr-bestore closed 2 months ago

dr-bestore commented 2 months ago

Hi guys, I'm encountering a crash when integrating randomx to a Swift project and using JIT flag to calculate hash on Apple Silicon device.

    template<class Allocator, bool softAes, bool secureJit>
    void CompiledVm<Allocator, softAes, secureJit>::execute() {
#ifdef __aarch64__
        memcpy(reg.f, config.eMask, sizeof(config.eMask));
#endif
        compiler.getProgramFunc()(reg, mem, scratchpad, RANDOMX_PROGRAM_ITERATIONS); // <- Thread 2: EXC_BAD_ACCESS (code=2, address=0x104374000)
    }

Does anyone has idea for this problem?

SChernykh commented 2 months ago

RandomX works on Apple silicon. Did you test randomx-benchmark from this repository, without any of your modifications? The error you get is caused by "executable" flag not set for the JIT code.

dr-bestore commented 2 months ago

Thanks for the reply! Yes it works perfect. I checked the compiler.code which was set but seemed not working. btw I just linked the .a built from cmake&make without any modification, did I miss something for that?

SChernykh commented 2 months ago

You probably don't set SECURE_JIT flag when you set up RandomX VM, it's mandatory for Apple silicon.

dr-bestore commented 2 months ago

Cool thanks! It's working with secure flag now.