diff --git a/kernel/src/memory.rs b/kernel/src/memory.rs index f98f1ad..54c2cff 100644 --- a/kernel/src/memory.rs +++ b/kernel/src/memory.rs @@ -106,7 +106,7 @@ impl Drop for KernelStack { /// Handle page fault at `addr`. /// Return true to continue, false to halt. pub fn handle_page_fault(addr: usize) -> bool { - debug!("page fault @ {:#x}", addr); + // debug!("page fault @ {:#x}", addr); // This is safe as long as page fault never happens in page fault handler unsafe { process_unsafe().vm.handle_page_fault(addr) } diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index 7bd1a77..a24f34a 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -59,8 +59,8 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { SYS_MPROTECT => sys_mprotect(args[0], args[1], args[2]), SYS_MUNMAP => sys_munmap(args[0], args[1]), SYS_BRK => { - warn!("sys_brk is unimplemented"); - Ok(0) + warn!("sys_brk is unimplemented, return -1"); + Err(SysError::ENOMEM) } SYS_RT_SIGACTION => { warn!("sys_sigaction is unimplemented"); @@ -174,6 +174,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { // SYS_GETRLIMIT => sys_getrlimit(), SYS_GETRUSAGE => sys_getrusage(args[0], args[1] as *mut RUsage), SYS_SYSINFO => sys_sysinfo(args[0] as *mut SysInfo), + SYS_TIMES => sys_times(args[0] as *mut Tms), SYS_GETUID => { warn!("sys_getuid is unimplemented"); Ok(0) diff --git a/kernel/src/syscall/time.rs b/kernel/src/syscall/time.rs index dd5cfcd..ff25cb3 100644 --- a/kernel/src/syscall/time.rs +++ b/kernel/src/syscall/time.rs @@ -146,3 +146,33 @@ pub fn sys_getrusage(who: usize, rusage: *mut RUsage) -> SysResult { unsafe { *rusage = new_rusage }; Ok(0) } + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Tms { + tms_utime: u64, /* user time */ + tms_stime: u64, /* system time */ + tms_cutime: u64, /* user time of children */ + tms_cstime: u64, /* system time of children */ +} + + +pub fn sys_times(buf:*mut Tms)-> SysResult { + info!("times: buf: {:?}", buf); + let proc = process(); + proc.vm.check_write_ptr(buf)?; + + let tick_base = *TICK_BASE; + let tick = unsafe { crate::trap::TICK as u64 }; + + let new_buf = Tms { + tms_utime: 0, + tms_stime: 0, + tms_cutime: 0, + tms_cstime: 0, + }; + + unsafe { *buf = new_buf }; + Ok(tick as usize) +} \ No newline at end of file