mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +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)
|
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
|
assert(_env->depth < 1024); // TODO: Handle call depth
|
||||||
|
|
||||||
auto value = llvm2eth(*_value);
|
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 ExecutionEngine::run(ExecBundle const& _exec, RuntimeData* _data, Env* _env)
|
||||||
{
|
{
|
||||||
ReturnCode returnCode;
|
ReturnCode returnCode;
|
||||||
std::jmp_buf buf;
|
Runtime runtime(_data, _env);
|
||||||
Runtime runtime(_data, _env, buf);
|
|
||||||
auto r = setjmp(buf);
|
auto r = setjmp(runtime.getJmpBuf());
|
||||||
if (r == 0)
|
if (r == 0)
|
||||||
{
|
{
|
||||||
auto result = _exec.engine->runFunction(_exec.entryFunc, {{}, llvm::GenericValue(&runtime)});
|
auto result = _exec.engine->runFunction(_exec.entryFunc, {{}, llvm::GenericValue(&runtime)});
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <llvm/IR/Function.h>
|
#include <llvm/IR/Function.h>
|
||||||
#include <llvm/IR/IntrinsicInst.h>
|
#include <llvm/IR/IntrinsicInst.h>
|
||||||
|
|
||||||
//#include <libevm/VM.h>
|
#include <iostream>
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
@ -13,12 +13,31 @@ namespace eth
|
||||||
{
|
{
|
||||||
namespace jit
|
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_data(*_data),
|
||||||
m_env(*_env),
|
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
|
u256 Runtime::getGas() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,13 @@ namespace jit
|
||||||
|
|
||||||
using StackImpl = std::vector<i256>;
|
using StackImpl = std::vector<i256>;
|
||||||
using MemoryImpl = bytes;
|
using MemoryImpl = bytes;
|
||||||
using JmpBufRef = decltype(&jmp_buf{}[0]);
|
using jmp_buf_ref = decltype(&std::jmp_buf{}[0]);
|
||||||
|
|
||||||
class Runtime
|
class Runtime
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Runtime(RuntimeData* _data, Env* _env, JmpBufRef _jmpBuf);
|
Runtime(RuntimeData* _data, Env* _env);
|
||||||
|
~Runtime();
|
||||||
|
|
||||||
Runtime(const Runtime&) = delete;
|
Runtime(const Runtime&) = delete;
|
||||||
void operator=(const Runtime&) = delete;
|
void operator=(const Runtime&) = delete;
|
||||||
|
|
@ -42,12 +43,15 @@ public:
|
||||||
|
|
||||||
u256 getGas() const;
|
u256 getGas() const;
|
||||||
bytes getReturnData() const;
|
bytes getReturnData() const;
|
||||||
JmpBufRef getJmpBuf() { return m_jmpBuf; }
|
jmp_buf_ref getJmpBuf() { return m_jmpBuf; }
|
||||||
|
static jmp_buf_ref getCurrJmpBuf();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RuntimeData& m_data;
|
RuntimeData& m_data; ///< Pointer to data. Expected by compiled contract.
|
||||||
Env& m_env;
|
Env& m_env; ///< Pointer to environment proxy. Expected by compiled contract.
|
||||||
JmpBufRef m_jmpBuf;
|
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;
|
StackImpl m_stack;
|
||||||
MemoryImpl m_memory;
|
MemoryImpl m_memory;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
|
#include <csetjmp>
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
#include "Instruction.h"
|
#include "Instruction.h"
|
||||||
|
#include "Runtime.h"
|
||||||
|
|
||||||
namespace dev
|
namespace dev
|
||||||
{
|
{
|
||||||
|
|
@ -53,6 +55,12 @@ u256 readPushData(bytes::const_iterator& _curr, bytes::const_iterator _end)
|
||||||
return value;
|
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);
|
u256 llvm2eth(i256);
|
||||||
i256 eth2llvm(u256);
|
i256 eth2llvm(u256);
|
||||||
|
|
||||||
|
void terminate(ReturnCode _returnCode);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue