aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordm4 <dm4@skymizer.com>2019-04-10 20:52:02 +0800
committerhydai <hydai@skymizer.com>2019-04-11 18:22:55 +0800
commit7bde04bcd7a60ca03466cad1991a0eb5ed1aa5ae (patch)
tree939ae00d6b1f56cfe054f3c36bf0dabc067172d2
parent0f7acecfe78a32cf51153f6996969ad67e989ada (diff)
downloaddexon-7bde04bcd7a60ca03466cad1991a0eb5ed1aa5ae.tar.gz
dexon-7bde04bcd7a60ca03466cad1991a0eb5ed1aa5ae.tar.zst
dexon-7bde04bcd7a60ca03466cad1991a0eb5ed1aa5ae.zip
[WIP] add ResetVM()
-rw-r--r--core/vm/dvm/dvm.go6
-rw-r--r--vendor/github.com/go-interpreter/wagon/exec/vm.go13
2 files changed, 16 insertions, 3 deletions
diff --git a/core/vm/dvm/dvm.go b/core/vm/dvm/dvm.go
index c4812e637..ac6deedd5 100644
--- a/core/vm/dvm/dvm.go
+++ b/core/vm/dvm/dvm.go
@@ -474,8 +474,10 @@ func (dvm *DVM) run(contract *vm.Contract, input []byte, ro bool) ([]byte, error
wavm.RecoverPanic = true
dvm.vmCache[contract.CodeHash] = wavm
} else {
- // reset memory if cache hit
- copy(wavm.Memory(), module.LinearMemoryIndexSpace[0])
+ err := wavm.ResetVM()
+ if err != nil {
+ return nil, fmt.Errorf("could not reset the vm: %v", err)
+ }
}
dvm.vm = wavm
diff --git a/vendor/github.com/go-interpreter/wagon/exec/vm.go b/vendor/github.com/go-interpreter/wagon/exec/vm.go
index 7074d8e3a..369c7814b 100644
--- a/vendor/github.com/go-interpreter/wagon/exec/vm.go
+++ b/vendor/github.com/go-interpreter/wagon/exec/vm.go
@@ -160,6 +160,18 @@ func NewVM(module *wasm.Module) (*VM, error) {
return &vm, nil
}
+func (vm *VM) ResetVM() error {
+ vm.abort = false
+ if vm.module.Memory != nil && len(vm.module.Memory.Entries) != 0 {
+ if len(vm.module.Memory.Entries) > 1 {
+ return ErrMultipleLinearMemories
+ }
+ vm.memory = make([]byte, uint(vm.module.Memory.Entries[0].Limits.Initial)*wasmPageSize)
+ copy(vm.memory, vm.module.LinearMemoryIndexSpace[0])
+ }
+ return nil
+}
+
// Memory returns the linear memory space for the VM.
func (vm *VM) Memory() []byte {
return vm.memory
@@ -296,7 +308,6 @@ func (vm *VM) ExecCode(fnIndex int64, args ...uint64) (rtrn interface{}, err err
vm.ctx.pc = 0
vm.ctx.code = compiled.code
vm.ctx.curFunc = fnIndex
- vm.abort = false
for i, arg := range args {
vm.ctx.locals[i] = arg