Browse Source

Suicide rework

cl-refactor
Paweł Bylica 10 years ago
parent
commit
e12fa127f4
  1. 5
      libevmjit-cpp/Env.cpp
  2. 4
      libevmjit-cpp/JitVM.cpp
  3. 11
      libevmjit/Compiler.cpp
  4. 8
      libevmjit/Ext.cpp
  5. 2
      libevmjit/Ext.h
  6. 4
      libevmjit/RuntimeData.h
  7. 5
      libevmjit/RuntimeManager.cpp
  8. 1
      libevmjit/RuntimeManager.h

5
libevmjit-cpp/Env.cpp

@ -42,11 +42,6 @@ extern "C"
*o_value = eth2llvm(u);
}
EXPORT void ext_suicide(ExtVMFace* _env, h256 const* _address)
{
_env->suicide(right160(*_address));
}
EXPORT void env_create(ExtVMFace* _env, i256* io_gas, i256* _endowment, byte* _initBeg, uint64_t _initSize, h256* o_address)
{
if (_env->depth == 1024)

4
libevmjit-cpp/JitVM.cpp

@ -34,6 +34,10 @@ bytesConstRef JitVM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
auto exitCode = m_engine.run(_ext.code, &m_data, env);
switch (exitCode)
{
case ReturnCode::Suicide:
_ext.suicide(right160(m_data.get(RuntimeData::SuicideDestAddress)));
break;
case ReturnCode::BadJumpDestination:
BOOST_THROW_EXCEPTION(BadJumpDestination());
case ReturnCode::OutOfGas:

11
libevmjit/Compiler.cpp

@ -798,14 +798,15 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode
}
case Instruction::SUICIDE:
case Instruction::STOP:
{
if (inst == Instruction::SUICIDE)
{
auto address = stack.pop();
_ext.suicide(address);
_runtimeManager.registerSuicide(stack.pop());
m_builder.CreateRet(Constant::get(ReturnCode::Suicide));
break;
}
case Instruction::STOP:
{
m_builder.CreateRet(Constant::get(ReturnCode::Stop));
break;
}

8
libevmjit/Ext.cpp

@ -44,7 +44,6 @@ Ext::Ext(RuntimeManager& _runtimeManager, Memory& _memoryMan):
m_sload = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "env_sload", module);
m_sstore = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "env_sstore", module);
m_balance = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 3}, false), Linkage::ExternalLinkage, "ext_balance", module);
m_suicide = llvm::Function::Create(llvm::FunctionType::get(Type::Void, {argsTypes, 2}, false), Linkage::ExternalLinkage, "ext_suicide", module);
llvm::Type* sha3ArgsTypes[] = {Type::BytePtr, Type::Size, Type::WordPtr};
m_sha3 = llvm::Function::Create(llvm::FunctionType::get(Type::Void, sha3ArgsTypes, false), Linkage::ExternalLinkage, "env_sha3", module);
@ -96,13 +95,6 @@ llvm::Value* Ext::balance(llvm::Value* _address)
return m_builder.CreateLoad(m_args[1]);
}
void Ext::suicide(llvm::Value* _address)
{
auto address = Endianness::toBE(m_builder, _address);
m_builder.CreateStore(address, m_args[0]);
m_builder.CreateCall2(m_suicide, getRuntimeManager().getEnvPtr(), m_args[0]);
}
llvm::Value* Ext::create(llvm::Value*& _gas, llvm::Value* _endowment, llvm::Value* _initOff, llvm::Value* _initSize)
{
m_builder.CreateStore(_gas, m_args[0]);

2
libevmjit/Ext.h

@ -27,7 +27,6 @@ public:
void sstore(llvm::Value* _index, llvm::Value* _value);
llvm::Value* balance(llvm::Value* _address);
void suicide(llvm::Value* _address);
llvm::Value* calldataload(llvm::Value* _index);
llvm::Value* create(llvm::Value*& _gas, llvm::Value* _endowment, llvm::Value* _initOff, llvm::Value* _initSize);
llvm::Value* call(llvm::Value*& _gas, llvm::Value* _receiveAddress, llvm::Value* _value, llvm::Value* _inOff, llvm::Value* _inSize, llvm::Value* _outOff, llvm::Value* _outSize, llvm::Value* _codeAddress);
@ -54,7 +53,6 @@ private:
llvm::Function* m_sstore;
llvm::Function* m_calldataload;
llvm::Function* m_balance;
llvm::Function* m_suicide;
llvm::Function* m_create;
llvm::Function* m_call;
llvm::Function* m_sha3;

4
libevmjit/RuntimeData.h

@ -32,7 +32,8 @@ struct RuntimeData
_size,
ReturnDataOffset = CallValue, // Reuse 2 fields for return data reference
ReturnDataSize = CallDataSize
ReturnDataSize = CallDataSize,
SuicideDestAddress = Address, ///< Suicide balance destination address
};
i256 elems[_size] = {};
@ -40,6 +41,7 @@ struct RuntimeData
byte const* code = nullptr;
void set(Index _index, u256 _value) { elems[_index] = eth2llvm(_value); }
u256 get(Index _index) { return llvm2eth(elems[_index]); }
};
/// VM Environment (ExtVM) opaque type

5
libevmjit/RuntimeManager.cpp

@ -132,6 +132,11 @@ void RuntimeManager::registerReturnData(llvm::Value* _offset, llvm::Value* _size
set(RuntimeData::ReturnDataSize, _size);
}
void RuntimeManager::registerSuicide(llvm::Value* _balanceAddress)
{
set(RuntimeData::SuicideDestAddress, _balanceAddress);
}
void RuntimeManager::raiseException(ReturnCode _returnCode)
{
m_builder.CreateCall2(m_longjmp, getJmpBuf(), Constant::get(_returnCode));

1
libevmjit/RuntimeManager.h

@ -29,6 +29,7 @@ public:
void setGas(llvm::Value* _gas);
void registerReturnData(llvm::Value* _index, llvm::Value* _size);
void registerSuicide(llvm::Value* _balanceAddress);
void raiseException(ReturnCode _returnCode);

Loading…
Cancel
Save