1*ab5c8ca4Slogin use crate::{ 2*ab5c8ca4Slogin include::bindings::bindings::mm_stat_t, 3*ab5c8ca4Slogin syscall::{Syscall, SystemError}, 4*ab5c8ca4Slogin }; 5*ab5c8ca4Slogin 6*ab5c8ca4Slogin extern "C" { 7*ab5c8ca4Slogin fn sys_do_brk(new_addr: usize) -> usize; 8*ab5c8ca4Slogin fn sys_do_sbrk(incr: isize) -> usize; 9*ab5c8ca4Slogin fn sys_do_mstat(dst: *mut mm_stat_t, from_user: bool) -> usize; 10*ab5c8ca4Slogin } 11*ab5c8ca4Slogin impl Syscall { 12*ab5c8ca4Slogin pub fn brk(new_addr: usize) -> Result<usize, SystemError> { 13*ab5c8ca4Slogin let ret = unsafe { sys_do_brk(new_addr) }; 14*ab5c8ca4Slogin if (ret as isize) < 0 { 15*ab5c8ca4Slogin return Err( 16*ab5c8ca4Slogin SystemError::from_posix_errno(-(ret as isize) as i32).expect("brk: Invalid errno") 17*ab5c8ca4Slogin ); 18*ab5c8ca4Slogin } 19*ab5c8ca4Slogin return Ok(ret); 20*ab5c8ca4Slogin } 21*ab5c8ca4Slogin 22*ab5c8ca4Slogin pub fn sbrk(incr: isize) -> Result<usize, SystemError> { 23*ab5c8ca4Slogin let ret = unsafe { sys_do_sbrk(incr) }; 24*ab5c8ca4Slogin if (ret as isize) < 0 { 25*ab5c8ca4Slogin return Err( 26*ab5c8ca4Slogin SystemError::from_posix_errno(-(ret as isize) as i32).expect("sbrk: Invalid errno") 27*ab5c8ca4Slogin ); 28*ab5c8ca4Slogin } 29*ab5c8ca4Slogin return Ok(ret); 30*ab5c8ca4Slogin } 31*ab5c8ca4Slogin 32*ab5c8ca4Slogin /// 获取内存统计信息 33*ab5c8ca4Slogin /// 34*ab5c8ca4Slogin /// TODO: 该函数不是符合POSIX标准的,在将来需要删除! 35*ab5c8ca4Slogin pub fn mstat(dst: *mut mm_stat_t, from_user: bool) -> Result<usize, SystemError> { 36*ab5c8ca4Slogin let ret = unsafe { sys_do_mstat(dst, from_user) }; 37*ab5c8ca4Slogin if (ret as isize) < 0 { 38*ab5c8ca4Slogin return Err(SystemError::from_posix_errno(-(ret as isize) as i32) 39*ab5c8ca4Slogin .expect("mstat: Invalid errno")); 40*ab5c8ca4Slogin } 41*ab5c8ca4Slogin return Ok(ret); 42*ab5c8ca4Slogin } 43*ab5c8ca4Slogin } 44