diff --git a/src/vm/fce.rs b/src/vm/fce.rs index f2a4fe23..c27acc8e 100644 --- a/src/vm/fce.rs +++ b/src/vm/fce.rs @@ -46,13 +46,13 @@ impl FCE { let module_abi = module.acquire_abi(); // TODO: introduce a macro for such things - let allocate = module_abi.allocate.unwrap(); + let allocate = module_abi.allocate; namespace.insert( config.allocate_fn_name.clone(), func!(move |size: i32| -> i32 { allocate.call(size).expect("allocate failed") }), ); - let invoke = module_abi.invoke.unwrap(); + let invoke = module_abi.invoke; namespace.insert( config.invoke_fn_name.clone(), func!(move |offset: i32, size: i32| -> i32 { @@ -60,7 +60,7 @@ impl FCE { }), ); - let deallocate = module_abi.deallocate.unwrap(); + let deallocate = module_abi.deallocate; namespace.insert( config.deallocate_fn_name.clone(), func!(move |ptr: i32, size: i32| { @@ -68,7 +68,7 @@ impl FCE { }), ); - let store = module_abi.store.unwrap(); + let store = module_abi.store; namespace.insert( config.store_fn_name.clone(), func!(move |offset: i32, value: i32| { @@ -76,7 +76,7 @@ impl FCE { }), ); - let load = module_abi.load.unwrap(); + let load = module_abi.load; namespace.insert( config.load_fn_name.clone(), func!(move |offset: i32| -> i32 { load.call(offset).expect("load failed") }), @@ -139,7 +139,7 @@ impl FCEService for FCE { Entry::Occupied(module) => { if module.get().get_abi_ref_counter() != 0 { - return Err(FCEError::ModuleInUse) + return Err(FCEError::ModuleInUse); } module.remove_entry(); Ok(()) diff --git a/src/vm/module/abi.rs b/src/vm/module/abi.rs index c32792f6..72d316dd 100644 --- a/src/vm/module/abi.rs +++ b/src/vm/module/abi.rs @@ -30,17 +30,17 @@ use crate::vm::errors::FCEError; /// 5. deallocate(res, strlen(sql)) to clean memory. pub(crate) trait ModuleABI { /// Allocates a region of memory inside a module. Used for passing argument inside the module. - fn allocate(&self, size: i32) -> Result; + fn allocate(&mut self, size: i32) -> Result; /// Deallocates previously allocated memory region. - fn deallocate(&self, ptr: i32, size: i32) -> Result<(), FCEError>; + fn deallocate(&mut self, ptr: i32, size: i32) -> Result<(), FCEError>; /// Calls the main entry point of a module called invoke. - fn invoke(&self, arg_address: i32, arg_size: i32) -> Result; + fn invoke(&mut self, arg_address: i32, arg_size: i32) -> Result; /// Stores one byte on given address. - fn store(&self, address: i32, value: i32) -> Result<(), FCEError>; + fn store(&mut self, address: i32, value: i32) -> Result<(), FCEError>; /// Loads one byte from given address. - fn load(&self, address: i32) -> Result; + fn load(&mut self, address: i32) -> Result; } diff --git a/src/vm/module/fce_module.rs b/src/vm/module/fce_module.rs index fe27053d..a4af2d4a 100644 --- a/src/vm/module/fce_module.rs +++ b/src/vm/module/fce_module.rs @@ -34,11 +34,11 @@ pub(crate) struct ABI { // It is safe to use unwrap() while calling these functions because Option is used here // just to allow partially initialization. And all Option fields will contain Some if // invoking FCE::new has been succeed. - pub(crate) allocate: Option>, - pub(crate) deallocate: Option>, - pub(crate) invoke: Option>, - pub(crate) store: Option>, - pub(crate) load: Option>, + pub(crate) allocate: Func<'static, i32, i32>, + pub(crate) deallocate: Func<'static, (i32, i32), ()>, + pub(crate) invoke: Func<'static, (i32, i32), i32>, + pub(crate) store: Func<'static, (i32, i32)>, + pub(crate) load: Func<'static, i32, i32>, } /// A building block of multi-modules scheme of FCE, represents one module that corresponds @@ -106,11 +106,11 @@ impl FCEModule { ); Ok(ABI { - allocate: Some(allocate), - deallocate: Some(deallocate), - invoke: Some(invoke), - store: Some(store), - load: Some(load), + allocate, + deallocate, + invoke, + store, + load, }) } } @@ -219,25 +219,24 @@ impl ModuleAPI for FCEModule { } } -#[rustfmt::skip] impl ModuleABI for FCEModule { - fn allocate(&self, size: i32) -> Result { - Ok(self.abi.allocate.as_ref().unwrap().call(size)?) + fn allocate(&mut self, size: i32) -> Result { + Ok(self.abi.allocate.call(size)?) } - fn deallocate(&self, ptr: i32, size: i32) -> Result<(), FCEError> { - Ok(self.abi.deallocate.as_ref().unwrap().call(ptr, size)?) + fn deallocate(&mut self, ptr: i32, size: i32) -> Result<(), FCEError> { + Ok(self.abi.deallocate.call(ptr, size)?) } - fn invoke(&self, arg_address: i32, arg_size: i32) -> Result { - Ok(self.abi.invoke.as_ref().unwrap().call(arg_address, arg_size)?) + fn invoke(&mut self, arg_address: i32, arg_size: i32) -> Result { + Ok(self.abi.invoke.call(arg_address, arg_size)?) } - fn store(&self, address: i32, value: i32) -> Result<(), FCEError> { - Ok(self.abi.store.as_ref().unwrap().call(address, value)?) + fn store(&mut self, address: i32, value: i32) -> Result<(), FCEError> { + Ok(self.abi.store.call(address, value)?) } - fn load(&self, address: i32) -> Result { - Ok(self.abi.load.as_ref().unwrap().call(address)?) + fn load(&mut self, address: i32) -> Result { + Ok(self.abi.load.call(address)?) } }