Skip to content

Commit

Permalink
Temp
Browse files Browse the repository at this point in the history
Signed-off-by: Klimenty Tsoutsman <[email protected]>
  • Loading branch information
tsoutsman committed Oct 23, 2023
1 parent dfa1e36 commit 319f6aa
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 1,626 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@
path = libs/core2
url = https://github.com/theseus-os/core2.git
shallow = true
[submodule "ports/rust"]
path = ports/rust
url = https://github.com/theseus-os/rust.git
1 change: 1 addition & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/ports/rust
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"theseus_features", ## Must be included to realize global Cargo features across Theseus.
"kernel/[!.]*/",
"applications/[!.]*/",
"shim",
]


Expand Down Expand Up @@ -55,7 +56,6 @@ exclude = [

## Exclude tlibc and libtheseus, which are currently built separately.
"tlibc",
"libtheseus",

########################################################################################
## Below, we exclude things that should NEVER be considered part of Theseus's workspace.
Expand Down
8 changes: 8 additions & 0 deletions applications/test_std/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "test_std"
version = "0.1.0"
edition = "2021"

[dependencies]
app_io = { path = "../../kernel/app_io" }
theseus-shim = { path = "../../shim" }
13 changes: 13 additions & 0 deletions applications/test_std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![no_std]

extern crate alloc;

use alloc::{string::String, vec::Vec};
use app_io::println;

pub fn main(_: Vec<String>) -> isize {
println!("starting");
// unsafe { shim::hello() };
println!("done");
0
}
9 changes: 9 additions & 0 deletions kernel/libtheseus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "libtheseus"
version = "0.1.0"
edition = "2021"

[dependencies]
path = { path = "../path" }
random = { path = "../random" }
task = { path = "../task" }
89 changes: 89 additions & 0 deletions kernel/libtheseus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#![no_std]
#![feature(vec_into_raw_parts)]

extern crate alloc;

use alloc::string::String;
use core::{marker::PhantomData, slice, str};

use path::Path;
use task::get_my_current_task;

// Add the libtheseus:: so mod_mgmt knows which crate to search.

#[repr(C)]
pub struct FfiString {
buf: *mut u8,
length: usize,
capacity: usize,
}

impl From<String> for FfiString {
fn from(value: String) -> Self {
let (buf, length, capacity) = value.into_raw_parts();
Self {
buf,
length,
capacity,
}
}
}

impl From<FfiString> for String {
fn from(
FfiString {
buf,
length,
capacity,
}: FfiString,
) -> Self {
unsafe { Self::from_raw_parts(buf, length, capacity) }
}
}

#[repr(C)]
pub struct FfiStr<'a> {
buf: *const u8,
length: usize,
_phantom_data: PhantomData<&'a ()>,
}

impl<'a> From<&'a str> for FfiStr<'a> {
fn from(value: &'a str) -> Self {
let buf = value.as_bytes();
Self {
buf: buf.as_ptr(),
length: buf.len(),
_phantom_data: PhantomData,
}
}
}

impl<'a> From<FfiStr<'a>> for &'a str {
fn from(FfiStr { buf, length, .. }: FfiStr<'a>) -> Self {
let bytes = unsafe { slice::from_raw_parts(buf, length) };
unsafe { str::from_utf8_unchecked(bytes) }
}
}

#[no_mangle]
#[export_name = "libtheseus::next_u64"]
pub extern "C" fn next_u64() -> u64 {
random::next_u64()
}

#[no_mangle]
#[export_name = "libtheseus::getcwd"]
pub extern "C" fn getcwd() -> FfiString {
get_my_current_task().unwrap().get_env().lock().cwd().into()
}

#[no_mangle]
#[export_name = "libtheseus::chdir"]
pub extern "C" fn chdir(path: FfiStr<'_>) {
get_my_current_task()
.unwrap()
.get_env()
.lock()
.chdir(Path::new(path.into()));
}
2 changes: 1 addition & 1 deletion kernel/random/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description = "A cryptograhically secure source of randomness"
edition = "2021"

[dependencies]
lazy_static = "1.4.0"
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
log = "0.4.8"
spin = "0.9.4"
tsc = { path = "../tsc" }
Expand Down
Loading

0 comments on commit 319f6aa

Please sign in to comment.