#![allow(unsafe_code)]
use crate::hton::{HaCloneMode, HaCloneType};
use crate::panic_guard::FfiBoundary;
use crate::runtime;
use crate::runtime::FfiPtr;
use crate::sys;
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__clone_capability(out_flags: *mut u64) {
FfiBoundary::run_void(|| {
let flags = match runtime::handlerton() {
Some(h) => h.clone_capability(),
None => 0,
};
if !out_flags.is_null() {
unsafe { out_flags.write(flags) };
}
});
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__clone_begin(
thd: *const sys::THD,
clone_type: usize,
mode: u32,
) -> i32 {
FfiBoundary::run(|| {
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => h.clone_begin(
thd_ref,
HaCloneType::from_raw(clone_type),
HaCloneMode::from_raw(mode),
),
None => Ok(()),
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__clone_copy(
thd: *const sys::THD,
task_id: u32,
cbk: *const sys::HaCloneCbk,
) -> i32 {
FfiBoundary::run(|| {
let thd_ref = unsafe { thd.as_ref() };
let cbk_ref = unsafe { cbk.as_ref() };
match runtime::handlerton() {
Some(h) => h.clone_copy(thd_ref, task_id, cbk_ref),
None => Ok(()),
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__clone_ack(
thd: *const sys::THD,
task_id: u32,
in_err: i32,
cbk: *const sys::HaCloneCbk,
) -> i32 {
FfiBoundary::run(|| {
let thd_ref = unsafe { thd.as_ref() };
let cbk_ref = unsafe { cbk.as_ref() };
match runtime::handlerton() {
Some(h) => h.clone_ack(thd_ref, task_id, in_err, cbk_ref),
None => Ok(()),
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__clone_end(
thd: *const sys::THD,
task_id: u32,
in_err: i32,
) -> i32 {
FfiBoundary::run(|| {
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => h.clone_end(thd_ref, task_id, in_err),
None => Ok(()),
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__clone_apply_begin(
thd: *const sys::THD,
mode: u32,
data_dir: *const u8,
data_dir_len: usize,
) -> i32 {
FfiBoundary::run(|| {
let data_dir_str = match unsafe { FfiPtr::bytes_to_str(data_dir, data_dir_len) } {
Ok(s) => s,
Err(e) => return Err(e),
};
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => h.clone_apply_begin(thd_ref, HaCloneMode::from_raw(mode), data_dir_str),
None => Ok(()),
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__clone_apply(
thd: *const sys::THD,
task_id: u32,
in_err: i32,
cbk: *const sys::HaCloneCbk,
) -> i32 {
FfiBoundary::run(|| {
let thd_ref = unsafe { thd.as_ref() };
let cbk_ref = unsafe { cbk.as_ref() };
match runtime::handlerton() {
Some(h) => h.clone_apply(thd_ref, task_id, in_err, cbk_ref),
None => Ok(()),
}
})
}
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rust__hton__clone_apply_end(
thd: *const sys::THD,
task_id: u32,
in_err: i32,
) -> i32 {
FfiBoundary::run(|| {
let thd_ref = unsafe { thd.as_ref() };
match runtime::handlerton() {
Some(h) => h.clone_apply_end(thd_ref, task_id, in_err),
None => Ok(()),
}
})
}