| 492 | } |
| 493 | |
| 494 | bool WasmHandleBase::canary(const std::shared_ptr<PluginBase> &plugin, |
| 495 | const WasmHandleCloneFactory &clone_factory) { |
| 496 | if (this->wasm() == nullptr) { |
| 497 | return false; |
| 498 | } |
| 499 | auto it = plugin_canary_cache_.find(plugin->key()); |
| 500 | if (it != plugin_canary_cache_.end()) { |
| 501 | return it->second; |
| 502 | } |
| 503 | auto configuration_canary_handle = clone_factory(shared_from_this()); |
| 504 | if (!configuration_canary_handle) { |
| 505 | this->wasm()->fail(FailState::UnableToCloneVm, "Failed to clone Base Wasm"); |
| 506 | return false; |
| 507 | } |
| 508 | if (!configuration_canary_handle->wasm()->initialize()) { |
| 509 | configuration_canary_handle->wasm()->fail(FailState::UnableToInitializeCode, |
| 510 | "Failed to initialize Wasm code"); |
| 511 | return false; |
| 512 | } |
| 513 | auto *root_context = configuration_canary_handle->wasm()->start(plugin); |
| 514 | if (root_context == nullptr) { |
| 515 | configuration_canary_handle->wasm()->fail(FailState::StartFailed, "Failed to start base Wasm"); |
| 516 | return false; |
| 517 | } |
| 518 | if (!configuration_canary_handle->wasm()->configure(root_context, plugin)) { |
| 519 | configuration_canary_handle->wasm()->fail(FailState::ConfigureFailed, |
| 520 | "Failed to configure base Wasm plugin"); |
| 521 | plugin_canary_cache_[plugin->key()] = false; |
| 522 | return false; |
| 523 | } |
| 524 | configuration_canary_handle->kill(); |
| 525 | plugin_canary_cache_[plugin->key()] = true; |
| 526 | return true; |
| 527 | } |
| 528 | |
| 529 | std::shared_ptr<WasmHandleBase> createWasm(const std::string &vm_key, const std::string &code, |
| 530 | const std::shared_ptr<PluginBase> &plugin, |
no test coverage detected