use crate::error::KernelError; use crate::proc::context::CpuContext; use crate::syscall::{SyscallResult, try_syscall}; pub fn sys_module_info(ctx: &mut CpuContext) { let module_index = ctx.rdi; let user_buf = ctx.rsi; let buf_len = ctx.rdx; let modules = match crate::arch::boot::modules() { Some(m) => m, None => { ctx.rax = SyscallResult::error(KernelError::NotFound).raw(); return; } }; if module_index == u64::MAX { ctx.rax = SyscallResult::success(modules.len() as u64).raw(); return; } if module_index >= modules.len() as u64 { ctx.rax = SyscallResult::error(KernelError::InvalidParameter).raw(); return; } let idx = module_index as usize; let path = modules[idx].path(); let path_bytes = path.to_bytes(); let copy_len = path_bytes.len().min(buf_len as usize); if copy_len > 0 && user_buf != 0 { let irq = match crate::sync::InterruptsDisabledToken::new_checked() { Some(tok) => tok, None => { x86_64::instructions::interrupts::disable(); match crate::sync::InterruptsDisabledToken::new_checked() { Some(tok) => tok, None => { ctx.rax = SyscallResult::error(KernelError::BadState).raw(); return; } } } }; try_syscall!( ctx, crate::syscall::copy_to_user(user_buf, &path_bytes[..copy_len], copy_len, &irq) ); } ctx.rax = SyscallResult::success(path_bytes.len() as u64).raw(); }