mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Changes in setjmps
This commit is contained in:
parent
dbf8174fc6
commit
70279f8679
6 changed files with 49 additions and 13 deletions
|
|
@ -67,6 +67,9 @@ extern "C"
|
|||
|
||||
EXPORT bool env_call(ExtVMFace* _env, i256* io_gas, h256* _receiveAddress, i256* _value, byte* _inBeg, uint64_t _inSize, byte* _outBeg, uint64_t _outSize, h256* _codeAddress)
|
||||
{
|
||||
if (_env->depth == 1024)
|
||||
jit::terminate(jit::ReturnCode::OutOfGas);
|
||||
|
||||
assert(_env->depth < 1024); // TODO: Handle call depth
|
||||
|
||||
auto value = llvm2eth(*_value);
|
||||
|
|
|
|||
|
|
@ -110,9 +110,9 @@ ReturnCode ExecutionEngine::run(std::unique_ptr<llvm::Module> _module, RuntimeDa
|
|||
ReturnCode ExecutionEngine::run(ExecBundle const& _exec, RuntimeData* _data, Env* _env)
|
||||
{
|
||||
ReturnCode returnCode;
|
||||
std::jmp_buf buf;
|
||||
Runtime runtime(_data, _env, buf);
|
||||
auto r = setjmp(buf);
|
||||
Runtime runtime(_data, _env);
|
||||
|
||||
auto r = setjmp(runtime.getJmpBuf());
|
||||
if (r == 0)
|
||||
{
|
||||
auto result = _exec.engine->runFunction(_exec.entryFunc, {{}, llvm::GenericValue(&runtime)});
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <llvm/IR/Function.h>
|
||||
#include <llvm/IR/IntrinsicInst.h>
|
||||
|
||||
//#include <libevm/VM.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
|
@ -13,12 +13,31 @@ namespace eth
|
|||
{
|
||||
namespace jit
|
||||
{
|
||||
namespace
|
||||
{
|
||||
jmp_buf_ref g_currJmpBuf;
|
||||
}
|
||||
|
||||
Runtime::Runtime(RuntimeData* _data, Env* _env, JmpBufRef _jmpBuf):
|
||||
jmp_buf_ref Runtime::getCurrJmpBuf()
|
||||
{
|
||||
return g_currJmpBuf;
|
||||
}
|
||||
|
||||
Runtime::Runtime(RuntimeData* _data, Env* _env):
|
||||
m_data(*_data),
|
||||
m_env(*_env),
|
||||
m_jmpBuf(_jmpBuf)
|
||||
{}
|
||||
m_currJmpBuf(m_jmpBuf),
|
||||
m_prevJmpBuf(g_currJmpBuf)
|
||||
{
|
||||
g_currJmpBuf = m_jmpBuf;
|
||||
std::cerr << "JB push " << g_currJmpBuf << "\n";
|
||||
}
|
||||
|
||||
Runtime::~Runtime()
|
||||
{
|
||||
std::cerr << "JB pop " << g_currJmpBuf << "\n";
|
||||
g_currJmpBuf = m_prevJmpBuf;
|
||||
}
|
||||
|
||||
u256 Runtime::getGas() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,12 +26,13 @@ namespace jit
|
|||
|
||||
using StackImpl = std::vector<i256>;
|
||||
using MemoryImpl = bytes;
|
||||
using JmpBufRef = decltype(&jmp_buf{}[0]);
|
||||
using jmp_buf_ref = decltype(&std::jmp_buf{}[0]);
|
||||
|
||||
class Runtime
|
||||
{
|
||||
public:
|
||||
Runtime(RuntimeData* _data, Env* _env, JmpBufRef _jmpBuf);
|
||||
Runtime(RuntimeData* _data, Env* _env);
|
||||
~Runtime();
|
||||
|
||||
Runtime(const Runtime&) = delete;
|
||||
void operator=(const Runtime&) = delete;
|
||||
|
|
@ -42,12 +43,15 @@ public:
|
|||
|
||||
u256 getGas() const;
|
||||
bytes getReturnData() const;
|
||||
JmpBufRef getJmpBuf() { return m_jmpBuf; }
|
||||
jmp_buf_ref getJmpBuf() { return m_jmpBuf; }
|
||||
static jmp_buf_ref getCurrJmpBuf();
|
||||
|
||||
private:
|
||||
RuntimeData& m_data;
|
||||
Env& m_env;
|
||||
JmpBufRef m_jmpBuf;
|
||||
RuntimeData& m_data; ///< Pointer to data. Expected by compiled contract.
|
||||
Env& m_env; ///< Pointer to environment proxy. Expected by compiled contract.
|
||||
jmp_buf_ref m_currJmpBuf; ///< Pointer to jump buffer. Expected by compiled contract.
|
||||
jmp_buf_ref m_prevJmpBuf;
|
||||
std::jmp_buf m_jmpBuf;
|
||||
StackImpl m_stack;
|
||||
MemoryImpl m_memory;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include <csetjmp>
|
||||
#include "Utils.h"
|
||||
#include "Instruction.h"
|
||||
#include "Runtime.h"
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
|
@ -53,6 +55,12 @@ u256 readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end)
|
|||
return value;
|
||||
}
|
||||
|
||||
void terminate(ReturnCode _returnCode)
|
||||
{
|
||||
auto jmpBuf = Runtime::getCurrJmpBuf();
|
||||
std::longjmp(jmpBuf, static_cast<int>(_returnCode));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ struct JIT: public NoteChannel { static const char* name() { return "JIT"; } };
|
|||
u256 llvm2eth(i256);
|
||||
i256 eth2llvm(u256);
|
||||
|
||||
void terminate(ReturnCode _returnCode);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue