Optional W^X policy for JIT pages (#112)

This commit is contained in:
tevador
2019-08-25 13:47:40 +02:00
committed by GitHub
parent 971f10c9c2
commit 67010ab554
12 changed files with 195 additions and 55 deletions
+27 -10
View File
@@ -34,27 +34,44 @@ namespace randomx {
static_assert(sizeof(MemoryRegisters) == 2 * sizeof(addr_t) + sizeof(uintptr_t), "Invalid alignment of struct randomx::MemoryRegisters");
static_assert(sizeof(RegisterFile) == 256, "Invalid alignment of struct randomx::RegisterFile");
template<class Allocator, bool softAes>
void CompiledVm<Allocator, softAes>::setDataset(randomx_dataset* dataset) {
template<class Allocator, bool softAes, bool secureJit>
CompiledVm<Allocator, softAes, secureJit>::CompiledVm() {
if (!secureJit) {
compiler.enableAll(); //make JIT buffer both writable and executable
}
}
template<class Allocator, bool softAes, bool secureJit>
void CompiledVm<Allocator, softAes, secureJit>::setDataset(randomx_dataset* dataset) {
datasetPtr = dataset;
}
template<class Allocator, bool softAes>
void CompiledVm<Allocator, softAes>::run(void* seed) {
template<class Allocator, bool softAes, bool secureJit>
void CompiledVm<Allocator, softAes, secureJit>::run(void* seed) {
VmBase<Allocator, softAes>::generateProgram(seed);
randomx_vm::initialize();
if (secureJit) {
compiler.enableWriting();
}
compiler.generateProgram(program, config);
if (secureJit) {
compiler.enableExecution();
}
mem.memory = datasetPtr->memory + datasetOffset;
execute();
}
template<class Allocator, bool softAes>
void CompiledVm<Allocator, softAes>::execute() {
template<class Allocator, bool softAes, bool secureJit>
void CompiledVm<Allocator, softAes, secureJit>::execute() {
compiler.getProgramFunc()(reg, mem, scratchpad, RANDOMX_PROGRAM_ITERATIONS);
}
template class CompiledVm<AlignedAllocator<CacheLineSize>, false>;
template class CompiledVm<AlignedAllocator<CacheLineSize>, true>;
template class CompiledVm<LargePageAllocator, false>;
template class CompiledVm<LargePageAllocator, true>;
template class CompiledVm<AlignedAllocator<CacheLineSize>, false, false>;
template class CompiledVm<AlignedAllocator<CacheLineSize>, true, false>;
template class CompiledVm<LargePageAllocator, false, false>;
template class CompiledVm<LargePageAllocator, true, false>;
template class CompiledVm<AlignedAllocator<CacheLineSize>, false, true>;
template class CompiledVm<AlignedAllocator<CacheLineSize>, true, true>;
template class CompiledVm<LargePageAllocator, false, true>;
template class CompiledVm<LargePageAllocator, true, true>;
}