From 1974cc585323196bbf44f838d165402d6ecd126d Mon Sep 17 00:00:00 2001 From: chyyuu Date: Fri, 26 Apr 2019 18:57:54 +0800 Subject: [PATCH] add syscall: sys_getrandom for python3, etc. --- kernel/src/syscall/misc.rs | 15 +++++++++++++++ kernel/src/syscall/mod.rs | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) 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")]