diff --git a/rust/lib/mammoth/src/macros.rs b/rust/lib/mammoth/src/macros.rs index 8313961..c977a91 100644 --- a/rust/lib/mammoth/src/macros.rs +++ b/rust/lib/mammoth/src/macros.rs @@ -50,18 +50,13 @@ macro_rules! debug { macro_rules! define_entry { () => { #[no_mangle] - pub extern "C" fn _start(init_port: mammoth::zion::z_cap_t) -> ! { - extern "C" { - fn main() -> z_err_t; - } - mammoth::init::parse_init_port(init_port); - mammoth::mem::init_heap(); - unsafe { - let err = main(); - let req = mammoth::zion::ZProcessExitReq { code: err }; - let _ = mammoth::syscall::syscall(mammoth::zion::kZionProcessExit, &req); - } - unreachable!() + pub extern "C" fn _start(init_port: $crate::zion::z_cap_t) -> ! { + $crate::init::parse_init_port(init_port); + $crate::mem::init_heap(); + + let resp = main(); + + $crate::syscall::process_exit(resp); } }; } diff --git a/rust/lib/mammoth/src/syscall.rs b/rust/lib/mammoth/src/syscall.rs index 3d029bc..0346e7f 100644 --- a/rust/lib/mammoth/src/syscall.rs +++ b/rust/lib/mammoth/src/syscall.rs @@ -7,7 +7,7 @@ use core::ffi::c_void; use core::panic::PanicInfo; #[must_use] -pub fn syscall(id: u64, req: &T) -> Result<(), ZError> { +fn syscall(id: u64, req: &T) -> Result<(), ZError> { unsafe { let resp = zion::SysCall1(id, req as *const T as *const c_void); if resp != 0 { @@ -40,6 +40,12 @@ pub fn debug(msg: &str) { syscall(zion::kZionDebug, &req).expect("Failed to write"); } +pub fn process_exit(code: u64) -> ! { + let _ = syscall(zion::kZionProcessExit, &zion::ZProcessExitReq { code }); + + unreachable!() +} + pub fn thread_create(proc_cap: z_cap_t) -> Result { let mut cap = 0; syscall(