rework libwasm

This commit is contained in:
Able 2022-02-10 23:54:16 -06:00
parent cdfe5d0045
commit 825baedbe0
7 changed files with 103 additions and 4 deletions

View file

@ -1,5 +1,8 @@
#![no_std]
#[macro_use]
pub mod logger;
pub mod process;
pub mod syscalls;
pub use core::*;

6
src/process/mod.rs Normal file
View file

@ -0,0 +1,6 @@
pub mod signals;
/// Process Identification
#[derive(Clone, Copy, PartialEq, Debug)]
#[repr(C)]
pub struct PID(pub usize);

8
src/process/signals.rs Normal file
View file

@ -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,
}

View file

@ -1,4 +0,0 @@
/// All system calls are defined here.
extern "C" {
pub fn add(a: u32, b: u32) -> u32;
}

View file

@ -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,
}

24
src/syscalls/mod.rs Normal file
View file

@ -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;
}

View file

@ -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);
}