diff --git a/src/arch/aarch64/kernel/scheduler.rs b/src/arch/aarch64/kernel/scheduler.rs index bb24e7c578..ba1d7db638 100644 --- a/src/arch/aarch64/kernel/scheduler.rs +++ b/src/arch/aarch64/kernel/scheduler.rs @@ -13,6 +13,8 @@ use crate::arch::aarch64::kernel::CURRENT_STACK_ADDRESS; use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags}; use crate::arch::aarch64::mm::{PhysAddr, VirtAddr}; use crate::scheduler::task::{Task, TaskFrame}; +#[cfg(target_os = "none")] +use crate::scheduler::PerCoreSchedulerExt; use crate::{kernel, DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE}; #[derive(Debug)] @@ -314,6 +316,12 @@ extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize, _user_stack: u64 unimplemented!() } +#[cfg(target_os = "none")] +extern "C" fn thread_exit(status: i32) -> ! { + debug!("Exit thread with error code {}!", status); + core_scheduler().exit(status) +} + #[cfg(target_os = "none")] #[naked] extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize) -> ! { @@ -331,7 +339,7 @@ extern "C" fn task_start(_f: extern "C" fn(usize), _arg: usize) -> ! { "add x4, x4, #:lo12:{exit}", "br x4", l0 = const 0, - exit = sym crate::sys_thread_exit, + exit = sym thread_exit, options(noreturn) ) } diff --git a/src/arch/x86_64/kernel/processor.rs b/src/arch/x86_64/kernel/processor.rs index 1c6afcbcf8..4271e5849c 100644 --- a/src/arch/x86_64/kernel/processor.rs +++ b/src/arch/x86_64/kernel/processor.rs @@ -844,7 +844,7 @@ pub fn configure() { #[cfg(feature = "fsgsbase")] if !supports_fsgs() { error!("FSGSBASE support is enabled, but the processor doesn't support it!"); - crate::shutdown(1); + crate::scheduler::shutdown(1); } debug!("Set CR4 to {:#x}", cr4); diff --git a/src/arch/x86_64/kernel/scheduler.rs b/src/arch/x86_64/kernel/scheduler.rs index c81ae9a57f..982034cc14 100644 --- a/src/arch/x86_64/kernel/scheduler.rs +++ b/src/arch/x86_64/kernel/scheduler.rs @@ -332,7 +332,8 @@ extern "C" fn task_entry(func: extern "C" fn(usize), arg: usize) -> ! { func(arg); // Exit task - crate::sys_thread_exit(0) + debug!("Exit thread with error code 0!"); + core_scheduler().exit(0) } impl TaskFrame for Task { diff --git a/src/executor/device.rs b/src/executor/device.rs index 7879f1bd26..83dfae38c8 100644 --- a/src/executor/device.rs +++ b/src/executor/device.rs @@ -10,7 +10,7 @@ use smoltcp::socket::dhcpv4; #[cfg(all(feature = "dns", not(feature = "dhcpv4")))] use smoltcp::socket::dns; use smoltcp::time::Instant; -#[cfg(any(feature = "dns", not(feature = "dhcpv4")))] +#[cfg(not(feature = "dhcpv4"))] use smoltcp::wire::Ipv4Address; use smoltcp::wire::{EthernetAddress, HardwareAddress}; #[cfg(not(feature = "dhcpv4"))] diff --git a/src/fd/socket/udp.rs b/src/fd/socket/udp.rs index 054df2dad5..10a9719b6a 100644 --- a/src/fd/socket/udp.rs +++ b/src/fd/socket/udp.rs @@ -15,12 +15,6 @@ use crate::executor::network::{now, Handle, NetworkState, NIC}; use crate::executor::{block_on, poll_on}; use crate::fd::{IoCtl, IoError, ObjectInterface, PollEvent}; -#[derive(Debug)] -pub struct IPv4; - -#[derive(Debug)] -pub struct IPv6; - #[derive(Debug)] pub struct Socket { handle: Handle, diff --git a/src/lib.rs b/src/lib.rs index 650f5448ac..b939c26384 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,6 @@ pub(crate) use crate::config::*; pub use crate::fs::create_file; use crate::kernel::is_uhyve_with_pci; use crate::scheduler::{PerCoreScheduler, PerCoreSchedulerExt}; -pub use crate::syscalls::*; #[macro_use] mod macros; @@ -103,7 +102,7 @@ hermit_entry::define_entry_version!(); extern "C" fn runtime_entry(_argc: i32, _argv: *const *const u8, _env: *const *const u8) -> ! { println!("Executing hermit unittests. Any arguments are dropped"); test_main(); - sys_exit(0); + core_scheduler().exit(0) } //https://github.com/rust-lang/rust/issues/50297#issuecomment-524180479 @@ -113,7 +112,7 @@ pub fn test_runner(tests: &[&dyn Fn()]) { for test in tests { test(); } - sys_exit(0); + core_scheduler().exit(0) } #[cfg(target_os = "none")] @@ -275,5 +274,5 @@ fn panic(info: &core::panic::PanicInfo<'_>) -> ! { let core_id = crate::arch::core_local::core_id(); println!("[{core_id}][PANIC] {info}"); - crate::shutdown(1); + crate::scheduler::shutdown(1); } diff --git a/src/scheduler/mod.rs b/src/scheduler/mod.rs index 8404852746..9c7ca0f29e 100644 --- a/src/scheduler/mod.rs +++ b/src/scheduler/mod.rs @@ -986,6 +986,10 @@ pub fn join(id: TaskId) -> Result<(), ()> { } } +pub fn shutdown(arg: i32) -> ! { + crate::syscalls::shutdown(arg) +} + fn get_task_handle(id: TaskId) -> Option { TASKS.lock().get(&id).copied() } diff --git a/src/shell.rs b/src/shell.rs index 52cab9ac17..77dd76659a 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -39,7 +39,7 @@ static mut SHELL: Lazy> = Lazy::new(|| { ShellCommand { help: "Shutdown HermitOS", func: |_, shell| { - crate::shutdown(0); + crate::scheduler::shutdown(0); Ok(()) }, aliases: &["s"], diff --git a/src/syscalls/semaphore.rs b/src/syscalls/semaphore.rs index 98fc0336bc..c11db47667 100644 --- a/src/syscalls/semaphore.rs +++ b/src/syscalls/semaphore.rs @@ -2,6 +2,7 @@ use alloc::boxed::Box; use crate::errno::*; use crate::synch::semaphore::Semaphore; +use crate::syscalls::{sys_clock_gettime, CLOCK_REALTIME}; use crate::time::timespec; #[allow(non_camel_case_types)] @@ -120,7 +121,7 @@ pub unsafe extern "C" fn sys_sem_timedwait(sem: *mut sem_t, ts: *const timespec) let mut current_ts: timespec = Default::default(); unsafe { - crate::sys_clock_gettime(crate::CLOCK_REALTIME, &mut current_ts as *mut _); + sys_clock_gettime(CLOCK_REALTIME, &mut current_ts as *mut _); let ts = &*ts; let ms: i64 = (ts.tv_sec - current_ts.tv_sec) * 1000 diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 618443087a..b6294b86dc 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -203,8 +203,8 @@ pub fn exit(failure: bool) -> ! { if hermit::_is_uhyve() { match failure { //ToDo: Add uhyve exit code enum - true => hermit::sys_exit(1), - false => hermit::sys_exit(0), + true => hermit::syscalls::sys_exit(1), + false => hermit::syscalls::sys_exit(0), } } else { match failure { @@ -223,7 +223,7 @@ pub fn exit_qemu(exit_code: QemuExitCode) -> ! { outl(0xf4, exit_code as u32); } println!("Warning - Failed to debug exit qemu - exiting via sys_exit()"); - hermit::sys_exit(0) //sys_exit exitcode on qemu gets silently dropped + hermit::syscalls::sys_exit(0) //sys_exit exitcode on qemu gets silently dropped } // ToDo: Maybe we could add a hard limit on the length of `s` to make this slightly safer? diff --git a/tests/thread.rs b/tests/thread.rs index 776bba5b97..61dc0a8f76 100644 --- a/tests/thread.rs +++ b/tests/thread.rs @@ -18,8 +18,8 @@ mod common; use alloc::vec; use hermit::errno::{EAGAIN, ETIMEDOUT}; +use hermit::syscalls::{sys_futex_wait, sys_futex_wake, sys_join, sys_spawn2, sys_usleep}; use hermit::time::timespec; -use hermit::{sys_futex_wait, sys_futex_wake, sys_join, sys_spawn2, sys_usleep}; const USER_STACK_SIZE: usize = 1_048_576; const NORMAL_PRIO: u8 = 2;