Skip to content
This repository has been archived by the owner on Aug 14, 2023. It is now read-only.

Commit

Permalink
Replace RuntimePtr with *mut c_void
Browse files Browse the repository at this point in the history
  • Loading branch information
neysofu committed Dec 2, 2021
1 parent fed94e4 commit 2c8f6f5
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions crates/runtime-ffi/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ lazy_static! {
static ref INITIALIZED: Mutex<bool> = Mutex::new(false);
}

type RuntimePtr = *mut c_void;

/// Initializes the SVM library.
#[must_use]
#[no_mangle]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()? {
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -605,7 +603,7 @@ pub unsafe extern "C" fn svm_transfer(
}

unsafe fn svm_runtime_action<F, C>(
runtime_ptr: RuntimePtr,
runtime_ptr: *mut c_void,
envelope: *const u8,
message: *const u8,
message_size: u32,
Expand All @@ -632,7 +630,7 @@ where
}

unsafe fn svm_validate<F>(
runtime_ptr: RuntimePtr,
runtime_ptr: *mut c_void,
message: *const u8,
message_size: u32,
validate_f: F,
Expand All @@ -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.")
Expand Down

0 comments on commit 2c8f6f5

Please sign in to comment.