Handle bad instructions (BadInstruction exception) [#81563132]

This commit is contained in:
Paweł Bylica 2014-10-28 18:15:58 +01:00
parent ac38bf9ac1
commit 6da6f3dc52
4 changed files with 15 additions and 5 deletions

View file

@ -0,0 +1 @@
4a

View file

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

View file

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

View file

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