Переглянути джерело

style: reformat files

No functional changes.

Signed-off-by: greatbridf <greatbridf@icloud.com>
greatbridf 1 тиждень тому
батько
коміт
681a121774

+ 6 - 7
crates/eonix_hal/eonix_hal_traits/src/trap.rs

@@ -1,7 +1,10 @@
-use crate::{context::RawTaskContext, fault::Fault};
 use core::marker::PhantomData;
+
 use eonix_mm::address::VAddr;
 
+use crate::context::RawTaskContext;
+use crate::fault::Fault;
+
 /// A raw trap context.
 ///
 /// This should be implemented by the architecture-specific trap context
@@ -30,12 +33,8 @@ pub trait RawTrapContext: Copy {
     fn set_user_return_value(&mut self, retval: usize);
 
     fn set_user_call_frame<E>(
-        &mut self,
-        pc: usize,
-        sp: Option<usize>,
-        ra: Option<usize>,
-        args: &[usize],
-        write_memory: impl Fn(VAddr, &[u8]) -> Result<(), E>,
+        &mut self, pc: usize, sp: Option<usize>, ra: Option<usize>,
+        args: &[usize], write_memory: impl Fn(VAddr, &[u8]) -> Result<(), E>,
     ) -> Result<(), E>;
 }
 

+ 36 - 30
crates/eonix_hal/src/arch/riscv64/trap/trap_context.rs

@@ -1,19 +1,17 @@
-use crate::{arch::time::set_next_timer, processor::CPU};
-use core::{arch::asm, mem::offset_of};
-use eonix_hal_traits::{
-    fault::{Fault, PageFaultErrorCode},
-    trap::{RawTrapContext, TrapType},
-};
+use core::arch::asm;
+use core::mem::offset_of;
+
+use eonix_hal_traits::fault::{Fault, PageFaultErrorCode};
+use eonix_hal_traits::trap::{RawTrapContext, TrapType};
 use eonix_mm::address::VAddr;
-use riscv::{
-    interrupt::{Exception, Interrupt, Trap},
-    register::{
-        scause::{self, Scause},
-        sstatus::{self, Sstatus, FS, SPP},
-        stval,
-    },
-    ExceptionNumber, InterruptNumber,
-};
+use riscv::interrupt::{Exception, Interrupt, Trap};
+use riscv::register::scause::{self, Scause};
+use riscv::register::sstatus::{self, Sstatus, FS, SPP};
+use riscv::register::stval;
+use riscv::{ExceptionNumber, InterruptNumber};
+
+use crate::arch::time::set_next_timer;
+use crate::processor::CPU;
 
 #[repr(C)]
 #[derive(Default, Clone, Copy)]
