Fixed panic handling (#1667)

This commit is contained in:
Arkadiy Paronyan
2019-02-04 09:11:29 +01:00
committed by Bastian Köcher
parent 87f0f6fd8f
commit 6c341f4e9d
11 changed files with 94 additions and 18 deletions
+1
View File
@@ -13,6 +13,7 @@ trie = { package = "substrate-trie", path = "../trie" }
serializer = { package = "substrate-serializer", path = "../serializer" }
state_machine = { package = "substrate-state-machine", path = "../state-machine" }
runtime_version = { package = "sr-version", path = "../sr-version" }
panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" }
serde = "1.0"
serde_derive = "1.0"
wasmi = { version = "0.4.3" }
@@ -97,11 +97,9 @@ fn fetch_cached_runtime_version<'a, E: Externalities<Blake2Hasher>>(
fn safe_call<F, U>(f: F) -> Result<U>
where F: UnwindSafe + FnOnce() -> U
{
// Substrate uses custom panic hook that terminates process on panic. Disable it for the native call.
let hook = ::std::panic::take_hook();
let result = ::std::panic::catch_unwind(f).map_err(|_| ErrorKind::Runtime.into());
::std::panic::set_hook(hook);
result
// Substrate uses custom panic hook that terminates process on panic. Disable termination for the native call.
let _guard = panic_handler::AbortGuard::new(false);
::std::panic::catch_unwind(f).map_err(|_| ErrorKind::Runtime.into())
}
/// Set up the externalities and safe calling environment to execute calls to a native runtime.