Fetch buffer in user space as a Vec.

This commit is contained in:
Yifan Wu 2020-12-07 18:07:19 +08:00
parent 9366099b28
commit 1008d92c35
6 changed files with 49 additions and 15 deletions

View file

@ -1,11 +1,16 @@
use crate::mm::translated_byte_buffer;
use crate::task::current_user_token;
const FD_STDOUT: usize = 1;
pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize {
//println!("into sys_write!");
match fd {
FD_STDOUT => {
let slice = unsafe { core::slice::from_raw_parts(buf, len) };
let str = core::str::from_utf8(slice).unwrap();
print!("{}", str);
let buffers = translated_byte_buffer(current_user_token(), buf, len);
for buffer in buffers {
print!("{}", core::str::from_utf8(buffer).unwrap());
}
len as isize
},
_ => {