Browse Source

Replace "bad jump" exit with "abort" exit.

cl-refactor
Paweł Bylica 10 years ago
parent
commit
947b9e9664
  1. 1
      evmjit/include/evmjit/JIT-c.h
  2. 1
      evmjit/include/evmjit/JIT.h
  3. 2
      evmjit/libevmjit-cpp/JitVM.cpp
  4. 30
      evmjit/libevmjit/Compiler.cpp
  5. 7
      evmjit/libevmjit/Compiler.h

1
evmjit/include/evmjit/JIT-c.h

@ -40,7 +40,6 @@ typedef enum evmjit_return_code
// Standard error codes
OutOfGas = -1,
StackUnderflow = -2,
BadJumpDestination = -3,
BadInstruction = -4,
Rejected = -5, ///< Input data (code, gas, block info, etc.) does not meet JIT requirement and execution request has been rejected

1
evmjit/include/evmjit/JIT.h

@ -102,7 +102,6 @@ enum class ReturnCode
// Standard error codes
OutOfGas = -1,
StackUnderflow = -2,
BadJumpDestination = -3,
BadInstruction = -4,
Rejected = -5, ///< Input data (code, gas, block info, etc.) does not meet JIT requirement and execution request has been rejected

2
evmjit/libevmjit-cpp/JitVM.cpp

@ -60,8 +60,6 @@ bytesConstRef JitVM::execImpl(u256& io_gas, ExtVMFace& _ext, OnOpFunc const& _on
_ext.suicide(right160(jit2eth(m_data.address)));
break;
case evmjit::ReturnCode::BadJumpDestination:
BOOST_THROW_EXCEPTION(BadJumpDestination());
case evmjit::ReturnCode::OutOfGas:
BOOST_THROW_EXCEPTION(OutOfGas());
case evmjit::ReturnCode::StackUnderflow: // FIXME: Remove support for detail errors

30
evmjit/libevmjit/Compiler.cpp

@ -94,7 +94,7 @@ void Compiler::createBasicBlocks(code_iterator _codeBegin, code_iterator _codeEn
}
}
llvm::BasicBlock* Compiler::getJumpTableBlock(RuntimeManager& _runtimeManager)
llvm::BasicBlock* Compiler::getJumpTableBlock()
{
if (!m_jumpTableBlock)
{
@ -102,7 +102,7 @@ llvm::BasicBlock* Compiler::getJumpTableBlock(RuntimeManager& _runtimeManager)
InsertPointGuard g{m_builder};
m_builder.SetInsertPoint(m_jumpTableBlock->llvm());
auto dest = m_builder.CreatePHI(Type::Word, 8, "target");
auto switchInstr = m_builder.CreateSwitch(dest, getBadJumpBlock(_runtimeManager));
auto switchInstr = m_builder.CreateSwitch(dest, m_abortBB);
for (auto&& p : m_basicBlocks)
{
if (p.second.isJumpDest())
@ -112,18 +112,6 @@ llvm::BasicBlock* Compiler::getJumpTableBlock(RuntimeManager& _runtimeManager)
return m_jumpTableBlock->llvm();
}
llvm::BasicBlock* Compiler::getBadJumpBlock(RuntimeManager& _runtimeManager)
{
if (!m_badJumpBlock)
{
m_badJumpBlock.reset(new BasicBlock("BadJump", m_mainFunc, m_builder, true));
InsertPointGuard g{m_builder};
m_builder.SetInsertPoint(m_badJumpBlock->llvm());
_runtimeManager.exit(ReturnCode::BadJumpDestination);
}
return m_badJumpBlock->llvm();
}
std::unique_ptr<llvm::Module> Compiler::compile(code_iterator _begin, code_iterator _end, std::string const& _id)
{
auto module = std::unique_ptr<llvm::Module>(new llvm::Module(_id, m_builder.getContext()));
@ -616,7 +604,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, RuntimeManager& _runti
auto&& c = constant->getValue();
auto targetIdx = c.getActiveBits() <= 64 ? c.getZExtValue() : -1;
auto it = m_basicBlocks.find(targetIdx);
targetBlock = (it != m_basicBlocks.end() && it->second.isJumpDest()) ? it->second.llvm() : getBadJumpBlock(_runtimeManager);
targetBlock = (it != m_basicBlocks.end() && it->second.isJumpDest()) ? it->second.llvm() : m_abortBB;
}
// TODO: Improve; check for constants
@ -629,7 +617,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, RuntimeManager& _runti
else
{
_basicBlock.setJumpTarget(target);
m_builder.CreateBr(getJumpTableBlock(_runtimeManager));
m_builder.CreateBr(getJumpTableBlock());
}
}
else // JUMPI
@ -645,7 +633,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, RuntimeManager& _runti
else
{
_basicBlock.setJumpTarget(target);
m_builder.CreateCondBr(cond, getJumpTableBlock(_runtimeManager), _nextBasicBlock);
m_builder.CreateCondBr(cond, getJumpTableBlock(), _nextBasicBlock);
}
}
break;
@ -901,12 +889,6 @@ void Compiler::removeDeadBlocks()
m_jumpTableBlock->llvm()->eraseFromParent();
m_jumpTableBlock.reset();
}
if (m_badJumpBlock && llvm::pred_begin(m_badJumpBlock->llvm()) == llvm::pred_end(m_badJumpBlock->llvm()))
{
m_badJumpBlock->llvm()->eraseFromParent();
m_badJumpBlock.reset();
}
}
void Compiler::dumpCFGifRequired(std::string const& _dotfilePath)
@ -931,8 +913,6 @@ void Compiler::dumpCFGtoStream(std::ostream& _out)
blocks.push_back(&pair.second);
if (m_jumpTableBlock)
blocks.push_back(m_jumpTableBlock.get());
if (m_badJumpBlock)
blocks.push_back(m_badJumpBlock.get());
// std::map<BasicBlock*,int> phiNodesPerBlock;

7
evmjit/libevmjit/Compiler.h

@ -37,9 +37,7 @@ private:
void compileBasicBlock(BasicBlock& _basicBlock, class RuntimeManager& _runtimeManager, class Arith256& _arith, class Memory& _memory, class Ext& _ext, class GasMeter& _gasMeter, llvm::BasicBlock* _nextBasicBlock);
llvm::BasicBlock* getJumpTableBlock(RuntimeManager& _runtimeManager);
llvm::BasicBlock* getBadJumpBlock(RuntimeManager& _runtimeManager);
llvm::BasicBlock* getJumpTableBlock();
void removeDeadBlocks();
@ -70,9 +68,6 @@ private:
/// Block with a jump table.
std::unique_ptr<BasicBlock> m_jumpTableBlock;
/// Destination for invalid jumps
std::unique_ptr<BasicBlock> m_badJumpBlock;
/// Main program function
llvm::Function* m_mainFunc = nullptr;
};

Loading…
Cancel
Save