Monero
Loading...
Searching...
No Matches
vm_interpreted.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the copyright holder nor the
14 names of its contributors may be used to endorse or promote products
15 derived from this software without specific prior written permission.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#pragma once
30
31#include <new>
32#include <vector>
33#include "common.hpp"
34#include "virtual_machine.hpp"
35#include "bytecode_machine.hpp"
36#include "intrin_portable.h"
37#include "allocator.hpp"
38
39namespace randomx {
40
41 template<class Allocator, bool softAes>
42 class InterpretedVm : public VmBase<Allocator, softAes>, public BytecodeMachine {
43 public:
44 using VmBase<Allocator, softAes>::mem;
45 using VmBase<Allocator, softAes>::scratchpad;
46 using VmBase<Allocator, softAes>::program;
47 using VmBase<Allocator, softAes>::config;
48 using VmBase<Allocator, softAes>::reg;
49 using VmBase<Allocator, softAes>::datasetPtr;
50 using VmBase<Allocator, softAes>::datasetOffset;
51 void* operator new(size_t size) {
53 if (ptr == nullptr)
54 throw std::bad_alloc();
55 return ptr;
56 }
57 void operator delete(void* ptr) {
59 }
60 void run(void* seed) override;
61 void setDataset(randomx_dataset* dataset) override;
62 protected:
63 virtual void datasetRead(uint64_t blockNumber, int_reg_t(&r)[RegistersCount]);
64 virtual void datasetPrefetch(uint64_t blockNumber);
65 private:
66 void execute();
67
69 };
70
75}
Definition bytecode_machine.hpp:108
Definition vm_interpreted.hpp:42
virtual void datasetPrefetch(uint64_t blockNumber)
Definition vm_interpreted.cpp:123
InstructionByteCode bytecode[RANDOMX_PROGRAM_SIZE]
Definition vm_interpreted.hpp:68
void run(void *seed) override
Definition vm_interpreted.cpp:49
void setDataset(randomx_dataset *dataset) override
Definition vm_interpreted.cpp:43
virtual void datasetRead(uint64_t blockNumber, int_reg_t(&r)[RegistersCount])
Definition vm_interpreted.cpp:116
void execute()
Definition vm_interpreted.cpp:56
Definition virtual_machine.hpp:80
uint64_t datasetOffset
Definition virtual_machine.hpp:71
randomx::MemoryRegisters mem
Definition virtual_machine.hpp:65
uint8_t * scratchpad
Definition virtual_machine.hpp:66
randomx::RegisterFile reg
Definition virtual_machine.hpp:63
randomx::ProgramConfiguration config
Definition virtual_machine.hpp:64
randomx_dataset * datasetPtr
Definition virtual_machine.hpp:69
randomx::Program program
Definition virtual_machine.hpp:62
Concept for allocating, resizing and freeing memory block.
const uint8_t seed[32]
Definition code-generator.cpp:37
#define RANDOMX_PROGRAM_SIZE
Definition configuration.h:56
Definition allocator.cpp:35
uint64_t int_reg_t
Definition common.hpp:140
InterpretedVm< LargePageAllocator, false > InterpretedVmLargePageHardAes
Definition vm_interpreted.hpp:74
InterpretedVm< AlignedAllocator< CacheLineSize >, false > InterpretedVmHardAes
Definition vm_interpreted.hpp:72
InterpretedVm< AlignedAllocator< CacheLineSize >, true > InterpretedVmDefault
Definition vm_interpreted.hpp:71
constexpr int RegistersCount
Definition common.hpp:156
InterpretedVm< LargePageAllocator, true > InterpretedVmLargePage
Definition vm_interpreted.hpp:73
unsigned __int64 uint64_t
Definition stdint.h:136
static void * allocMemory(size_t)
Definition allocator.cpp:38
static void freeMemory(void *, size_t)
Definition allocator.cpp:46
Definition bytecode_machine.hpp:46
Definition dataset.hpp:40