Skip to content

Commit

Permalink
refactor: make bind_syscalls an associated function
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Stebalien committed Dec 10, 2023
1 parent 8f4d31b commit bae4c9f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 18 deletions.
8 changes: 1 addition & 7 deletions fvm/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion fvm/src/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub trait Kernel: GasOps + SyscallHandler<Self> + 'static {
}

pub trait SyscallHandler<K: Kernel>: Sized {
fn bind_syscalls(&self, linker: &mut Linker<InvocationData<K>>) -> anyhow::Result<()>;
fn bind_syscalls(linker: &mut Linker<InvocationData<K>>) -> anyhow::Result<()>;
}

/// Network-related operations.
Expand Down
8 changes: 2 additions & 6 deletions fvm/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,7 @@ where
+ RandomnessOps
+ SelfOps,
{
fn bind_syscalls(
&self,
linker: &mut wasmtime::Linker<InvocationData<K>>,
) -> anyhow::Result<()> {
fn bind_syscalls(linker: &mut wasmtime::Linker<InvocationData<K>>) -> anyhow::Result<()> {
linker.bind("vm", "exit", vm::exit)?;
linker.bind("vm", "message_context", vm::message_context)?;

Expand Down Expand Up @@ -338,10 +335,9 @@ where
C: CallManager,
{
fn bind_syscalls(
&self,
linker: &mut Linker<InvocationData<DefaultFilecoinKernel<DefaultKernel<C>>>>,
) -> anyhow::Result<()> {
self.0.bind_syscalls(linker)?;
DefaultKernel::<C>::bind_syscalls(linker)?;

// Bind the circulating supply call.
linker.bind(
Expand Down
5 changes: 1 addition & 4 deletions testing/conformance/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ where
C: CallManager<Machine = TestMachine<M>>,
K: Kernel<CallManager = C>,
{
fn bind_syscalls(
&self,
_linker: &mut Linker<InvocationData<TestKernel<K>>>,
) -> anyhow::Result<()> {
fn bind_syscalls(_linker: &mut Linker<InvocationData<TestKernel<K>>>) -> anyhow::Result<()> {
Ok(())
}
}
Expand Down

0 comments on commit bae4c9f

Please sign in to comment.