@@ -151,10 +149,13 @@ impl RawTrapContext for TrapContext {
                     Interrupt::SupervisorExternal => TrapType::Irq {
                         callback: |handler| {
                             let mut cpu = CPU::local();
-                            match cpu.as_mut().interrupt.plic.claim_interrupt() {
+                            match cpu.as_mut().interrupt.plic.claim_interrupt()
+                            {
                                 None => {}
                                 Some(irqno) => {
-                                    cpu.interrupt.plic.complete_interrupt(irqno);
+                                    cpu.interrupt
+                                        .plic
+                                        .complete_interrupt(irqno);
                                     handler(irqno);
                                 }
                             }
@@ -172,18 +173,25 @@ impl RawTrapContext for TrapContext {
                     | Exception::InstructionFault
                     | Exception::LoadFault
                     | Exception::StoreFault
-                    | Exception::StoreMisaligned => TrapType::Fault(Fault::BadAccess),
-                    Exception::IllegalInstruction => TrapType::Fault(Fault::InvalidOp),
+                    | Exception::StoreMisaligned => {
+                        TrapType::Fault(Fault::BadAccess)
+                    }
+                    Exception::IllegalInstruction => {
+                        TrapType::Fault(Fault::InvalidOp)
+                    }
                     Exception::UserEnvCall => TrapType::Syscall {
                         no: self.syscall_no(),
                         args: self.syscall_args(),
                     },
                     exception @ (Exception::InstructionPageFault
                     | Exception::LoadPageFault
-                    | Exception::StorePageFault) => TrapType::Fault(Fault::PageFault {
-                        error_code: self.get_page_fault_error_code(exception),
-                        address: VAddr::from(self.stval),
-                    }),
+                    | Exception::StorePageFault) => {
+                        TrapType::Fault(Fault::PageFault {
+                            error_code: self
+                                .get_page_fault_error_code(exception),
+                            address: VAddr::from(self.stval),
+                        })
+                    }
                     // breakpoint and supervisor env call
                     _ => TrapType::Fault(Fault::Unknown(e)),
                 }
@@ -239,12 +247,8 @@ impl RawTrapContext for TrapContext {
     }
 
     fn set_user_call_frame<E>(
-        &mut self,
-        pc: usize,
-        sp: Option<usize>,
-        ra: Option<usize>,
-        args: &[usize],
-        _write_memory: impl Fn(VAddr, &[u8]) -> Result<(), E>,
+        &mut self, pc: usize, sp: Option<usize>, ra: Option<usize>,
+        args: &[usize], _write_memory: impl Fn(VAddr, &[u8]) -> Result<(), E>,
     ) -> Result<(), E> {
         self.set_program_counter(pc);
 
@@ -275,7 +279,9 @@ impl RawTrapContext for TrapContext {
 
 impl TrapContext {
     /// TODO: get PageFaultErrorCode also need check pagetable
-    fn get_page_fault_error_code(&self, exception: Exception) -> PageFaultErrorCode {
+    fn get_page_fault_error_code(
+        &self, exception: Exception,
+    ) -> PageFaultErrorCode {
         let mut error_code = PageFaultErrorCode::empty();
 
         match exception {

+ 35 - 31
crates/eonix_hal/src/arch/x86_64/bootstrap/init.rs

@@ -1,30 +1,29 @@
-use crate::{
-    arch::{
-        bootstrap::{EARLY_GDT_DESCRIPTOR, KERNEL_PML4},
-        cpu::{wrmsr, CPU},
-        io::Port8,
-        mm::{ArchPhysAccess, GLOBAL_PAGE_TABLE, V_KERNEL_BSS_START},
-    },
-    bootstrap::BootStrapData,
-    mm::{ArchMemory, ArchPagingMode, BasicPageAlloc, BasicPageAllocRef, ScopedAllocator},
-};
-use acpi::{platform::ProcessorState, AcpiHandler, AcpiTables, PhysicalMapping, PlatformInfo};
-use core::{
-    alloc::Allocator,
-    arch::{asm, global_asm},
-    cell::RefCell,
-    hint::spin_loop,
-    sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering},
-};
+use core::alloc::Allocator;
+use core::arch::{asm, global_asm};
+use core::cell::RefCell;
+use core::hint::spin_loop;
+use core::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering};
+
+use acpi::platform::ProcessorState;
+use acpi::{AcpiHandler, AcpiTables, PhysicalMapping, PlatformInfo};
 use eonix_hal_traits::mm::Memory;
-use eonix_mm::{
-    address::{Addr as _, PAddr, PRange, PhysAccess, VRange},
-    page_table::{PageAttribute, PagingMode, PTE as _},
-    paging::{Page, PageAccess, PageAlloc, PAGE_SIZE},
-};
+use eonix_mm::address::{Addr as _, PAddr, PRange, PhysAccess, VRange};
+use eonix_mm::page_table::{PageAttribute, PagingMode, PTE as _};
+use eonix_mm::paging::{Page, PageAccess, PageAlloc, PAGE_SIZE};
 use eonix_percpu::PercpuArea;
 
-static BSP_PAGE_ALLOC: AtomicPtr<RefCell<BasicPageAlloc>> = AtomicPtr::new(core::ptr::null_mut());
+use crate::arch::bootstrap::{EARLY_GDT_DESCRIPTOR, KERNEL_PML4};
+use crate::arch::cpu::{wrmsr, CPU};
+use crate::arch::io::Port8;
+use crate::arch::mm::{ArchPhysAccess, GLOBAL_PAGE_TABLE, V_KERNEL_BSS_START};
+use crate::bootstrap::BootStrapData;
+use crate::mm::{
+    ArchMemory, ArchPagingMode, BasicPageAlloc, BasicPageAllocRef,
+    ScopedAllocator,
+};
+
+static BSP_PAGE_ALLOC: AtomicPtr<RefCell<BasicPageAlloc>> =
+    AtomicPtr::new(core::ptr::null_mut());
 
 static AP_COUNT: AtomicUsize = AtomicUsize::new(0);
 static AP_STACK: AtomicUsize = AtomicUsize::new(0);
@@ -188,9 +187,7 @@ fn bootstrap_smp(alloc: impl Allocator, page_alloc: &RefCell<BasicPageAlloc>) {
 
     impl AcpiHandler for Handler {
         unsafe fn map_physical_region<T>(
-            &self,
-            physical_address: usize,
-            size: usize,
+            &self, physical_address: usize, size: usize,
         ) -> PhysicalMapping<Self, T> {
             unsafe {
                 PhysicalMapping::new(
@@ -236,7 +233,8 @@ fn bootstrap_smp(alloc: impl Allocator, page_alloc: &RefCell<BasicPageAlloc>) {
         };
 
         // SAFETY: All the APs can see the allocator work done before this point.
-        let old = BSP_PAGE_ALLOC.swap((&raw const *page_alloc) as *mut _, Ordering::Release);
+        let old = BSP_PAGE_ALLOC
+            .swap((&raw const *page_alloc) as *mut _, Ordering::Release);
         assert!(
             old.is_null(),
             "BSP_PAGE_ALLOC should be null before we release it"
@@ -305,7 +303,11 @@ pub extern "C" fn kernel_init() -> ! {
 
     unsafe {
         // SAFETY: We've just mapped the area with sufficient length.
-        core::ptr::write_bytes(V_KERNEL_BSS_START.addr() as *mut (), 0, BSS_LENGTH as usize);
+        core::ptr::write_bytes(
+            V_KERNEL_BSS_START.addr() as *mut (),
+            0,
+            BSS_LENGTH as usize,
+        );
     }
 
     setup_cpu(&alloc);
@@ -329,12 +331,14 @@ pub extern "C" fn kernel_init() -> ! {
 }
 
 pub extern "C" fn ap_entry(stack_bottom: PAddr) -> ! {
-    let stack_range = PRange::new(stack_bottom - (1 << 3) * PAGE_SIZE, stack_bottom);
+    let stack_range =
+        PRange::new(stack_bottom - (1 << 3) * PAGE_SIZE, stack_bottom);
 
     {
         // SAFETY: Acquire all the work done by the BSP and other APs.
         let alloc = loop {
-            let alloc = BSP_PAGE_ALLOC.swap(core::ptr::null_mut(), Ordering::AcqRel);
+            let alloc =
+                BSP_PAGE_ALLOC.swap(core::ptr::null_mut(), Ordering::AcqRel);
 
             if !alloc.is_null() {
                 break alloc;

+ 2 - 1
crates/eonix_hal/src/arch/x86_64/context.rs

@@ -1,4 +1,5 @@
 use core::arch::naked_asm;
+
 use eonix_hal_traits::context::RawTaskContext;
 
 /// Necessary hardware states of task for doing context switches.
@@ -36,7 +37,7 @@ impl TaskContext {
     }
 
     #[unsafe(naked)]
-    unsafe extern "C" fn do_call() -> ! {
+    unsafe extern "C" fn do_call() {
         naked_asm!(
             "mov %r12, %rdi",
             "push %rbp", // NULL return address.

+ 8 - 4
crates/eonix_hal/src/arch/x86_64/cpu.rs

@@ -1,13 +1,15 @@
-use super::gdt::{GDTEntry, GDT};
-use super::interrupt::InterruptControl;
-use super::trap::TrapContext;
 use core::arch::asm;
 use core::marker::PhantomPinned;
 use core::mem::size_of;
 use core::pin::Pin;
+
 use eonix_preempt::PreemptGuard;
 use eonix_sync_base::LazyLock;
 
+use super::gdt::{GDTEntry, GDT};
+use super::interrupt::InterruptControl;
+use super::trap::TrapContext;
+
 #[eonix_percpu::define_percpu]
 static LOCAL_CPU: LazyLock<CPU> = LazyLock::new(CPU::new);
 
@@ -55,7 +57,9 @@ pub struct CPU {
 impl UserTLS {
     /// # Return
     /// Returns the TLS descriptor and the index of the TLS segment.
-    pub fn new32(base: u32, limit: u32, is_limit_in_pages: bool) -> (Self, u32) {
+    pub fn new32(
+        base: u32, limit: u32, is_limit_in_pages: bool,
+    ) -> (Self, u32) {
         let flags = if is_limit_in_pages { 0xc } else { 0x4 };
 
         (

+ 3 - 1
crates/eonix_hal/src/arch/x86_64/gdt.rs

@@ -1,5 +1,7 @@
+use core::arch::asm;
+use core::marker::PhantomPinned;
+
 use super::cpu::TSS;
-use core::{arch::asm, marker::PhantomPinned};
 
 #[repr(transparent)]
 #[derive(Debug, Clone, Copy)]

+ 7 - 2
crates/eonix_hal/src/arch/x86_64/interrupt.rs

@@ -1,5 +1,9 @@
+use core::arch::asm;
+use core::marker::PhantomPinned;
+use core::pin::Pin;
+use core::ptr::NonNull;
+
 use crate::arch::cpu::rdmsr;
-use core::{arch::asm, marker::PhantomPinned, pin::Pin, ptr::NonNull};
 
 #[repr(C)]
 #[derive(Clone, Copy)]
@@ -121,7 +125,8 @@ impl InterruptControl {
             let apic_base = rdmsr(0x1b);
             assert_eq!(apic_base & 0x800, 0x800, "LAPIC not enabled");
 
-            let apic_base = ((apic_base & !0xfff) + 0xffffff00_00000000) as *mut u32;
+            let apic_base =
+                ((apic_base & !0xfff) + 0xffffff00_00000000) as *mut u32;
             APICRegs {
                 // TODO: A better way to convert to physical address
                 base: NonNull::new(apic_base).expect("Invalid APIC base"),

+ 20 - 15
crates/eonix_hal/src/arch/x86_64/mm.rs

@@ -1,15 +1,19 @@
-use crate::traits::mm::Memory;
-use core::{arch::asm, marker::PhantomData, ptr::NonNull};
-use eonix_mm::{
-    address::{Addr as _, AddrOps as _, PAddr, PRange, PhysAccess, VAddr},
-    page_table::{
-        PageAttribute, PageTable, PageTableLevel, PagingMode, RawAttribute, RawPageTable,
-        TableAttribute, PTE,
-    },
-    paging::{NoAlloc, Page, PageBlock, PAGE_SIZE, PFN},
+use core::arch::asm;
+use core::marker::PhantomData;
+use core::ptr::NonNull;
+
+use eonix_mm::address::{
+    Addr as _, AddrOps as _, PAddr, PRange, PhysAccess, VAddr,
+};
+use eonix_mm::page_table::{
+    PageAttribute, PageTable, PageTableLevel, PagingMode, RawAttribute,
+    RawPageTable, TableAttribute, PTE,
 };
+use eonix_mm::paging::{NoAlloc, Page, PageBlock, PAGE_SIZE, PFN};
 use eonix_sync_base::LazyLock;
 
+use crate::traits::mm::Memory;
+
 pub const PA_P: u64 = 0x001;
 pub const PA_RW: u64 = 0x002;
 pub const PA_US: u64 = 0x004;
@@ -32,12 +36,13 @@ pub const V_KERNEL_BSS_START: VAddr = VAddr::from(0xffffffffc0200000);
 
 const KERNEL_PML4_PFN: PFN = PFN::from_val(0x1000 >> 12);
 
-pub static GLOBAL_PAGE_TABLE: LazyLock<PageTable<ArchPagingMode, NoAlloc, ArchPhysAccess>> =
-    LazyLock::new(|| unsafe {
-        Page::with_raw(KERNEL_PML4_PFN, |root_table_page| {
-            PageTable::with_root_table(root_table_page.clone())
-        })
-    });
+pub static GLOBAL_PAGE_TABLE: LazyLock<
+    PageTable<ArchPagingMode, NoAlloc, ArchPhysAccess>,
+> = LazyLock::new(|| unsafe {
+    Page::with_raw(KERNEL_PML4_PFN, |root_table_page| {
+        PageTable::with_root_table(root_table_page.clone())
+    })
+});
 
 #[repr(transparent)]
 pub struct PTE64(u64);

+ 7 - 11
crates/eonix_hal/src/arch/x86_64/trap/trap_context.rs

@@ -1,11 +1,11 @@
-use crate::processor::CPU;
 use core::arch::asm;
-use eonix_hal_traits::{
-    fault::{Fault, PageFaultErrorCode},
-    trap::{RawTrapContext, TrapType},
-};
+
+use eonix_hal_traits::fault::{Fault, PageFaultErrorCode};
+use eonix_hal_traits::trap::{RawTrapContext, TrapType};
 use eonix_mm::address::VAddr;
 
+use crate::processor::CPU;
+
 #[derive(Clone, Copy, Default)]
 #[repr(C, align(16))]
 pub struct TrapContext {
@@ -169,12 +169,8 @@ impl RawTrapContext for TrapContext {
     }
 
     fn set_user_call_frame<E>(
-        &mut self,
-        pc: usize,
-        sp: Option<usize>,
-        ra: Option<usize>,
-        args: &[usize],
-        write_memory: impl Fn(VAddr, &[u8]) -> Result<(), E>,
+        &mut self, pc: usize, sp: Option<usize>, ra: Option<usize>,
+        args: &[usize], write_memory: impl Fn(VAddr, &[u8]) -> Result<(), E>,
     ) -> Result<(), E> {
         self.set_program_counter(pc);
 

+ 88 - 71
src/kernel/syscall/procops.rs

@@ -16,17 +16,21 @@ use posix_types::SIGNAL_NOW;
 use super::SyscallNoReturn;
 use crate::io::Buffer;
 use crate::kernel::constants::{
-    CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_REALTIME_COARSE, EINVAL, ENOENT, ENOSYS, ENOTDIR,
-    ERANGE, ESRCH, PR_GET_NAME, PR_SET_NAME, RLIMIT_STACK, SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK,
+    CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_REALTIME_COARSE, EINVAL, ENOENT,
+    ENOSYS, ENOTDIR, ERANGE, ESRCH, PR_GET_NAME, PR_SET_NAME, RLIMIT_STACK,
+    SIG_BLOCK, SIG_SETMASK, SIG_UNBLOCK,
 };
 use crate::kernel::mem::PageBuffer;
 use crate::kernel::syscall::{User, UserMut};
 use crate::kernel::task::{
-    do_clone, futex_exec, futex_wait, futex_wake, parse_futexop, yield_now, CloneArgs, FutexFlags,
-    FutexOp, ProcessList, ProgramLoader, RobustListHead, SignalAction, Thread, WaitId, WaitType,
+    do_clone, futex_exec, futex_wait, futex_wake, parse_futexop, yield_now,
+    CloneArgs, FutexFlags, FutexOp, ProcessList, ProgramLoader, RobustListHead,
+    SignalAction, Thread, WaitId, WaitType,
 };
 use crate::kernel::timer::sleep;
-use crate::kernel::user::{UserBuffer, UserPointer, UserPointerMut, UserString};
+use crate::kernel::user::{
+    UserBuffer, UserPointer, UserPointerMut, UserString,
+};
 use crate::kernel::vfs::dentry::Dentry;
 use crate::kernel::vfs::types::Permission;
 use crate::kernel::vfs::{self};
@@ -49,7 +53,9 @@ bitflags! {
 }
 
 #[eonix_macros::define_syscall(SYS_NANOSLEEP)]
-async fn nanosleep(req: User<(u32, u32)>, rem: UserMut<(u32, u32)>) -> KResult<usize> {
+async fn nanosleep(
+    req: User<(u32, u32)>, rem: UserMut<(u32, u32)>,
+) -> KResult<usize> {
     let req = UserPointer::new(req)?.read()?;
     let rem = if rem.is_null() {
         None
@@ -57,7 +63,8 @@ async fn nanosleep(req: User<(u32, u32)>, rem: UserMut<(u32, u32)>) -> KResult<u
         Some(UserPointerMut::new(rem)?)
     };
 
-    let duration = Duration::from_secs(req.0 as u64) + Duration::from_nanos(req.1 as u64);
+    let duration =
+        Duration::from_secs(req.0 as u64) + Duration::from_nanos(req.1 as u64);
     sleep(duration).await;
 
     if let Some(rem) = rem {
@@ -69,10 +76,7 @@ async fn nanosleep(req: User<(u32, u32)>, rem: UserMut<(u32, u32)>) -> KResult<u
 
 #[eonix_macros::define_syscall(SYS_CLOCK_NANOSLEEP)]
 async fn clock_nanosleep(
-    clock_id: u32,
-    _flags: u32,
-    req: User<(u32, u32)>,
-    rem: UserMut<(u32, u32)>,
+    clock_id: u32, _flags: u32, req: User<(u32, u32)>, rem: UserMut<(u32, u32)>,
 ) -> KResult<usize> {
     if clock_id != CLOCK_REALTIME
         && clock_id != CLOCK_REALTIME_COARSE
@@ -88,7 +92,8 @@ async fn clock_nanosleep(
         Some(UserPointerMut::new(rem)?)
     };
 
-    let duration = Duration::from_secs(req.0 as u64) + Duration::from_nanos(req.1 as u64);
+    let duration =
+        Duration::from_secs(req.0 as u64) + Duration::from_nanos(req.1 as u64);
     sleep(duration).await;
 
     if let Some(rem) = rem {
@@ -101,7 +106,8 @@ async fn clock_nanosleep(
 #[eonix_macros::define_syscall(SYS_UMASK)]
 async fn umask(raw_new_mask: u32) -> KResult<u32> {
     let new_mask = Permission::new(!raw_new_mask);
-    let old_mask = core::mem::replace(&mut *thread.fs_context.umask.lock(), new_mask);
+    let old_mask =
+        core::mem::replace(&mut *thread.fs_context.umask.lock(), new_mask);
 
     Ok(!old_mask.bits())
 }
@@ -147,7 +153,9 @@ async fn umount(source: User<u8>) -> KResult<()> {
 }
 
 #[eonix_macros::define_syscall(SYS_MOUNT)]
-async fn mount(source: User<u8>, target: User<u8>, fstype: User<u8>, flags: usize) -> KResult<()> {
+async fn mount(
+    source: User<u8>, target: User<u8>, fstype: User<u8>, flags: usize,
+) -> KResult<()> {
     let source = UserString::new(source)?;
     if source.as_cstr().to_str().unwrap() == "/dev/vda2" {
         return Ok(());
@@ -176,7 +184,9 @@ async fn mount(source: User<u8>, target: User<u8>, fstype: User<u8>, flags: usiz
     .await
 }
 
-fn get_strings(mut ptr_strings: UserPointer<'_, PtrT>) -> KResult<Vec<CString>> {
+fn get_strings(
+    mut ptr_strings: UserPointer<'_, PtrT>,
+) -> KResult<Vec<CString>> {
     let mut strings = Vec::new();
 
     loop {
@@ -194,24 +204,34 @@ fn get_strings(mut ptr_strings: UserPointer<'_, PtrT>) -> KResult<Vec<CString>>
 }
 
 #[eonix_macros::define_syscall(SYS_EXECVE)]
-async fn execve(exec: User<u8>, argv: User<PtrT>, envp: User<PtrT>) -> KResult<SyscallNoReturn> {
+async fn execve(
+    exec: User<u8>, argv: User<PtrT>, envp: User<PtrT>,
+) -> KResult<SyscallNoReturn> {
     let exec = UserString::new(exec)?;
     let exec = exec.as_cstr().to_owned();
 
     let argv = get_strings(UserPointer::new(argv)?)?;
     let envp = get_strings(UserPointer::new(envp)?)?;
 
-    let dentry = Dentry::open(&thread.fs_context, Path::new(exec.as_bytes())?, true).await?;
+    let dentry =
+        Dentry::open(&thread.fs_context, Path::new(exec.as_bytes())?, true)
+            .await?;
     if !dentry.is_valid() {
         Err(ENOENT)?;
     }
 
     // TODO: When `execve` is called by one of the threads in a process, the other threads
     //       should be terminated and `execve` is performed in the thread group leader.
-    let load_info = ProgramLoader::parse(&thread.fs_context, exec, dentry.clone(), argv, envp)
-        .await?
-        .load()
-        .await?;
+    let load_info = ProgramLoader::parse(
+        &thread.fs_context,
+        exec,
+        dentry.clone(),
+        argv,
+        envp,
+    )
+    .await?
+    .load()
+    .await?;
 
     futex_exec(thread).await;
 
@@ -257,10 +277,7 @@ enum WaitInfo {
 }
 
 async fn do_waitid(
-    thread: &Thread,
-    wait_id: WaitId,
-    info: WaitInfo,
-    options: u32,
+    thread: &Thread, wait_id: WaitId, info: WaitInfo, options: u32,
     rusage: UserMut<RUsage>,
 ) -> KResult<u32> {
     if !rusage.is_null() {
@@ -300,7 +317,8 @@ async fn do_waitid(
             Ok(0)
         }
         WaitInfo::Status(status_ptr) => {
-            UserPointerMut::new(status_ptr)?.write(wait_object.code.to_wstatus())?;
+            UserPointerMut::new(status_ptr)?
+                .write(wait_object.code.to_wstatus())?;
             Ok(wait_object.pid)
         }
         WaitInfo::None => Ok(wait_object.pid),
@@ -309,10 +327,7 @@ async fn do_waitid(
 
 #[eonix_macros::define_syscall(SYS_WAITID)]
 async fn waitid(
-    id_type: u32,
-    id: u32,
-    info: UserMut<SigInfo>,
-    options: u32,
+    id_type: u32, id: u32, info: UserMut<SigInfo>, options: u32,
     rusage: UserMut<RUsage>,
 ) -> KResult<u32> {
     let wait_id = WaitId::from_type_and_id(id_type, id)?;
@@ -334,10 +349,7 @@ async fn waitid(
 
 #[eonix_macros::define_syscall(SYS_WAIT4)]
 async fn wait4(
-    wait_id: i32,
-    arg1: UserMut<u32>,
-    options: u32,
-    rusage: UserMut<RUsage>,
+    wait_id: i32, arg1: UserMut<u32>, options: u32, rusage: UserMut<RUsage>,
 ) -> KResult<u32> {
     let waitinfo = if arg1.is_null() {
         WaitInfo::None
@@ -352,7 +364,9 @@ async fn wait4(
 
 #[cfg(target_arch = "x86_64")]
 #[eonix_macros::define_syscall(SYS_WAITPID)]
-async fn waitpid(waitpid: i32, arg1: UserMut<u32>, options: u32) -> KResult<u32> {
+async fn waitpid(
+    waitpid: i32, arg1: UserMut<u32>, options: u32,
+) -> KResult<u32> {
     sys_wait4(thread, waitpid, arg1, options, UserMut::null()).await
 }
 
@@ -503,7 +517,9 @@ async fn set_tid_address(tidptr: UserMut<u32>) -> KResult<u32> {
 async fn prctl(option: u32, arg2: PtrT) -> KResult<()> {
     match option {
         PR_SET_NAME => {
-            let name = UserPointer::<[u8; 16]>::new(User::with_addr(arg2.addr()))?.read()?;
+            let name =
+                UserPointer::<[u8; 16]>::new(User::with_addr(arg2.addr()))?
+                    .read()?;
             let len = name.iter().position(|&c| c == 0).unwrap_or(15);
             thread.set_name(name[..len].into());
             Ok(())
@@ -511,8 +527,10 @@ async fn prctl(option: u32, arg2: PtrT) -> KResult<()> {
         PR_GET_NAME => {
             let name = thread.get_name();
             let len = name.len().min(15);
-            let name: [u8; 16] = core::array::from_fn(|i| if i < len { name[i] } else { 0 });
-            UserPointerMut::<[u8; 16]>::new(UserMut::with_addr(arg2.addr()))?.write(name)?;
+            let name: [u8; 16] =
+                core::array::from_fn(|i| if i < len { name[i] } else { 0 });
+            UserPointerMut::<[u8; 16]>::new(UserMut::with_addr(arg2.addr()))?
+                .write(name)?;
             Ok(())
         }
         _ => Err(EINVAL),
@@ -572,10 +590,7 @@ async fn tgkill(tgid: u32, tid: u32, sig: u32) -> KResult<()> {
 
 #[eonix_macros::define_syscall(SYS_RT_SIGPROCMASK)]
 async fn rt_sigprocmask(
-    how: u32,
-    set: UserMut<SigSet>,
-    oldset: UserMut<SigSet>,
-    sigsetsize: usize,
+    how: u32, set: UserMut<SigSet>, oldset: UserMut<SigSet>, sigsetsize: usize,
 ) -> KResult<()> {
     if sigsetsize != size_of::<SigSet>() {
         return Err(EINVAL);
@@ -607,9 +622,7 @@ async fn rt_sigprocmask(
     eonix_macros::define_syscall(SYS_RT_SIGTIMEDWAIT)
 )]
 async fn rt_sigtimedwait(
-    _uthese: User<SigSet>,
-    _uinfo: UserMut<SigInfo>,
-    _uts: User<TimeSpec>,
+    _uthese: User<SigSet>, _uinfo: UserMut<SigInfo>, _uts: User<TimeSpec>,
 ) -> KResult<i32> {
     // TODO
     Ok(0)
@@ -617,9 +630,7 @@ async fn rt_sigtimedwait(
 
 #[eonix_macros::define_syscall(SYS_RT_SIGACTION)]
 async fn rt_sigaction(
-    signum: u32,
-    act: User<SigAction>,
-    oldact: UserMut<SigAction>,
+    signum: u32, act: User<SigAction>, oldact: UserMut<SigAction>,
     sigsetsize: usize,
 ) -> KResult<()> {
     let signal = Signal::try_from_raw(signum)?;
@@ -649,9 +660,7 @@ async fn rt_sigaction(
 
 #[eonix_macros::define_syscall(SYS_PRLIMIT64)]
 async fn prlimit64(
-    pid: u32,
-    resource: u32,
-    new_limit: User<RLimit>,
+    pid: u32, resource: u32, new_limit: User<RLimit>,
     old_limit: UserMut<RLimit>,
 ) -> KResult<()> {
     if pid != 0 {
@@ -764,13 +773,16 @@ async fn fork() -> KResult<u32> {
 #[cfg(not(target_arch = "loongarch64"))]
 #[eonix_macros::define_syscall(SYS_CLONE)]
 async fn clone(
-    clone_flags: usize,
-    new_sp: usize,
-    parent_tidptr: UserMut<u32>,
-    tls: PtrT,
+    clone_flags: usize, new_sp: usize, parent_tidptr: UserMut<u32>, tls: PtrT,
     child_tidptr: UserMut<u32>,
 ) -> KResult<u32> {
-    let clone_args = CloneArgs::for_clone(clone_flags, new_sp, child_tidptr, parent_tidptr, tls)?;
+    let clone_args = CloneArgs::for_clone(
+        clone_flags,
+        new_sp,
+        child_tidptr,
+        parent_tidptr,
+        tls,
+    )?;
 
     do_clone(thread, clone_args).await
 }
@@ -778,24 +790,23 @@ async fn clone(
 #[cfg(target_arch = "loongarch64")]
 #[eonix_macros::define_syscall(SYS_CLONE)]
 async fn clone(
-    clone_flags: usize,
-    new_sp: usize,
-    parent_tidptr: UserMut<u32>,
-    child_tidptr: UserMut<u32>,
-    tls: usize,
+    clone_flags: usize, new_sp: usize, parent_tidptr: UserMut<u32>,
+    child_tidptr: UserMut<u32>, tls: usize,
 ) -> KResult<u32> {
-    let clone_args = CloneArgs::for_clone(clone_flags, new_sp, child_tidptr, parent_tidptr, tls)?;
+    let clone_args = CloneArgs::for_clone(
+        clone_flags,
+        new_sp,
+        child_tidptr,
+        parent_tidptr,
+        tls,
+    )?;
 
     do_clone(thread, clone_args).await
 }
 
 #[eonix_macros::define_syscall(SYS_FUTEX)]
 async fn futex(
-    uaddr: usize,
-    op: u32,
-    val: u32,
-    _time_out: usize,
-    _uaddr2: usize,
+    uaddr: usize, op: u32, val: u32, _time_out: usize, _uaddr2: usize,
     _val3: u32,
 ) -> KResult<usize> {
     let (futex_op, futex_flag) = parse_futexop(op)?;
@@ -824,7 +835,9 @@ async fn futex(
 }
 
 #[eonix_macros::define_syscall(SYS_SET_ROBUST_LIST)]
-async fn set_robust_list(head: User<RobustListHead>, len: usize) -> KResult<()> {
+async fn set_robust_list(
+    head: User<RobustListHead>, len: usize,
+) -> KResult<()> {
     if len != size_of::<RobustListHead>() {
         return Err(EINVAL);
     }
@@ -875,7 +888,9 @@ async fn sigreturn() -> KResult<SyscallNoReturn> {
 async fn arch_prctl(option: u32, addr: PtrT) -> KResult<u32> {
     match option {
         PR_SET_NAME => {
-            let name = UserPointer::<[u8; 16]>::new(User::with_addr(addr.addr()))?.read()?;
+            let name =
+                UserPointer::<[u8; 16]>::new(User::with_addr(addr.addr()))?
+                    .read()?;
             let len = name.iter().position(|&c| c == 0).unwrap_or(15);
             thread.set_name(name[..len].into());
             Ok(0)
@@ -883,8 +898,10 @@ async fn arch_prctl(option: u32, addr: PtrT) -> KResult<u32> {
         PR_GET_NAME => {
             let name = thread.get_name();
             let len = name.len().min(15);
-            let name: [u8; 16] = core::array::from_fn(|i| if i < len { name[i] } else { 0 });
-            UserPointerMut::<[u8; 16]>::new(UserMut::with_addr(addr.addr()))?.write(name)?;
+            let name: [u8; 16] =
+                core::array::from_fn(|i| if i < len { name[i] } else { 0 });
+            UserPointerMut::<[u8; 16]>::new(UserMut::with_addr(addr.addr()))?
+                .write(name)?;
             Ok(0)
         }
         _ => Err(EINVAL),

+ 21 - 9
src/kernel/task.rs

@@ -13,12 +13,14 @@ mod user_tls;
 pub use clone::{do_clone, CloneArgs, CloneFlags};
 use eonix_hal::symbol_addr;
 pub use futex::{
-    futex_exec, futex_exit, futex_wait, futex_wake, parse_futexop, FutexFlags, FutexOp,
-    RobustListHead,
+    futex_exec, futex_exit, futex_wait, futex_wake, parse_futexop, FutexFlags,
+    FutexOp, RobustListHead,
 };
 pub use kernel_stack::KernelStack;
 pub use loader::ProgramLoader;
-pub use process::{alloc_pid, Process, ProcessBuilder, WaitId, WaitObject, WaitType};
+pub use process::{
+    alloc_pid, Process, ProcessBuilder, WaitId, WaitObject, WaitType,
+};
 pub use process_group::ProcessGroup;
 pub use process_list::ProcessList;
 pub use session::Session;
@@ -101,12 +103,16 @@ where
     use eonix_runtime::task::Task;
     use thread::wait_for_wakeups;
 
-    use crate::kernel::interrupt::{default_fault_handler, default_irq_handler};
+    use crate::kernel::interrupt::{
+        default_fault_handler, default_irq_handler,
+    };
     use crate::kernel::timer::{should_reschedule, timer_interrupt};
 
     let stack = KernelStack::new();
 
-    fn execute<F>(mut future: Pin<&mut F>, output_ptr: NonNull<Option<F::Output>>) -> !
+    fn execute<F>(
+        mut future: Pin<&mut F>, output_ptr: NonNull<Option<F::Output>>,
+    ) -> !
     where
         F: Future,
     {
@@ -139,7 +145,9 @@ where
             match future.as_mut().poll(&mut cx) {
                 Poll::Ready(output) => break output,
                 Poll::Pending => {
-                    assert_preempt_enabled!("Blocking in stackful futures is not allowed.");
+                    assert_preempt_enabled!(
+                        "Blocking in stackful futures is not allowed."
+                    );
 
                     if Task::current().is_ready() {
                         continue;
@@ -203,7 +211,9 @@ where
 
         match trap_ctx.trap_type() {
             TrapType::Syscall { .. } => {}
-            TrapType::Fault(fault) => default_fault_handler(fault, &mut trap_ctx),
+            TrapType::Fault(fault) => {
+                default_fault_handler(fault, &mut trap_ctx)
+            }
             TrapType::Irq { callback } => callback(default_irq_handler),
             TrapType::Timer { callback } => {
                 callback(timer_interrupt);
@@ -220,10 +230,12 @@ where
                 }
 
                 #[cfg(target_arch = "riscv64")]
-                trap_ctx.set_program_counter(trap_ctx.get_program_counter() + 2);
+                trap_ctx
+                    .set_program_counter(trap_ctx.get_program_counter() + 2);
 
                 #[cfg(target_arch = "loongarch64")]
-                trap_ctx.set_program_counter(trap_ctx.get_program_counter() + 4);
+                trap_ctx
+                    .set_program_counter(trap_ctx.get_program_counter() + 4);
             }
         }
     }

+ 1 - 4
src/kernel/task/signal/signal_action.rs

@@ -141,10 +141,7 @@ impl SignalActionList {
 impl SignalAction {
     /// # Might Sleep
     pub(super) fn handle(
-        self,
-        signal: Signal,
-        old_mask: SigSet,
-        trap_ctx: &mut TrapContext,
+        self, signal: Signal, old_mask: SigSet, trap_ctx: &mut TrapContext,
         fpu_state: &mut FpuState,
     ) -> KResult<()> {
         let SignalAction::SimpleHandler {