message: Implement hard exit for smart contracts
diff: @@ -38,6 +38,10 @@ namespace eosio { namespace chain {
  using namespace webassembly;
  using namespace webassembly::common;
  + struct wasm_exit {
  + int32_t code = 0;
  + };
  +
  /**
  * Implementation class for the wasm cache
  * it is responsible for compiling and storing instances of wasm code for use
  @@ -337,6 +341,7 @@ namespace eosio { namespace chain {
  }
  void wasm_interface::apply( wasm_cache::entry& code, apply_context& context, vm_type vm ) {
  + try {
  auto context_guard = scoped_context(my->current_context, code, context, vm);
  switch (vm) {
  case vm_type::wavm:
  @@ -346,9 +351,11 @@ namespace eosio { namespace chain {
  code.binaryen.call_apply(context);
  break;
  }
  + } catch ( const wasm_exit& ){}
  }
  void wasm_interface::error( wasm_cache::entry& code, apply_context& context, vm_type vm ) {
  + try {
  auto context_guard = scoped_context(my->current_context, code, context, vm);
  switch (vm) {
  case vm_type::wavm:
  @@ -358,6 +365,7 @@ namespace eosio { namespace chain {
  code.binaryen.call_error(context);
  break;
  }
  + } catch ( const wasm_exit& ){}
  }
  wasm_context& common::intrinsics_accessor::get_context(wasm_interface &wasm) {
  @@ -818,6 +826,10 @@ class system_api : public context_aware_api {
  }
  }
  + void eosio_exit(int32_t code) {
  + throw wasm_exit{code};
  + }
  +
  fc::time_point_sec now() {
  return context.controller.head_block_time();
  }
  @@ -1763,6 +1775,7 @@ REGISTER_INTRINSICS(string_api,
  REGISTER_INTRINSICS(system_api,
  (abort, void())
  (eosio_assert, void(int, int))
  + (eosio_exit, void(int ))
  (now, int())
  );
  