diff --git a/kernel/src/syscall/misc.rs b/kernel/src/syscall/misc.rs index ac3ff39..a5367e1 100644 --- a/kernel/src/syscall/misc.rs +++ b/kernel/src/syscall/misc.rs @@ -201,3 +201,18 @@ pub struct RLimit { cur: u64, // soft limit max: u64, // hard limit } + +pub fn sys_getrandom( buf: *mut u8, len: usize, flag: u32) -> SysResult { + + //info!("getrandom: buf: {:?}, len: {:?}, falg {:?}", buf, len,flag); + let mut proc = process(); + proc.vm.check_write_array(buf, len)?; + let slice = unsafe { slice::from_raw_parts_mut(buf, len) }; + let mut i=0; + for elm in slice { + unsafe{ *elm=i+ crate::trap::TICK as u8;} + i+=1; + } + + Ok(len) +} \ No newline at end of file diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index ba267b7..4a5f6c1 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -230,7 +230,9 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { // custom SYS_MAP_PCI_DEVICE => sys_map_pci_device(args[0], args[1]), SYS_GET_PADDR => sys_get_paddr(args[0] as *const u64, args[1] as *mut u64, args[2]), - + //SYS_GETRANDOM => unimplemented("getrandom", Err(SysError::EINVAL)), + SYS_GETRANDOM =>sys_getrandom( args[0] as *mut u8, args[1] as usize, args[2] as u32), + SYS_TKILL => unimplemented("tkill", Ok(0)), _ => { let ret = match () { #[cfg(target_arch = "x86_64")]