From d4f60f4942924869e3cd343500c65974b3b01291 Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Sun, 28 Jul 2024 21:01:00 -0700 Subject: [PATCH] Moved process exit to syscall helper. Final call moved so syscall is private now. Also cleans up the macro a fair bit. --- rust/lib/mammoth/src/macros.rs | 19 +++++++------------ rust/lib/mammoth/src/syscall.rs | 8 +++++++- 2 files changed, 14 insertions(+), 13 deletions(-) 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(