akern-gkgoat-fork/user/ablewasi/src/api.rs

36 lines
692 B
Rust

use crate::sys;
pub struct Object{
pub id: i64
}
impl Drop for Object{
fn drop(&mut self) {
unsafe{
sys::drop_object(self.id);
}
}
}
impl Object{
pub fn to_global(self) -> [u64; 4]{
let b = unsafe {
sys::make_global(self.id).into()
};
core::mem::forget(self);
return b;
}
pub fn from_global(a: [u64; 4]) -> Object{
return Object{id: unsafe {
sys::take_global(a.into())
}};
}
pub fn new(name: &str) -> Object{
return Object{id: unsafe {
let a = name.as_ptr();
sys::create_object(a, name.len() as i32)
}};
}
}