forked from theseus-os/Theseus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Klimenty Tsoutsman <[email protected]>
- Loading branch information
Showing
18 changed files
with
187 additions
and
1,626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/ports/rust |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.