|
|
@ -10,7 +10,7 @@ use rcore_memory::VMError;
|
|
|
|
use crate::arch::cpu;
|
|
|
|
use crate::arch::cpu;
|
|
|
|
use crate::arch::interrupt::TrapFrame;
|
|
|
|
use crate::arch::interrupt::TrapFrame;
|
|
|
|
use crate::arch::syscall::*;
|
|
|
|
use crate::arch::syscall::*;
|
|
|
|
use crate::memory::{copy_from_user_u8, copy_from_user_usize, MemorySet};
|
|
|
|
use crate::memory::{copy_from_user, MemorySet};
|
|
|
|
use crate::process::*;
|
|
|
|
use crate::process::*;
|
|
|
|
use crate::sync::{Condvar, MutexGuard, SpinNoIrq};
|
|
|
|
use crate::sync::{Condvar, MutexGuard, SpinNoIrq};
|
|
|
|
use crate::thread;
|
|
|
|
use crate::thread;
|
|
|
@ -561,33 +561,25 @@ pub fn check_and_clone_cstr(user: *const u8) -> Result<String, SysError> {
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
for i in 0.. {
|
|
|
|
for i in 0.. {
|
|
|
|
let addr = unsafe { user.add(i) };
|
|
|
|
let addr = unsafe { user.add(i) };
|
|
|
|
if let Some(data) = copy_from_user_u8(addr) {
|
|
|
|
let data = copy_from_user(addr).ok_or(SysError::EFAULT)?;
|
|
|
|
if data > 0 {
|
|
|
|
if data == 0 {
|
|
|
|
buffer.push(data);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Err(SysError::EFAULT);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.push(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return String::from_utf8(buffer).map_err(|_| SysError::EFAULT);
|
|
|
|
String::from_utf8(buffer).map_err(|_| SysError::EFAULT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn check_and_clone_cstr_array(user: *const *const u8) -> Result<Vec<String>, SysError> {
|
|
|
|
pub fn check_and_clone_cstr_array(user: *const *const u8) -> Result<Vec<String>, SysError> {
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
let mut buffer = Vec::new();
|
|
|
|
for i in 0.. {
|
|
|
|
for i in 0.. {
|
|
|
|
let addr = unsafe { user.add(i) };
|
|
|
|
let addr = unsafe { user.add(i) };
|
|
|
|
if let Some(str_addr) = copy_from_user_usize(addr as *const usize) {
|
|
|
|
let str_ptr = copy_from_user(addr).ok_or(SysError::EFAULT)?;
|
|
|
|
if str_addr > 0 {
|
|
|
|
if str_ptr.is_null() {
|
|
|
|
let string = check_and_clone_cstr(str_addr as *const u8)?;
|
|
|
|
break;
|
|
|
|
buffer.push(string);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Err(SysError::EFAULT);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let string = check_and_clone_cstr(str_ptr)?;
|
|
|
|
|
|
|
|
buffer.push(string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Ok(buffer);
|
|
|
|
Ok(buffer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|