Nothing to see here, move along
at main 54 lines 1.7 kB view raw
1use crate::error::KernelError; 2use crate::proc::context::CpuContext; 3use crate::syscall::{SyscallResult, try_syscall}; 4 5pub fn sys_module_info(ctx: &mut CpuContext) { 6 let module_index = ctx.rdi; 7 let user_buf = ctx.rsi; 8 let buf_len = ctx.rdx; 9 10 let modules = match crate::arch::boot::modules() { 11 Some(m) => m, 12 None => { 13 ctx.rax = SyscallResult::error(KernelError::NotFound).raw(); 14 return; 15 } 16 }; 17 18 if module_index == u64::MAX { 19 ctx.rax = SyscallResult::success(modules.len() as u64).raw(); 20 return; 21 } 22 23 if module_index >= modules.len() as u64 { 24 ctx.rax = SyscallResult::error(KernelError::InvalidParameter).raw(); 25 return; 26 } 27 let idx = module_index as usize; 28 29 let path = modules[idx].path(); 30 let path_bytes = path.to_bytes(); 31 let copy_len = path_bytes.len().min(buf_len as usize); 32 33 if copy_len > 0 && user_buf != 0 { 34 let irq = match crate::sync::InterruptsDisabledToken::new_checked() { 35 Some(tok) => tok, 36 None => { 37 x86_64::instructions::interrupts::disable(); 38 match crate::sync::InterruptsDisabledToken::new_checked() { 39 Some(tok) => tok, 40 None => { 41 ctx.rax = SyscallResult::error(KernelError::BadState).raw(); 42 return; 43 } 44 } 45 } 46 }; 47 try_syscall!( 48 ctx, 49 crate::syscall::copy_to_user(user_buf, &path_bytes[..copy_len], copy_len, &irq) 50 ); 51 } 52 53 ctx.rax = SyscallResult::success(path_bytes.len() as u64).raw(); 54}