libc: setup args/env
This commit is contained in:
parent
0a904a21fe
commit
4519e5385a
@ -14,3 +14,6 @@ bitflags = "2.6.0"
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = { git = "https://git.alnyan.me/yggdrasil/cbindgen.git", branch = "master" }
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "allow", check-cfg = ['cfg(rust_analyzer)'] }
|
||||
|
@ -1,9 +1,23 @@
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use alloc::{ffi::CString, vec::Vec};
|
||||
use yggdrasil_rt::process::ProgramArgumentInner;
|
||||
|
||||
pub fn handle_kernel_argument(arg: usize) -> (Vec<String>, Vec<String>) {
|
||||
let arg_ptr: *const ProgramArgumentInner = core::ptr::with_exposed_provenance(arg);
|
||||
let arg = unsafe { arg_ptr.as_ref() }.expect("TODO");
|
||||
use crate::util::PointerExt;
|
||||
|
||||
todo!()
|
||||
pub fn handle_kernel_argument(arg: usize) -> (Vec<CString>, Vec<CString>) {
|
||||
let arg_ptr: *const ProgramArgumentInner = core::ptr::with_exposed_provenance(arg);
|
||||
let arg = unsafe { arg_ptr.ensure() };
|
||||
|
||||
let mut args = Vec::new();
|
||||
let mut envs = Vec::new();
|
||||
|
||||
for &arg in arg.args {
|
||||
let c_arg = CString::new(arg).unwrap();
|
||||
args.push(c_arg);
|
||||
}
|
||||
for &env in arg.env {
|
||||
let c_env = CString::new(env).unwrap();
|
||||
envs.push(c_env);
|
||||
}
|
||||
|
||||
(args, envs)
|
||||
}
|
||||
|
@ -47,9 +47,9 @@
|
||||
// <stdbool.h> -
|
||||
// <stddef.h> -
|
||||
// <stdint.h> -
|
||||
// <stdio.h> ~
|
||||
// <stdio.h> +
|
||||
// <stdlib.h> -
|
||||
// <string.h> -
|
||||
// <string.h> +
|
||||
// <strings.h> -
|
||||
// <stropts.h> -
|
||||
// <sys/ipc.h> -
|
||||
|
@ -17,6 +17,7 @@ unsafe extern "C" fn perror(message: *const c_char) {
|
||||
out.write_unlocked(b": ").ok();
|
||||
}
|
||||
|
||||
#[allow(static_mut_refs)]
|
||||
out.write_unlocked(error::errno.to_c_str().to_bytes()).ok();
|
||||
out.write_unlocked(b"\n").ok();
|
||||
|
||||
|
@ -14,25 +14,22 @@
|
||||
extern crate alloc;
|
||||
|
||||
use core::{
|
||||
ffi::{c_char, c_int, c_void},
|
||||
ffi::{c_char, c_int},
|
||||
panic::PanicInfo,
|
||||
ptr::null,
|
||||
};
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use yggdrasil_rt::{
|
||||
debug_trace,
|
||||
process::{ExitCode, ProcessId, Signal},
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
use yggdrasil_rt::{debug_trace, process::Signal};
|
||||
|
||||
mod allocator;
|
||||
mod args;
|
||||
mod error;
|
||||
mod io;
|
||||
mod process;
|
||||
mod util;
|
||||
mod sync;
|
||||
mod types;
|
||||
mod util;
|
||||
|
||||
pub mod headers;
|
||||
|
||||
@ -44,7 +41,25 @@ unsafe extern "C" fn _start(arg: usize) {
|
||||
|
||||
io::init();
|
||||
|
||||
let status = main(0, null(), null());
|
||||
// Setup args
|
||||
let (args, envs) = args::handle_kernel_argument(arg);
|
||||
let mut c_args = Vec::new();
|
||||
let mut c_envs = Vec::new();
|
||||
|
||||
for arg in args.iter() {
|
||||
c_args.push(arg.as_ptr());
|
||||
}
|
||||
for env in envs.iter() {
|
||||
c_envs.push(env.as_ptr());
|
||||
}
|
||||
c_args.push(null());
|
||||
c_envs.push(null());
|
||||
|
||||
let status = main(
|
||||
args.len().try_into().unwrap(),
|
||||
c_args.as_ptr(),
|
||||
c_envs.as_ptr(),
|
||||
);
|
||||
|
||||
process::c_exit(status)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user