This commit is contained in:
nora 2023-09-30 10:25:23 +02:00
parent de90913d46
commit 54e0e7604e
23 changed files with 77 additions and 33 deletions

7
Cargo.lock generated
View file

@ -2,6 +2,13 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "c"
version = "0.1.0"
dependencies = [
"libuwuc",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"

View file

@ -1,18 +1,9 @@
[package] [workspace]
name = "libuwuc" members = ["libuwuc", "c"]
version = "0.1.0" resolver = "2"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev] [profile.dev]
panic = "abort" panic = "abort"
[profile.release] [profile.release]
panic = "abort" panic = "abort"
[dependencies]
cfg-if = "1.0.0"
[features]
export_symbols = []

13
c/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "c"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["rlib"]
[dependencies]
libuwuc = { path = "../libuwuc" }

11
c/src/lib.rs Normal file
View file

@ -0,0 +1,11 @@
#![no_std]
mod string;
// libcore seems to require this symbol, even though it's unused.
#[no_mangle]
fn rust_eh_personality() {
unsafe {
libuwuc::trap!();
}
}

View file

@ -8,11 +8,6 @@ pub(crate) unsafe extern "C" fn memset(ptr: *mut u8, constant: u8, len: usize) {
} }
#[no_mangle] #[no_mangle]
pub(crate) unsafe extern "C" fn strlen(mut s: *const u8) -> usize { pub(crate) unsafe extern "C" fn strlen(s: *const u8) -> usize {
let mut len = 0; libuwuc::mem::strlen(s)
while s.read() != 0 {
len += 1;
s = s.add(1);
}
len
} }

View file

@ -2,6 +2,13 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "c"
version = "0.1.0"
dependencies = [
"libuwuc",
]
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -12,6 +19,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
name = "example-user" name = "example-user"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"c",
"libuwuc", "libuwuc",
] ]

View file

@ -14,4 +14,5 @@ panic = "abort"
panic = "abort" panic = "abort"
[dependencies] [dependencies]
libuwuc = { path = "..", features = ["export_symbols"] } c = { path = "../c" }
libuwuc = { path = "../libuwuc" }

View file

@ -6,7 +6,7 @@ use core::ffi::c_char;
use libuwuc::{println, utils::SharedThinCstr}; use libuwuc::{println, utils::SharedThinCstr};
extern crate libuwuc; extern crate c;
#[panic_handler] #[panic_handler]
#[cfg(not(test))] #[cfg(not(test))]
@ -27,11 +27,3 @@ extern "C" fn main(_argc: i32, _argv: *const *const c_char) -> i32 {
println!("PWD={pwd:?}"); println!("PWD={pwd:?}");
0 0
} }
// libcore seems to require this symbol, even though it's unused.
#[no_mangle]
fn rust_eh_personality() {
unsafe {
libuwuc::trap!();
}
}

9
libuwuc/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "libuwuc"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cfg-if = "1.0.0"

View file

@ -63,7 +63,6 @@ pub fn getenv(name: SharedThinCstr) -> Option<SharedThinCstr> {
fn getenv_inner(mut envp: EnvP, name: SharedThinCstr) -> Option<SharedThinCstr> { fn getenv_inner(mut envp: EnvP, name: SharedThinCstr) -> Option<SharedThinCstr> {
let mut eq_idx = 0; let mut eq_idx = 0;
envp.find(|env| { envp.find(|env| {
println!("trying {env:?}");
// Find ENV // Find ENV
// EN=x // EN=x
// ENV=x <- this one // ENV=x <- this one

View file

@ -4,7 +4,7 @@
#[cfg(test)] #[cfg(test)]
extern crate std; extern crate std;
mod basic_mem; pub mod mem;
pub mod env; pub mod env;
pub mod io; pub mod io;
pub mod start; pub mod start;

18
libuwuc/src/mem.rs Normal file
View file

@ -0,0 +1,18 @@
#[inline]
pub unsafe fn memset(ptr: *mut u8, constant: u8, len: usize) {
for i in 0..len {
unsafe {
*ptr.add(i) = constant;
}
}
}
#[inline]
pub unsafe fn strlen(mut s: *const u8) -> usize {
let mut len = 0;
while s.read() != 0 {
len += 1;
s = s.add(1);
}
len
}

View file

@ -13,7 +13,7 @@ pub(crate) unsafe extern "C" fn start(argc: u64, argv: *const *const c_char, rsp
fn main(argc: c_int, argv: *const *const c_char) -> c_int; fn main(argc: c_int, argv: *const *const c_char) -> c_int;
} }
crate::env::debug_env(); // crate::env::debug_env();
let result = main(argc as i32, argv); let result = main(argc as i32, argv);