From bae4c9f84f86574c1fdcb7398e0b78a61cc5c8f1 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 7 Dec 2023 14:07:21 +0900 Subject: [PATCH] refactor: make `bind_syscalls` an associated function The result of this function is cached and not tied to any given kernel. It shouldn't have access to a particular kernel's state because the "result" of calling this function will be used with multiple kernels (of the same type). --- fvm/src/engine/mod.rs | 8 +------- fvm/src/kernel/mod.rs | 2 +- fvm/src/syscalls/mod.rs | 8 ++------ testing/conformance/src/vm.rs | 5 +---- 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/fvm/src/engine/mod.rs b/fvm/src/engine/mod.rs index 60d6e7ff0..8fa9d3e35 100644 --- a/fvm/src/engine/mod.rs +++ b/fvm/src/engine/mod.rs @@ -515,13 +515,7 @@ impl Engine { .insert({ let mut linker = Linker::new(&self.inner.engine); linker.allow_shadowing(true); - - store - .data() - .kernel - .bind_syscalls(&mut linker) - .map_err(Abort::Fatal)?; - + K::bind_syscalls(&mut linker).map_err(Abort::Fatal)?; Box::new(Cache { linker }) }) .downcast_mut() diff --git a/fvm/src/kernel/mod.rs b/fvm/src/kernel/mod.rs index b0fe0055b..7886063f5 100644 --- a/fvm/src/kernel/mod.rs +++ b/fvm/src/kernel/mod.rs @@ -95,7 +95,7 @@ pub trait Kernel: GasOps + SyscallHandler + 'static { } pub trait SyscallHandler: Sized { - fn bind_syscalls(&self, linker: &mut Linker>) -> anyhow::Result<()>; + fn bind_syscalls(linker: &mut Linker>) -> anyhow::Result<()>; } /// Network-related operations. diff --git a/fvm/src/syscalls/mod.rs b/fvm/src/syscalls/mod.rs index 9541c1a0d..ddf555723 100644 --- a/fvm/src/syscalls/mod.rs +++ b/fvm/src/syscalls/mod.rs @@ -253,10 +253,7 @@ where + RandomnessOps + SelfOps, { - fn bind_syscalls( - &self, - linker: &mut wasmtime::Linker>, - ) -> anyhow::Result<()> { + fn bind_syscalls(linker: &mut wasmtime::Linker>) -> anyhow::Result<()> { linker.bind("vm", "exit", vm::exit)?; linker.bind("vm", "message_context", vm::message_context)?; @@ -338,10 +335,9 @@ where C: CallManager, { fn bind_syscalls( - &self, linker: &mut Linker>>>, ) -> anyhow::Result<()> { - self.0.bind_syscalls(linker)?; + DefaultKernel::::bind_syscalls(linker)?; // Bind the circulating supply call. linker.bind( diff --git a/testing/conformance/src/vm.rs b/testing/conformance/src/vm.rs index 6c0642124..ba721b436 100644 --- a/testing/conformance/src/vm.rs +++ b/testing/conformance/src/vm.rs @@ -249,10 +249,7 @@ where C: CallManager>, K: Kernel, { - fn bind_syscalls( - &self, - _linker: &mut Linker>>, - ) -> anyhow::Result<()> { + fn bind_syscalls(_linker: &mut Linker>>) -> anyhow::Result<()> { Ok(()) } }