Skip to content

Commit

Permalink
Add initial support for pluggable syscalls (#1922)
Browse files Browse the repository at this point in the history
See: #1787

This PR adds initial support for pluggable syscall by allowing us to extend the default kernel and add new custom syscalls through a new kernel.

The implementation does this by moving the global bind_syscall function into kernel via a SyscallHandler trait where each kernel needs to add their new syscalls.

The implementation uses Ambassador crate which automatically create stubs for delegating kernel implementations we are not overriding in new kernels, minimizing the code we need to write.
  • Loading branch information
fridrik01 authored Nov 22, 2023
1 parent 1200b8a commit 97b45db
Show file tree
Hide file tree
Showing 17 changed files with 1,112 additions and 921 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions fvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ minstant = "0.1.2"
blake2b_simd = "1.0.0"
byteorder = "1.4.3"
static_assertions = "1.1.0"
ambassador = "0.3.5"

[dev-dependencies]
pretty_assertions = "1.3.0"
Expand Down
12 changes: 8 additions & 4 deletions fvm/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use crate::machine::limiter::MemoryLimiter;
use crate::machine::{Machine, NetworkConfig};
use crate::syscalls::error::Abort;
use crate::syscalls::{
bind_syscalls, charge_for_exec, charge_for_init, record_init_time, update_gas_available,
InvocationData,
charge_for_exec, charge_for_init, record_init_time, update_gas_available, InvocationData,
};
use crate::Kernel;

Expand Down Expand Up @@ -514,10 +513,15 @@ impl Engine {
.expect("invalid instance cache entry"),
Vacant(e) => &mut *e
.insert({
let mut linker: Linker<InvocationData<K>> = Linker::new(&self.inner.engine);
let mut linker = Linker::new(&self.inner.engine);
linker.allow_shadowing(true);

bind_syscalls(&mut linker).map_err(Abort::Fatal)?;
store
.data()
.kernel
.bind_syscalls(&mut linker)
.map_err(Abort::Fatal)?;

Box::new(Cache { linker })
})
.downcast_mut()
Expand Down
1 change: 0 additions & 1 deletion fvm/src/gas/price_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,6 @@ impl PriceList {
}

/// Returns the gas required for installing an actor.
#[cfg(feature = "m2-native")]
pub fn on_install_actor(&self, wasm_size: usize) -> GasCharge {
GasCharge::new(
"OnInstallActor",
Expand Down
Loading

0 comments on commit 97b45db

Please sign in to comment.