From 93bcd45b69758f4529052251cafd923017303821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20Leegwater=20Sim=C3=B5es?= Date: Thu, 24 Aug 2023 21:41:16 +0200 Subject: [PATCH] piecrust: `init_traps` before making any memories This is necessary to ensure that the handler for segfaults in `crumbles` is properly set, instead of using the default `wasmer` handler. --- piecrust/src/vm.rs | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/piecrust/src/vm.rs b/piecrust/src/vm.rs index 858c08a9..c32f2e5d 100644 --- a/piecrust/src/vm.rs +++ b/piecrust/src/vm.rs @@ -12,6 +12,7 @@ use std::sync::Arc; use std::thread; use tempfile::tempdir; +use wasmer_vm::init_traps; use crate::session::{Session, SessionData}; use crate::store::ContractStore; @@ -53,6 +54,8 @@ impl VM { /// # Errors /// If the directory contains unparseable or inconsistent data. pub fn new>(root_dir: P) -> Result { + init_traps(); + let store = ContractStore::new(root_dir) .map_err(|err| PersistenceError(Arc::new(err)))?; Ok(Self { @@ -69,6 +72,8 @@ impl VM { /// # Errors /// If creating a temporary directory fails. pub fn ephemeral() -> Result { + init_traps(); + let tmp = tempdir().map_err(|err| PersistenceError(Arc::new(err)))?; let tmp = tmp.path().to_path_buf(); @@ -125,27 +130,6 @@ impl VM { self.store.commits().into_iter().map(Into::into).collect() } - /// Remove the diff files from a commit by applying them to the base - /// memories, and writing them back to disk. - /// - /// # Errors - /// If this function fails, it may be due to any number of reasons: - /// - /// - [`remove_file`] may fail - /// - [`write`] may fail - /// - /// Failing may result in a corrupted commit, and the user is encouraged to - /// call [`delete_commit`]. - /// - /// [`remove_file`]: std::fs::remove_file - /// [`write`]: std::fs::write - /// [`delete_commit`]: VM::delete_commit - pub fn squash_commit(&self, root: [u8; 32]) -> Result<(), Error> { - self.store - .squash_commit(root.into()) - .map_err(|err| PersistenceError(Arc::new(err))) - } - /// Deletes the given commit from disk. pub fn delete_commit(&self, root: [u8; 32]) -> Result<(), Error> { self.store