From 079c59b929d5e09eebad6169c22f146bd2f060af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 26 Jan 2015 18:02:09 +0100 Subject: [PATCH] Update JitVm to new EVM JIT ABI (C interface) --- vm/vm_jit.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/vm/vm_jit.go b/vm/vm_jit.go index 4c0988df9..38cab57da 100644 --- a/vm/vm_jit.go +++ b/vm/vm_jit.go @@ -3,17 +3,10 @@ package vm /* -#include -#include -struct evmjit_result -{ - int32_t returnCode; - uint64_t returnDataSize; - void* returnData; -}; - -struct evmjit_result evmjit_run(void* _data, void* _env); +void* evmjit_create(); +int evmjit_run(void* _jit, void* _data, void* _env); +void evmjit_destroy(void* _jit); // Shared library evmjit (e.g. libevmjit.so) is expected to be installed in /usr/local/lib // More: https://github.com/ethereum/evmjit @@ -188,17 +181,17 @@ func (self *JitVm) Run(me, caller ContextRef, code []byte, value, gas, price *bi self.data.code = getDataPtr(code) self.data.codeSize = uint64(len(code)) - result := C.evmjit_run(unsafe.Pointer(&self.data), unsafe.Pointer(self)) + jit := C.evmjit_create() + retCode := C.evmjit_run(jit, unsafe.Pointer(&self.data), unsafe.Pointer(self)) - if result.returnCode >= 100 { + if retCode < 0 { err = errors.New("OOG from JIT") gas.SetInt64(0) // Set gas to 0, JIT does not bother } else { gas.SetInt64(self.data.gas) - if result.returnCode == 1 { // RETURN - ret = C.GoBytes(result.returnData, C.int(result.returnDataSize)) - C.free(result.returnData) - } else if result.returnCode == 2 { // SUICIDE + if retCode == 1 { // RETURN + ret = C.GoBytes(unsafe.Pointer(self.data.callData), C.int(self.data.callDataSize)) + } else if retCode == 2 { // SUICIDE // TODO: Suicide support logic should be moved to Env to be shared by VM implementations state := self.Env().State() receiverAddr := llvm2hashRef(bswap(&self.data.address)) @@ -208,7 +201,8 @@ func (self *JitVm) Run(me, caller ContextRef, code []byte, value, gas, price *bi state.Delete(me.Address()) } } - + + C.evmjit_destroy(jit); return }