Make context name a RwLock
This commit is contained in:
@@ -95,7 +95,7 @@ interrupt_stack!(syscall, |stack| {
|
||||
let context = contexts.current();
|
||||
if let Some(current) = context {
|
||||
let current = current.read();
|
||||
let name = current.name.lock();
|
||||
let name = current.name.read();
|
||||
println!("Warning: Context {} used deprecated `int 0x80` construct", core::str::from_utf8(&name).unwrap_or("(invalid utf8)"));
|
||||
} else {
|
||||
println!("Warning: Unknown context used deprecated `int 0x80` construct");
|
||||
|
||||
@@ -5,7 +5,7 @@ use alloc::collections::VecDeque;
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::cmp::Ordering;
|
||||
use core::mem;
|
||||
use spin::Mutex;
|
||||
use spin::{Mutex, RwLock};
|
||||
|
||||
use crate::arch::{interrupt::InterruptStack, paging::PAGE_SIZE};
|
||||
use crate::common::unique::Unique;
|
||||
@@ -120,7 +120,7 @@ pub struct ContextSnapshot {
|
||||
impl ContextSnapshot {
|
||||
//TODO: Should this accept &mut Context to ensure name/files will not change?
|
||||
pub fn new(context: &Context) -> Self {
|
||||
let name = context.name.lock().clone();
|
||||
let name = context.name.read().clone();
|
||||
let mut files = Vec::new();
|
||||
for descriptor_opt in context.files.lock().iter() {
|
||||
let description = if let Some(descriptor) = descriptor_opt {
|
||||
@@ -230,7 +230,7 @@ pub struct Context {
|
||||
/// User grants
|
||||
pub grants: Arc<Mutex<UserGrants>>,
|
||||
/// The name of the context
|
||||
pub name: Arc<Mutex<Box<[u8]>>>,
|
||||
pub name: Arc<RwLock<Box<[u8]>>>,
|
||||
/// The current working directory
|
||||
pub cwd: Arc<Mutex<Vec<u8>>>,
|
||||
/// The open files in the scheme
|
||||
@@ -287,7 +287,7 @@ impl Context {
|
||||
sigstack: None,
|
||||
tls: None,
|
||||
grants: Arc::new(Mutex::new(UserGrants::default())),
|
||||
name: Arc::new(Mutex::new(Vec::new().into_boxed_slice())),
|
||||
name: Arc::new(RwLock::new(Vec::new().into_boxed_slice())),
|
||||
cwd: Arc::new(Mutex::new(Vec::new())),
|
||||
files: Arc::new(Mutex::new(Vec::new())),
|
||||
actions: Arc::new(Mutex::new(vec![(
|
||||
|
||||
@@ -15,7 +15,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.lock()));
|
||||
// println!("{}: take {} {}", cpu_id, context.id, ::core::str::from_utf8_unchecked(&context.name.read()));
|
||||
}
|
||||
|
||||
// Restore from signal, must only be done from another context to avoid overwriting the stack!
|
||||
|
||||
@@ -276,7 +276,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.lock()) });
|
||||
info!("NAME {}", unsafe { ::core::str::from_utf8_unchecked(&context.name.read()) });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ 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.lock().clone())),
|
||||
Operation::Static(_) => OperationData::Static(StaticData::new(target.name.read().clone())),
|
||||
_ => OperationData::Other,
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
let contexts = context::contexts();
|
||||
for (id, context_lock) in contexts.iter() {
|
||||
let context = context_lock.read();
|
||||
rows.push((*id, context.name.lock().clone(), context.status_reason));
|
||||
rows.push((*id, context.name.read().clone(), context.status_reason));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
format!("{} B", memory)
|
||||
};
|
||||
|
||||
let name_bytes = context.name.lock();
|
||||
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",
|
||||
|
||||
@@ -8,7 +8,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
let name = context.name.lock();
|
||||
let name = context.name.read();
|
||||
name.clone().into_vec()
|
||||
};
|
||||
Ok(name)
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
let contexts = context::contexts();
|
||||
for (id, context_lock) in contexts.iter() {
|
||||
let context = context_lock.read();
|
||||
rows.push((*id, context.name.lock().clone(), context.files.lock().clone()));
|
||||
rows.push((*id, context.name.read().clone(), context.files.lock().clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
let contexts = context::contexts();
|
||||
for (id, context_lock) in contexts.iter() {
|
||||
let context = context_lock.read();
|
||||
rows.push((*id, context.name.lock().clone(), context.syscall.clone()));
|
||||
rows.push((*id, context.name.read().clone(), context.syscall.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +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.lock();
|
||||
let name = current.name.read();
|
||||
println!("{:?} using deprecated fmap(...) call", core::str::from_utf8(&name));
|
||||
}
|
||||
file_op(a, fd, c, d)
|
||||
@@ -92,7 +92,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.lock();
|
||||
let name = current.name.read();
|
||||
println!("{:?} using deprecated funmap(...) call", core::str::from_utf8(&name));
|
||||
}
|
||||
funmap_old(b)
|
||||
@@ -197,7 +197,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.lock();
|
||||
let name_raw = context.name.read();
|
||||
let name = unsafe { core::str::from_utf8_unchecked(&name_raw) };
|
||||
if name.contains("redoxfs") {
|
||||
if a == SYS_CLOCK_GETTIME || a == SYS_YIELD {
|
||||
@@ -219,7 +219,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.lock()) }, context.id.into());
|
||||
print!("{} ({}): ", unsafe { core::str::from_utf8_unchecked(&context.name.read()) }, context.id.into());
|
||||
}
|
||||
|
||||
println!("{}", debug::format_call(a, b, c, d, e, f));
|
||||
@@ -254,7 +254,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.lock()) }, context.id.into());
|
||||
print!("{} ({}): ", unsafe { core::str::from_utf8_unchecked(&context.name.read()) }, context.id.into());
|
||||
}
|
||||
|
||||
print!("{} = ", debug::format_call(a, b, c, d, e, f));
|
||||
|
||||
@@ -5,7 +5,7 @@ use alloc::vec::Vec;
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::ops::DerefMut;
|
||||
use core::{intrinsics, mem};
|
||||
use spin::Mutex;
|
||||
use spin::{RwLock, Mutex};
|
||||
|
||||
use crate::context::file::FileDescriptor;
|
||||
use crate::context::{ContextId, WaitpidKey};
|
||||
@@ -231,7 +231,7 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> {
|
||||
if flags.contains(CLONE_VM) {
|
||||
name = Arc::clone(&context.name);
|
||||
} else {
|
||||
name = Arc::new(Mutex::new(context.name.lock().clone()));
|
||||
name = Arc::new(RwLock::new(context.name.read().clone()));
|
||||
}
|
||||
|
||||
if flags.contains(CLONE_FS) {
|
||||
@@ -560,7 +560,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.lock()) }, grant);
|
||||
println!("{}: {}: Grant should not exist: {:?}", context.id.into(), unsafe { ::core::str::from_utf8_unchecked(&context.name.read()) }, grant);
|
||||
|
||||
let mut new_table = unsafe { InactivePageTable::from_address(context.arch.get_page_table()) };
|
||||
let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(crate::USER_TMP_GRANT_OFFSET)));
|
||||
@@ -604,7 +604,7 @@ fn fexec_noreturn(
|
||||
ptrace::regs_for(&context).map(|s| s.is_singlestep()).unwrap_or(false)
|
||||
};
|
||||
|
||||
context.name = Arc::new(Mutex::new(name));
|
||||
context.name = Arc::new(RwLock::new(name));
|
||||
|
||||
empty(&mut context, false);
|
||||
|
||||
@@ -926,7 +926,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.lock()) },
|
||||
unsafe { ::core::str::from_utf8_unchecked(&context.name.read()) },
|
||||
fd.into(),
|
||||
err
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user