Fetch buffer in user space as a Vec.

This commit is contained in:
Yifan Wu 2020-12-07 18:07:19 +08:00
parent 064f1cb5cb
commit f54573ae15
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
},
_ => {

View file

@ -10,7 +10,7 @@ use fs::*;
use process::*;
pub fn syscall(syscall_id: usize, args: [usize; 3]) -> isize {
println!("into syscall!");
//println!("into syscall!");
match syscall_id {
SYSCALL_WRITE => sys_write(args[0], args[1] as *const u8, args[2]),
SYSCALL_EXIT => sys_exit(args[0] as i32),