Browse Source

Handle bad instructions (BadInstruction exception) [#81563132]

cl-refactor
Paweł Bylica 10 years ago
parent
commit
6da6f3dc52
  1. 1
      evmcc/test/except/badinst1.evm
  2. 5
      libevmjit/Compiler.cpp
  3. 3
      libevmjit/Type.h
  4. 11
      libevmjit/VM.cpp

1
evmcc/test/except/badinst1.evm

@ -0,0 +1 @@
4a

5
libevmjit/Compiler.cpp

@ -816,6 +816,11 @@ void Compiler::compileBasicBlock(BasicBlock& basicBlock, bytesConstRef bytecode,
break;
}
default: // Invalid instruction - runtime exception
{
_runtimeManager.raiseException(ReturnCode::BadInstruction);
}
}
}

3
libevmjit/Type.h

@ -43,7 +43,8 @@ enum class ReturnCode
BadJumpDestination = 101,
OutOfGas = 102,
StackTooSmall = 103
StackTooSmall = 103,
BadInstruction = 104,
};
struct Constant

11
libevmjit/VM.cpp

@ -5,6 +5,7 @@
#include "ExecutionEngine.h"
#include "Compiler.h"
#include "Type.h"
namespace dev
{
@ -20,14 +21,16 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const&, uint64_t)
ExecutionEngine engine;
auto exitCode = engine.run(std::move(module), m_gas, &_ext);
switch (exitCode)
switch (static_cast<ReturnCode>(exitCode))
{
case 101:
case ReturnCode::BadJumpDestination:
BOOST_THROW_EXCEPTION(BadJumpDestination());
case 102:
case ReturnCode::OutOfGas:
BOOST_THROW_EXCEPTION(OutOfGas());
case 103:
case ReturnCode::StackTooSmall:
BOOST_THROW_EXCEPTION(StackTooSmall(1,0));
case ReturnCode::BadInstruction:
BOOST_THROW_EXCEPTION(BadInstruction());
}
m_output = std::move(engine.returnData);

Loading…
Cancel
Save