From 9975d0805419b43ec1ba99549537f7ffdc0b72d4 Mon Sep 17 00:00:00 2001 From: Graham Kelly Date: Tue, 11 Apr 2023 19:48:05 -0400 Subject: [PATCH] ablelib --- Cargo.lock | 4 ++++ Cargo.toml | 2 +- user/ablewasi/Cargo.toml | 8 ++++++++ user/ablewasi/src/api.rs | 29 +++++++++++++++++++++++++++++ user/ablewasi/src/lib.rs | 8 ++++++++ user/ablewasi/src/sys.rs | 29 +++++++++++++++++++++++++++++ 6 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 user/ablewasi/Cargo.toml create mode 100644 user/ablewasi/src/api.rs create mode 100644 user/ablewasi/src/lib.rs create mode 100644 user/ablewasi/src/sys.rs diff --git a/Cargo.lock b/Cargo.lock index 44e9cca7..f53a7888 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,10 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ablewasi" +version = "0.1.0" + [[package]] name = "ahash" version = "0.7.6" diff --git a/Cargo.toml b/Cargo.toml index af2ccc0d..b463cecd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,4 +2,4 @@ resolver = "2" [workspace] -members = ["kernel", "repbuild"] +members = ["kernel", "repbuild", "user/ablewasi"] diff --git a/user/ablewasi/Cargo.toml b/user/ablewasi/Cargo.toml new file mode 100644 index 00000000..00e1bcb5 --- /dev/null +++ b/user/ablewasi/Cargo.toml @@ -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] diff --git a/user/ablewasi/src/api.rs b/user/ablewasi/src/api.rs new file mode 100644 index 00000000..c44a8db5 --- /dev/null +++ b/user/ablewasi/src/api.rs @@ -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()) + }}; + } +} \ No newline at end of file diff --git a/user/ablewasi/src/lib.rs b/user/ablewasi/src/lib.rs new file mode 100644 index 00000000..7b04e1be --- /dev/null +++ b/user/ablewasi/src/lib.rs @@ -0,0 +1,8 @@ +pub mod sys; +pub mod api; + +#[cfg(test)] +mod tests { + use super::*; + +} diff --git a/user/ablewasi/src/sys.rs b/user/ablewasi/src/sys.rs new file mode 100644 index 00000000..8b69dd3b --- /dev/null +++ b/user/ablewasi/src/sys.rs @@ -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 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); +} \ No newline at end of file