This commit is contained in:
Graham Kelly 2023-04-11 19:48:05 -04:00
parent ec7a80c93a
commit 9975d08054
6 changed files with 79 additions and 1 deletions

4
Cargo.lock generated
View file

@ -2,6 +2,10 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "ablewasi"
version = "0.1.0"
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.7.6"

View file

@ -2,4 +2,4 @@ resolver = "2"
[workspace] [workspace]
members = ["kernel", "repbuild"] members = ["kernel", "repbuild", "user/ablewasi"]

8
user/ablewasi/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "ablewasi"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

29
user/ablewasi/src/api.rs Normal file
View file

@ -0,0 +1,29 @@
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{
fn to_global(self) -> [u64; 4]{
let b = unsafe {
sys::make_global(self.id).into()
};
core::mem::forget(self);
return b;
}
fn from_global(a: [u64; 4]) -> Object{
return Object{id: unsafe {
sys::take_global(a.into())
}};
}
}

8
user/ablewasi/src/lib.rs Normal file
View file

@ -0,0 +1,8 @@
pub mod sys;
pub mod api;
#[cfg(test)]
mod tests {
use super::*;
}

29
user/ablewasi/src/sys.rs Normal file
View file

@ -0,0 +1,29 @@
#[repr(C)]
pub struct ROAResult(*const u8,i32);
pub type LocalObject = i64;
#[repr(C)]
pub struct GlobalObject(u64,u64,u64,u64);
impl From<[u64;4]> for GlobalObject {
fn from(value: [u64;4]) -> Self {
GlobalObject(value[0], value[1], value[2], value[3])
}
}
impl From<GlobalObject> for [u64; 4]{
fn from(value: GlobalObject) -> Self {
let GlobalObject(a,b,c,d) = value;
[a,b,c,d]
}
}
extern "C"{
pub fn create_object(a: *const u8, b: i32) -> LocalObject;
pub fn read_object_attribute(a: LocalObject, b: *const i8, c: i32) -> ROAResult;
pub fn take_global(a: GlobalObject) -> LocalObject;
pub fn make_global(a: LocalObject) -> GlobalObject;
pub fn drop_object(a: LocalObject);
}