Require UTF-8 for context name
This commit is contained in:
@@ -95,8 +95,7 @@ interrupt_stack!(syscall, |stack| {
|
||||
let context = contexts.current();
|
||||
if let Some(current) = context {
|
||||
let current = current.read();
|
||||
let name = current.name.read();
|
||||
println!("Warning: Context {} used deprecated `int 0x80` construct", core::str::from_utf8(&name).unwrap_or("(invalid utf8)"));
|
||||
println!("Warning: Context {} used deprecated `int 0x80` construct", *current.name.read());
|
||||
} else {
|
||||
println!("Warning: Unknown context used deprecated `int 0x80` construct");
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
use alloc::sync::Arc;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::vec::Vec;
|
||||
use alloc::collections::VecDeque;
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::cmp::Ordering;
|
||||
use core::mem;
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
collections::VecDeque,
|
||||
string::String,
|
||||
sync::Arc,
|
||||
vec::Vec,
|
||||
};
|
||||
use core::{
|
||||
alloc::{GlobalAlloc, Layout},
|
||||
cmp::Ordering,
|
||||
mem,
|
||||
};
|
||||
use spin::{Mutex, RwLock};
|
||||
|
||||
use crate::arch::{interrupt::InterruptStack, paging::PAGE_SIZE};
|
||||
@@ -112,7 +117,7 @@ pub struct ContextSnapshot {
|
||||
pub syscall: Option<(usize, usize, usize, usize, usize, usize)>,
|
||||
// Clone fields
|
||||
//TODO: is there a faster way than allocation?
|
||||
pub name: Box<[u8]>,
|
||||
pub name: Box<str>,
|
||||
pub files: Vec<Option<FileDescription>>,
|
||||
// pub cwd: Box<[u8]>,
|
||||
}
|
||||
@@ -230,7 +235,7 @@ pub struct Context {
|
||||
/// User grants
|
||||
pub grants: Arc<Mutex<UserGrants>>,
|
||||
/// The name of the context
|
||||
pub name: Arc<RwLock<Box<[u8]>>>,
|
||||
pub name: Arc<RwLock<Box<str>>>,
|
||||
/// The current working directory
|
||||
pub cwd: Arc<Mutex<Vec<u8>>>,
|
||||
/// The open files in the scheme
|
||||
@@ -287,7 +292,7 @@ impl Context {
|
||||
sigstack: None,
|
||||
tls: None,
|
||||
grants: Arc::new(Mutex::new(UserGrants::default())),
|
||||
name: Arc::new(RwLock::new(Vec::new().into_boxed_slice())),
|
||||
name: Arc::new(RwLock::new(String::new().into_boxed_str())),
|
||||
cwd: Arc::new(Mutex::new(Vec::new())),
|
||||
files: Arc::new(Mutex::new(Vec::new())),
|
||||
actions: Arc::new(Mutex::new(vec![(
|
||||
|
||||
@@ -13,7 +13,7 @@ unsafe fn update(context: &mut Context, cpu_id: usize) {
|
||||
// Take ownership if not already owned
|
||||
if context.cpu_id == None {
|
||||
context.cpu_id = Some(cpu_id);
|
||||
// println!("{}: take {} {}", cpu_id, context.id, ::core::str::from_utf8_unchecked(&context.name.read()));
|
||||
// println!("{}: take {} {}", cpu_id, context.id, *context.name.read());
|
||||
}
|
||||
|
||||
// Restore from signal, must only be done from another context to avoid overwriting the stack!
|
||||
|
||||
@@ -279,7 +279,7 @@ pub extern fn ksignal(signal: usize) {
|
||||
let contexts = context::contexts();
|
||||
if let Some(context_lock) = contexts.current() {
|
||||
let context = context_lock.read();
|
||||
info!("NAME {}", unsafe { ::core::str::from_utf8_unchecked(&context.name.read()) });
|
||||
info!("NAME {}", *context.name.read());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,7 +236,9 @@ impl Scheme for ProcScheme {
|
||||
data = match operation {
|
||||
Operation::Memory => OperationData::Memory(MemData::default()),
|
||||
Operation::Trace => OperationData::Trace(TraceData::default()),
|
||||
Operation::Static(_) => OperationData::Static(StaticData::new(target.name.read().clone())),
|
||||
Operation::Static(_) => OperationData::Static(StaticData::new(
|
||||
target.name.read().clone().into()
|
||||
)),
|
||||
_ => OperationData::Other,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use core::fmt::Write;
|
||||
use core::str;
|
||||
|
||||
use crate::context;
|
||||
use crate::syscall::error::Result;
|
||||
@@ -21,7 +20,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
|
||||
for row in rows.iter() {
|
||||
let id: usize = row.0.into();
|
||||
let name = str::from_utf8(&row.1).unwrap_or(".");
|
||||
let name = &row.1;
|
||||
|
||||
let _ = writeln!(string, "{}: {}", id, name);
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use core::str;
|
||||
|
||||
use crate::context;
|
||||
use crate::syscall::error::Result;
|
||||
@@ -107,9 +106,6 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
format!("{} B", memory)
|
||||
};
|
||||
|
||||
let name_bytes = context.name.read();
|
||||
let name = str::from_utf8(&name_bytes).unwrap_or("");
|
||||
|
||||
string.push_str(&format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<8}{}\n",
|
||||
context.id.into(),
|
||||
context.pgid.into(),
|
||||
@@ -124,7 +120,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
cpu_string,
|
||||
ticks_string,
|
||||
memory_string,
|
||||
name));
|
||||
*context.name.read()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use alloc::vec::Vec;
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
vec::Vec,
|
||||
};
|
||||
|
||||
use crate::context;
|
||||
use crate::syscall::error::{Error, ESRCH, Result};
|
||||
@@ -9,7 +12,8 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
let name = context.name.read();
|
||||
name.clone().into_vec()
|
||||
let name_bytes: Box<[u8]> = name.clone().into();
|
||||
name_bytes.into_vec()
|
||||
};
|
||||
Ok(name)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
|
||||
for row in rows.iter() {
|
||||
let id: usize = row.0.into();
|
||||
let name = str::from_utf8(&row.1).unwrap_or(".");
|
||||
let name = &row.1;
|
||||
let _ = writeln!(string, "{}: {}", id, name);
|
||||
|
||||
for (fd, f) in row.2.iter().enumerate() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use core::fmt::Write;
|
||||
use core::str;
|
||||
|
||||
use crate::context;
|
||||
use crate::syscall;
|
||||
@@ -22,7 +21,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
|
||||
for row in rows.iter() {
|
||||
let id: usize = row.0.into();
|
||||
let name = str::from_utf8(&row.1).unwrap_or(".");
|
||||
let name = &row.1;
|
||||
|
||||
let _ = writeln!(string, "{}: {}", id, name);
|
||||
|
||||
|
||||
@@ -82,8 +82,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, bp: u
|
||||
let contexts = crate::context::contexts();
|
||||
let current = contexts.current().unwrap();
|
||||
let current = current.read();
|
||||
let name = current.name.read();
|
||||
println!("{:?} using deprecated fmap(...) call", core::str::from_utf8(&name));
|
||||
println!("{:?} using deprecated fmap(...) call", *current.name.read());
|
||||
}
|
||||
file_op(a, fd, c, d)
|
||||
},
|
||||
@@ -92,8 +91,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, bp: u
|
||||
let contexts = crate::context::contexts();
|
||||
let current = contexts.current().unwrap();
|
||||
let current = current.read();
|
||||
let name = current.name.read();
|
||||
println!("{:?} using deprecated funmap(...) call", core::str::from_utf8(&name));
|
||||
println!("{:?} using deprecated funmap(...) call", *current.name.read());
|
||||
}
|
||||
funmap_old(b)
|
||||
},
|
||||
@@ -208,8 +206,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, bp: u
|
||||
let contexts = crate::context::contexts();
|
||||
if let Some(context_lock) = contexts.current() {
|
||||
let context = context_lock.read();
|
||||
let name_raw = context.name.read();
|
||||
let name = unsafe { core::str::from_utf8_unchecked(&name_raw) };
|
||||
let name = context.name.read();
|
||||
if name.contains("redoxfs") {
|
||||
if a == SYS_CLOCK_GETTIME || a == SYS_YIELD {
|
||||
false
|
||||
@@ -230,7 +227,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, bp: u
|
||||
let contexts = crate::context::contexts();
|
||||
if let Some(context_lock) = contexts.current() {
|
||||
let context = context_lock.read();
|
||||
print!("{} ({}): ", unsafe { core::str::from_utf8_unchecked(&context.name.read()) }, context.id.into());
|
||||
print!("{} ({}): ", *context.name.read(), context.id.into());
|
||||
}
|
||||
|
||||
println!("{}", debug::format_call(a, b, c, d, e, f));
|
||||
@@ -265,7 +262,7 @@ pub fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize, bp: u
|
||||
let contexts = crate::context::contexts();
|
||||
if let Some(context_lock) = contexts.current() {
|
||||
let context = context_lock.read();
|
||||
print!("{} ({}): ", unsafe { core::str::from_utf8_unchecked(&context.name.read()) }, context.id.into());
|
||||
print!("{} ({}): ", *context.name.read(), context.id.into());
|
||||
}
|
||||
|
||||
print!("{} = ", debug::format_call(a, b, c, d, e, f));
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use alloc::boxed::Box;
|
||||
use alloc::collections::BTreeSet;
|
||||
use alloc::sync::Arc;
|
||||
use alloc::vec::Vec;
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
collections::BTreeSet,
|
||||
string::String,
|
||||
sync::Arc,
|
||||
vec::Vec,
|
||||
};
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::ops::DerefMut;
|
||||
use core::{intrinsics, mem};
|
||||
@@ -608,7 +611,7 @@ fn empty(context: &mut context::Context, reaping: bool) {
|
||||
let grants = mem::replace(&mut *grants, UserGrants::default());
|
||||
for grant in grants.inner.into_iter() {
|
||||
if reaping {
|
||||
println!("{}: {}: Grant should not exist: {:?}", context.id.into(), unsafe { ::core::str::from_utf8_unchecked(&context.name.read()) }, grant);
|
||||
println!("{}: {}: Grant should not exist: {:?}", context.id.into(), *context.name.read(), grant);
|
||||
|
||||
let mut new_table = unsafe { InactivePageTable::from_address(context.arch.get_page_utable()) };
|
||||
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(crate::USER_TMP_GRANT_OFFSET)));
|
||||
@@ -632,7 +635,7 @@ impl Drop for ExecFile {
|
||||
fn fexec_noreturn(
|
||||
setuid: Option<u32>,
|
||||
setgid: Option<u32>,
|
||||
name: Box<[u8]>,
|
||||
name: Box<str>,
|
||||
data: Box<[u8]>,
|
||||
args: Box<[Box<[u8]>]>,
|
||||
vars: Box<[Box<[u8]>]>,
|
||||
@@ -893,7 +896,7 @@ fn fexec_noreturn(
|
||||
unsafe { usermode(entry, sp, 0, singlestep) }
|
||||
}
|
||||
|
||||
pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>]>, name_override_opt: Option<Box<[u8]>>, auxv: Option<Vec<usize>>) -> Result<usize> {
|
||||
pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>]>, name_override_opt: Option<Box<str>>, auxv: Option<Vec<usize>>) -> Result<usize> {
|
||||
let (uid, gid) = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
@@ -902,7 +905,7 @@ pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>
|
||||
};
|
||||
|
||||
let mut stat: Stat;
|
||||
let mut name: Vec<u8>;
|
||||
let name: String;
|
||||
let mut data: Vec<u8>;
|
||||
{
|
||||
let file = ExecFile(fd);
|
||||
@@ -926,11 +929,18 @@ pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>
|
||||
}
|
||||
|
||||
if let Some(name_override) = name_override_opt {
|
||||
name = Vec::from(name_override);
|
||||
name = String::from(name_override);
|
||||
} else {
|
||||
name = vec![0; 4096];
|
||||
let len = syscall::file_op_mut_slice(syscall::number::SYS_FPATH, file.0, &mut name)?;
|
||||
name.truncate(len);
|
||||
let mut name_bytes = vec![0; 4096];
|
||||
let len = syscall::file_op_mut_slice(syscall::number::SYS_FPATH, file.0, &mut name_bytes)?;
|
||||
name_bytes.truncate(len);
|
||||
name = match String::from_utf8(name_bytes) {
|
||||
Ok(ok) => ok,
|
||||
Err(_err) => {
|
||||
//TODO: print error?
|
||||
return Err(Error::new(EINVAL));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//TODO: Only read elf header, not entire file. Then read required segments
|
||||
@@ -974,7 +984,7 @@ pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>
|
||||
println!(
|
||||
"{}: {}: fexec failed to execute {}: {}",
|
||||
context.id.into(),
|
||||
unsafe { ::core::str::from_utf8_unchecked(&context.name.read()) },
|
||||
*context.name.read(),
|
||||
fd.into(),
|
||||
err
|
||||
);
|
||||
@@ -1026,8 +1036,8 @@ pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>
|
||||
|
||||
let mut args_vec = Vec::from(args);
|
||||
//TODO: pass file handle in auxv
|
||||
let name_override = name.into_boxed_slice();
|
||||
args_vec[0] = name_override.clone();
|
||||
let name_override = name.into_boxed_str();
|
||||
args_vec[0] = name_override.clone().into();
|
||||
|
||||
// Drop variables, since fexec_kernel probably won't return
|
||||
drop(elf);
|
||||
@@ -1060,7 +1070,7 @@ pub fn fexec_kernel(fd: FileHandle, args: Box<[Box<[u8]>]>, vars: Box<[Box<[u8]>
|
||||
// This is the point of no return, quite literaly. Any checks for validity need
|
||||
// to be done before, and appropriate errors returned. Otherwise, we have nothing
|
||||
// to return to.
|
||||
fexec_noreturn(setuid, setgid, name.into_boxed_slice(), data.into_boxed_slice(), args, vars, auxv.into_boxed_slice());
|
||||
fexec_noreturn(setuid, setgid, name.into_boxed_str(), data.into_boxed_slice(), args, vars, auxv.into_boxed_slice());
|
||||
}
|
||||
|
||||
pub fn fexec(fd: FileHandle, arg_ptrs: &[[usize; 2]], var_ptrs: &[[usize; 2]]) -> Result<usize> {
|
||||
|
||||
Reference in New Issue
Block a user