@@ -34,27 +34,44 @@ namespace randomx {
3434 static_assert (sizeof (MemoryRegisters) == 2 * sizeof (addr_t ) + sizeof (uintptr_t ), " Invalid alignment of struct randomx::MemoryRegisters" );
3535 static_assert (sizeof (RegisterFile) == 256 , " Invalid alignment of struct randomx::RegisterFile" );
3636
37- template <class Allocator , bool softAes>
38- void CompiledVm<Allocator, softAes>::setDataset(randomx_dataset* dataset) {
37+ template <class Allocator , bool softAes, bool secureJit>
38+ CompiledVm<Allocator, softAes, secureJit>::CompiledVm() {
39+ if (!secureJit) {
40+ compiler.enableAll (); // make JIT buffer both writable and executable
41+ }
42+ }
43+
44+ template <class Allocator , bool softAes, bool secureJit>
45+ void CompiledVm<Allocator, softAes, secureJit>::setDataset(randomx_dataset* dataset) {
3946 datasetPtr = dataset;
4047 }
4148
42- template <class Allocator , bool softAes>
43- void CompiledVm<Allocator, softAes>::run(void * seed) {
49+ template <class Allocator , bool softAes, bool secureJit >
50+ void CompiledVm<Allocator, softAes, secureJit >::run(void * seed) {
4451 VmBase<Allocator, softAes>::generateProgram (seed);
4552 randomx_vm::initialize ();
53+ if (secureJit) {
54+ compiler.enableWriting ();
55+ }
4656 compiler.generateProgram (program, config);
57+ if (secureJit) {
58+ compiler.enableExecution ();
59+ }
4760 mem.memory = datasetPtr->memory + datasetOffset;
4861 execute ();
4962 }
5063
51- template <class Allocator , bool softAes>
52- void CompiledVm<Allocator, softAes>::execute() {
64+ template <class Allocator , bool softAes, bool secureJit >
65+ void CompiledVm<Allocator, softAes, secureJit >::execute() {
5366 compiler.getProgramFunc ()(reg, mem, scratchpad, RANDOMX_PROGRAM_ITERATIONS);
5467 }
5568
56- template class CompiledVm <AlignedAllocator<CacheLineSize>, false >;
57- template class CompiledVm <AlignedAllocator<CacheLineSize>, true >;
58- template class CompiledVm <LargePageAllocator, false >;
59- template class CompiledVm <LargePageAllocator, true >;
69+ template class CompiledVm <AlignedAllocator<CacheLineSize>, false , false >;
70+ template class CompiledVm <AlignedAllocator<CacheLineSize>, true , false >;
71+ template class CompiledVm <LargePageAllocator, false , false >;
72+ template class CompiledVm <LargePageAllocator, true , false >;
73+ template class CompiledVm <AlignedAllocator<CacheLineSize>, false , true >;
74+ template class CompiledVm <AlignedAllocator<CacheLineSize>, true , true >;
75+ template class CompiledVm <LargePageAllocator, false , true >;
76+ template class CompiledVm <LargePageAllocator, true , true >;
6077}
0 commit comments