diff --git a/crates/runtime-ffi/src/api.rs b/crates/runtime-ffi/src/api.rs index 0aefdd974..79e3744bb 100644 --- a/crates/runtime-ffi/src/api.rs +++ b/crates/runtime-ffi/src/api.rs @@ -20,8 +20,6 @@ lazy_static! { static ref INITIALIZED: Mutex = Mutex::new(false); } -type RuntimePtr = *mut c_void; - /// Initializes the SVM library. #[must_use] #[no_mangle] @@ -59,7 +57,7 @@ pub unsafe extern "C" fn svm_free_result(_result: svm_result_t) {} #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_runtime_create( - runtime_ptr: *mut RuntimePtr, + runtime_ptr: *mut *mut c_void, path: *const u8, path_len: u32, ) -> svm_result_t { @@ -111,7 +109,7 @@ pub unsafe extern "C" fn svm_runtime_create( /// #[must_use] #[no_mangle] -pub extern "C" fn svm_runtime_destroy(runtime: RuntimePtr) -> svm_result_t { +pub extern "C" fn svm_runtime_destroy(runtime: *mut c_void) -> svm_result_t { if RUNTIME_TRACKER.free(runtime).is_some() { svm_result_t::OK } else { @@ -150,7 +148,7 @@ pub extern "C" fn svm_runtimes_count() -> u64 { #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_validate_deploy( - runtime: RuntimePtr, + runtime: *mut c_void, message: *const u8, message_size: u32, ) -> svm_result_t { @@ -189,7 +187,7 @@ pub unsafe extern "C" fn svm_validate_deploy( #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_validate_spawn( - runtime: RuntimePtr, + runtime: *mut c_void, message: *const u8, message_size: u32, ) -> svm_result_t { @@ -222,7 +220,7 @@ pub unsafe extern "C" fn svm_validate_spawn( #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_validate_call( - runtime: RuntimePtr, + runtime: *mut c_void, message: *const u8, message_size: u32, ) -> svm_result_t { @@ -265,7 +263,7 @@ pub unsafe extern "C" fn svm_validate_call( #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_deploy( - runtime: RuntimePtr, + runtime: *mut c_void, envelope: *const u8, message: *const u8, message_size: u32, @@ -312,7 +310,7 @@ pub unsafe extern "C" fn svm_deploy( #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_spawn( - runtime: RuntimePtr, + runtime: *mut c_void, envelope: *const u8, message: *const u8, message_size: u32, @@ -363,7 +361,7 @@ pub unsafe extern "C" fn svm_spawn( #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_verify( - runtime: RuntimePtr, + runtime: *mut c_void, envelope: *const u8, message: *const u8, message_size: u32, @@ -411,7 +409,7 @@ pub unsafe extern "C" fn svm_verify( #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_call( - runtime: RuntimePtr, + runtime: *mut c_void, envelope: *const u8, message: *const u8, message_size: u32, @@ -448,7 +446,7 @@ pub unsafe extern "C" fn svm_call( /// #[must_use] #[no_mangle] -pub unsafe extern "C" fn svm_uncommitted_changes(runtime_ptr: RuntimePtr) -> svm_result_t { +pub unsafe extern "C" fn svm_uncommitted_changes(runtime_ptr: *mut c_void) -> svm_result_t { catch_unwind_or_fail(|| { let runtime = get_runtime(runtime_ptr); if runtime.has_uncommitted_changes()? { @@ -463,7 +461,7 @@ pub unsafe extern "C" fn svm_uncommitted_changes(runtime_ptr: RuntimePtr) -> svm #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_layer_info( - runtime_ptr: RuntimePtr, + runtime_ptr: *mut c_void, hash: *mut u8, layer: *mut u64, ) -> svm_result_t { @@ -481,7 +479,7 @@ pub unsafe extern "C" fn svm_layer_info( /// Undos all changes after the given layer. #[must_use] #[no_mangle] -pub unsafe extern "C" fn svm_rewind(runtime_ptr: RuntimePtr, layer_id: u64) -> svm_result_t { +pub unsafe extern "C" fn svm_rewind(runtime_ptr: *mut c_void, layer_id: u64) -> svm_result_t { catch_unwind_or_fail(|| { get_runtime(runtime_ptr).rewind(Layer(layer_id))?; svm_result_t::OK @@ -491,7 +489,7 @@ pub unsafe extern "C" fn svm_rewind(runtime_ptr: RuntimePtr, layer_id: u64) -> s /// Commits all written data to persistent storage. #[must_use] #[no_mangle] -pub unsafe extern "C" fn svm_commit(runtime_ptr: RuntimePtr) -> svm_result_t { +pub unsafe extern "C" fn svm_commit(runtime_ptr: *mut c_void) -> svm_result_t { catch_unwind_or_fail(|| { get_runtime(runtime_ptr).commit()?; svm_result_t::OK @@ -523,7 +521,7 @@ impl svm_account { #[must_use] #[no_mangle] pub unsafe extern "C" fn svm_get_account( - runtime_ptr: RuntimePtr, + runtime_ptr: *mut c_void, account_addr: *const u8, account: *mut svm_account, ) -> svm_result_t { @@ -548,7 +546,7 @@ pub unsafe extern "C" fn svm_get_account( #[no_mangle] #[must_use] pub unsafe extern "C" fn svm_create_account( - runtime_ptr: RuntimePtr, + runtime_ptr: *mut c_void, addr: *const u8, balance: u64, counter_upper_bits: u64, @@ -568,7 +566,7 @@ pub unsafe extern "C" fn svm_create_account( #[no_mangle] #[must_use] pub unsafe extern "C" fn svm_increase_balance( - runtime_ptr: RuntimePtr, + runtime_ptr: *mut c_void, addr: *const u8, additional_balance: u64, ) -> svm_result_t { @@ -605,7 +603,7 @@ pub unsafe extern "C" fn svm_transfer( } unsafe fn svm_runtime_action( - runtime_ptr: RuntimePtr, + runtime_ptr: *mut c_void, envelope: *const u8, message: *const u8, message_size: u32, @@ -632,7 +630,7 @@ where } unsafe fn svm_validate( - runtime_ptr: RuntimePtr, + runtime_ptr: *mut c_void, message: *const u8, message_size: u32, validate_f: F, @@ -658,7 +656,7 @@ where }) } -unsafe fn get_runtime(runtime_ptr: RuntimePtr) -> &'static mut Runtime { +unsafe fn get_runtime(runtime_ptr: *mut c_void) -> &'static mut Runtime { RUNTIME_TRACKER .get(runtime_ptr) .expect("The given runtime pointer doesn't point to a valid runtime.")