Browse Source

Merge commit '1990dde405f509086154644e70739fafbe7c61a4' from subtree evmjit/develop into evmjit

Conflicts:
	evmjit/libevmjit/Runtime.cpp
	evmjit/libevmjit/RuntimeData.h
	evmjit/libevmjit/interface.cpp
cl-refactor
Paweł Bylica 10 years ago
parent
commit
f64f5d57aa
  1. 18
      evmjit/libevmjit/Common.h
  2. 1
      evmjit/libevmjit/Runtime.cpp
  3. 2
      evmjit/libevmjit/RuntimeData.h
  4. 6
      evmjit/libevmjit/Stack.cpp
  5. 42
      evmjit/libevmjit/interface.cpp
  6. 13
      evmjit/libevmjit/interface.h

18
evmjit/libevmjit/Common.h

@ -22,14 +22,16 @@ enum class ReturnCode
Return = 1,
Suicide = 2,
BadJumpDestination = 101,
OutOfGas = 102,
StackTooSmall = 103,
BadInstruction = 104,
LLVMConfigError = 201,
LLVMCompileError = 202,
LLVMLinkError = 203,
OutOfGas = -1,
BadJumpDestination = -2,
StackTooSmall = -3,
BadInstruction = -4,
LLVMConfigError = -5,
LLVMCompileError = -6,
LLVMLinkError = -7,
UnexpectedException = -8,
};
/// Representation of 256-bit value binary compatible with LLVM i256

1
evmjit/libevmjit/Runtime.cpp

@ -26,6 +26,7 @@ bytes_ref Runtime::getReturnData() const
if (data < m_memory.data() || data >= m_memory.data() + m_memory.size() || size == 0)
{
assert(size == 0); // data can be an invalid pointer only if size is 0
m_data.callData = nullptr;
return {};
}

2
evmjit/libevmjit/RuntimeData.h

@ -47,7 +47,7 @@ struct RuntimeData
i256 difficulty;
i256 gasLimit;
uint64_t number = 0;
uint64_t timestamp = 0;
int64_t timestamp = 0;
byte const* code = nullptr;
uint64_t codeSize = 0;
};

6
evmjit/libevmjit/Stack.cpp

@ -73,7 +73,7 @@ extern "C"
{
auto& stack = _rt->getStack();
if (stack.size() < _count)
longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
longjmp(_rt->getJmpBuf(), static_cast<int>(ReturnCode::StackTooSmall));
stack.erase(stack.end() - _count, stack.end());
}
@ -92,7 +92,7 @@ extern "C"
auto& stack = _rt->getStack();
// TODO: encode _index and stack size in the return code
if (stack.size() <= _index)
longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
longjmp(_rt->getJmpBuf(), static_cast<int>(ReturnCode::StackTooSmall));
*o_ret = *(stack.rbegin() + _index);
}
@ -102,7 +102,7 @@ extern "C"
auto& stack = _rt->getStack();
// TODO: encode _index and stack size in the return code
if (stack.size() <= _index)
longjmp(_rt->getJmpBuf(), static_cast<uint64_t>(ReturnCode::StackTooSmall));
longjmp(_rt->getJmpBuf(), static_cast<int>(ReturnCode::StackTooSmall));
*(stack.rbegin() + _index) = *_word;
}

42
evmjit/libevmjit/interface.cpp

@ -1,34 +1,36 @@
#include "interface.h"
#include <cstring>
#include "ExecutionEngine.h"
extern "C"
{
evmjit_result evmjit_run(void* _data, void* _env)
{
using namespace dev::eth::jit;
using namespace dev::eth::jit;
auto data = static_cast<RuntimeData*>(_data);
void* evmjit_create() noexcept
{
return new(std::nothrow) ExecutionEngine;
}
ExecutionEngine engine;
void evmjit_destroy(ExecutionEngine* _engine) noexcept
{
delete _engine;
}
auto codePtr = data->code;
auto codeSize = data->codeSize;
bytes bytecode;
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize);
int evmjit_run(ExecutionEngine* _engine, RuntimeData* _data, Env* _env) noexcept
{
try
{
auto codePtr = _data->code;
auto codeSize = _data->codeSize;
bytes bytecode;
bytecode.insert(bytecode.end(), codePtr, codePtr + codeSize);
auto returnCode = engine.run(bytecode, data, static_cast<Env*>(_env));
evmjit_result result = {static_cast<int32_t>(returnCode), 0, nullptr};
if (returnCode == ReturnCode::Return && std::get<0>(engine.returnData))
auto returnCode = _engine->run(bytecode, _data, _env);
return static_cast<int>(returnCode);
}
catch(...)
{
// TODO: Optimized returning data. Allocating memory on client side by callback function might be a good idea
result.returnDataSize = std::get<1>(engine.returnData);
result.returnData = std::malloc(result.returnDataSize);
std::memcpy(result.returnData, std::get<0>(engine.returnData), result.returnDataSize);
return static_cast<int>(ReturnCode::UnexpectedException);
}
return result;
}
}

13
evmjit/libevmjit/interface.h

@ -1,19 +1,12 @@
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct evmjit_result
{
int32_t returnCode;
uint64_t returnDataSize;
void* returnData;
void* evmjit_create();
int evmjit_run(void* _jit, void* _data, void* _env);
void evmjit_destroy(void* _jit);
} evmjit_result;
evmjit_result evmjit_run(void* _data, void* _env);
#ifdef __cplusplus
}

Loading…
Cancel
Save