From 825baedbe0036995f622f50889323d1a926120ff Mon Sep 17 00:00:00 2001 From: Able Date: Thu, 10 Feb 2022 23:54:16 -0600 Subject: [PATCH] rework libwasm --- src/lib.rs | 3 +++ src/process/mod.rs | 6 ++++++ src/process/signals.rs | 8 +++++++ src/syscalls.rs | 4 ---- src/syscalls/file_calls.rs | 43 ++++++++++++++++++++++++++++++++++++++ src/syscalls/mod.rs | 24 +++++++++++++++++++++ src/syscalls/time_calls.rs | 19 +++++++++++++++++ 7 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 src/process/mod.rs create mode 100644 src/process/signals.rs delete mode 100644 src/syscalls.rs create mode 100644 src/syscalls/file_calls.rs create mode 100644 src/syscalls/mod.rs create mode 100644 src/syscalls/time_calls.rs diff --git a/src/lib.rs b/src/lib.rs index 9c4ee35..43d8d95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,8 @@ +#![no_std] + #[macro_use] pub mod logger; +pub mod process; pub mod syscalls; pub use core::*; diff --git a/src/process/mod.rs b/src/process/mod.rs new file mode 100644 index 0000000..cab46e3 --- /dev/null +++ b/src/process/mod.rs @@ -0,0 +1,6 @@ +pub mod signals; + +/// Process Identification +#[derive(Clone, Copy, PartialEq, Debug)] +#[repr(C)] +pub struct PID(pub usize); diff --git a/src/process/signals.rs b/src/process/signals.rs new file mode 100644 index 0000000..8df469d --- /dev/null +++ b/src/process/signals.rs @@ -0,0 +1,8 @@ +#[repr(C)] +/// Signals that can be sent to a process +pub enum Signals { + /// Terminate the process + Terminate, + /// Shutdown the process and allow it to shutdown cleanly + Quit, +} diff --git a/src/syscalls.rs b/src/syscalls.rs deleted file mode 100644 index 376456f..0000000 --- a/src/syscalls.rs +++ /dev/null @@ -1,4 +0,0 @@ -/// All system calls are defined here. -extern "C" { - pub fn add(a: u32, b: u32) -> u32; -} diff --git a/src/syscalls/file_calls.rs b/src/syscalls/file_calls.rs new file mode 100644 index 0000000..653eced --- /dev/null +++ b/src/syscalls/file_calls.rs @@ -0,0 +1,43 @@ +//! File system related system calls. + +/// Temporary representation of a file path +pub type Path = *const u8; + +/// Remove a Directory from the filesystem +/// +/// # Arguments +/// * `full_path` - The full path of the directory to remove +/// * `force` - Whether to remove the directory even if it is not empty +#[no_mangle] +pub extern "C" fn remove_directory(path: Path, force_delete: bool) { + unimplemented!(); +} + +/// Create a new directory at the given path +/// +/// # Arguments +/// * `full_path` - The full path of the directory to create +#[no_mangle] +pub extern "C" fn create_directory(path: Path) -> FSReturns { + unimplemented!(); +} + +#[repr(C)] +/// A return used by the file related system calls +pub enum FSReturns { + /// The system call was successful + Ok, + + /// The directory can not be created + DirectoryCouldNotBeCreated, + /// The directory could not be removed + DirectoryCouldNotBeRemoved, + /// + FileCouldNotBeCreated, + /// + FileCouldNotBeRemoved, + /// The file could not be opened + FileCouldNotBeOpened, + /// + FileCouldNotBeClosed, +} diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs new file mode 100644 index 0000000..e618ae8 --- /dev/null +++ b/src/syscalls/mod.rs @@ -0,0 +1,24 @@ +#![deny(missing_docs)] +//! The module of syscalls. + +use crate::process::{signals::Signals, PID}; + +pub mod file_calls; +pub mod time_calls; + +#[no_mangle] +/// All system calls are defined here. +extern "C" { + + /// Send a signal to a process + /// + /// # Arguments + /// + /// * `pid` - The PID of the process to send the signal to + /// * `signal` - The signal to send + pub fn send_signal(pid: PID, signal: Signals) -> bool; + + /// A temporary function to test the syscall interface + pub fn add(a: u32, b: u32) -> u32; + +} diff --git a/src/syscalls/time_calls.rs b/src/syscalls/time_calls.rs new file mode 100644 index 0000000..258b4ad --- /dev/null +++ b/src/syscalls/time_calls.rs @@ -0,0 +1,19 @@ +//! Time related system calls. + +/// Seconds and milliseconds since the Unix epoch. +#[repr(C)] +pub struct SecondsTime { + seconds: u64, + milliseconds: u64, +} + +extern "C" { + /// Sleep the calling process for the given number of milliseconds + pub fn sleep(time: SecondsTime); + + /// Get the current time in seconds, milliseconds + pub fn get_time() -> SecondsTime; + + /// Set the current time in seconds, milliseconds + pub fn set_time(time: SecondsTime); +}