Remove one level of indirection for Context::name.
This commit is contained in:
@@ -142,7 +142,7 @@ interrupt_stack!(syscall, |stack| {
|
||||
let context = contexts.current();
|
||||
if let Some(current) = context {
|
||||
let current = current.read();
|
||||
println!("Warning: Context {} used deprecated `int 0x80` construct", *current.name.read());
|
||||
println!("Warning: Context {} used deprecated `int 0x80` construct", current.name);
|
||||
} else {
|
||||
println!("Warning: Unknown context used deprecated `int 0x80` construct");
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
collections::VecDeque,
|
||||
string::{String},
|
||||
sync::Arc,
|
||||
vec::Vec,
|
||||
vec::Vec, borrow::Cow,
|
||||
};
|
||||
use core::{
|
||||
alloc::GlobalAlloc,
|
||||
@@ -128,7 +127,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.read().clone();
|
||||
let name = context.name.clone().into_owned().into_boxed_str();
|
||||
let mut files = Vec::new();
|
||||
for descriptor_opt in context.files.read().iter() {
|
||||
let description = if let Some(descriptor) = descriptor_opt {
|
||||
@@ -240,7 +239,8 @@ pub struct Context {
|
||||
/// mappings are universal and independent on address spaces or contexts.
|
||||
pub addr_space: Option<Arc<RwLock<AddrSpace>>>,
|
||||
/// The name of the context
|
||||
pub name: Arc<RwLock<Box<str>>>,
|
||||
// TODO: fixed size ArrayString?
|
||||
pub name: Cow<'static, str>,
|
||||
/// The open files in the scheme
|
||||
pub files: Arc<RwLock<Vec<Option<FileDescriptor>>>>,
|
||||
/// Signal actions
|
||||
@@ -372,7 +372,7 @@ impl Context {
|
||||
ksig: None,
|
||||
ksig_restore: false,
|
||||
addr_space: None,
|
||||
name: Arc::new(RwLock::new(String::new().into_boxed_str())),
|
||||
name: Cow::Borrowed(""),
|
||||
files: Arc::new(RwLock::new(Vec::new())),
|
||||
actions: Self::empty_actions(),
|
||||
regs: None,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//! For resources on contexts, please consult [wikipedia](https://en.wikipedia.org/wiki/Context_switch) and [osdev](https://wiki.osdev.org/Context_Switching)
|
||||
use core::sync::atomic::Ordering;
|
||||
|
||||
use alloc::borrow::Cow;
|
||||
use alloc::sync::Arc;
|
||||
|
||||
use spin::{RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
@@ -69,6 +70,7 @@ pub fn init() {
|
||||
let context_lock = contexts.insert_context_raw(id).expect("could not initialize first context");
|
||||
let mut context = context_lock.write();
|
||||
context.sched_affinity = Some(crate::cpu_id());
|
||||
context.name = Cow::Borrowed("kmain");
|
||||
|
||||
self::arch::EMPTY_CR3.call_once(|| unsafe { RmmA::table(TableKind::User) });
|
||||
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ pub unsafe fn debugger(target_id: Option<crate::context::ContextId>) {
|
||||
for (id, context_lock) in crate::context::contexts().iter() {
|
||||
if target_id.map_or(false, |target_id| *id != target_id) { continue; }
|
||||
let context = context_lock.read();
|
||||
println!("{}: {}", (*id).into(), context.name.read());
|
||||
println!("{}: {}", (*id).into(), context.name);
|
||||
|
||||
// Switch to context page table to ensure syscall debug and stack dump will work
|
||||
if let Some(ref space) = context.addr_space {
|
||||
|
||||
+2
-3
@@ -73,7 +73,6 @@ extern crate spin;
|
||||
#[cfg(feature = "slab")]
|
||||
extern crate slab_allocator;
|
||||
|
||||
use alloc::string::ToString;
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use crate::scheme::SchemeNamespace;
|
||||
@@ -205,7 +204,7 @@ pub fn kmain(cpus: usize, bootstrap: Bootstrap) -> ! {
|
||||
context.rns = SchemeNamespace::from(1);
|
||||
context.ens = SchemeNamespace::from(1);
|
||||
context.status = context::Status::Runnable;
|
||||
*context.name.write() = "bootstrap".to_string().into_boxed_str();
|
||||
context.name = "bootstrap".into();
|
||||
},
|
||||
Err(err) => {
|
||||
panic!("failed to spawn userspace_init: {:?}", err);
|
||||
@@ -267,7 +266,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 {}", *context.name.read());
|
||||
info!("NAME {}", context.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ pub extern "C" fn rust_begin_unwind(info: &PanicInfo) -> ! {
|
||||
let contexts = context::contexts();
|
||||
if let Some(context_lock) = contexts.current() {
|
||||
let context = context_lock.read();
|
||||
println!("NAME: {}", *context.name.read());
|
||||
println!("NAME: {}", context.name);
|
||||
|
||||
if let Some((a, b, c, d, e, f)) = context.syscall {
|
||||
println!("SYSCALL: {}", syscall::debug::format_call(a, b, c, d, e, f));
|
||||
|
||||
+4
-4
@@ -324,7 +324,7 @@ impl ProcScheme {
|
||||
Operation::Memory { .. } => OperationData::Memory(MemData::default()),
|
||||
Operation::Trace => OperationData::Trace(TraceData::default()),
|
||||
Operation::Static(_) => OperationData::Static(StaticData::new(
|
||||
target.name.read().clone().into()
|
||||
target.name.clone().into_owned().into_bytes().into()
|
||||
)),
|
||||
Operation::AddrSpace { .. } => OperationData::Offset(0),
|
||||
_ => OperationData::Other,
|
||||
@@ -814,7 +814,7 @@ impl Scheme for ProcScheme {
|
||||
// Return read events
|
||||
Ok(read * mem::size_of::<PtraceEvent>())
|
||||
}
|
||||
Operation::Name => read_from(buf, context::contexts().get(info.pid).ok_or(Error::new(ESRCH))?.read().name.read().as_bytes(), &mut 0),
|
||||
Operation::Name => read_from(buf, context::contexts().get(info.pid).ok_or(Error::new(ESRCH))?.read().name.as_bytes(), &mut 0),
|
||||
Operation::Sigstack => read_from(buf, &context::contexts().get(info.pid).ok_or(Error::new(ESRCH))?.read().sigstack.unwrap_or(!0).to_ne_bytes(), &mut 0),
|
||||
Operation::Attr(attr) => {
|
||||
let src_buf = match (attr, &*Arc::clone(context::contexts().get(info.pid).ok_or(Error::new(ESRCH))?).read()) {
|
||||
@@ -1031,8 +1031,8 @@ impl Scheme for ProcScheme {
|
||||
Ok(mem::size_of::<u64>())
|
||||
},
|
||||
Operation::Name => {
|
||||
let utf8 = alloc::string::String::from_utf8(buf.to_vec()).map_err(|_| Error::new(EINVAL))?.into_boxed_str();
|
||||
*context::contexts().get(info.pid).ok_or(Error::new(ESRCH))?.read().name.write() = utf8;
|
||||
let utf8 = alloc::string::String::from_utf8(buf.to_vec()).map_err(|_| Error::new(EINVAL))?;
|
||||
context::contexts().get(info.pid).ok_or(Error::new(ESRCH))?.write().name = utf8.into();
|
||||
Ok(buf.len())
|
||||
}
|
||||
Operation::Sigstack => {
|
||||
|
||||
@@ -14,7 +14,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.read().clone(), context.status_reason));
|
||||
rows.push((*id, context.name.clone(), context.status_reason));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ pub fn resource() -> Result<Vec<u8>> {
|
||||
affinity,
|
||||
cpu_time_string,
|
||||
memory_string,
|
||||
*context.name.read()));
|
||||
context.name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-14
@@ -1,19 +1,8 @@
|
||||
use alloc::{
|
||||
boxed::Box,
|
||||
vec::Vec,
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::context;
|
||||
use crate::syscall::error::{Error, ESRCH, Result};
|
||||
use crate::syscall::error::Result;
|
||||
|
||||
pub fn resource() -> Result<Vec<u8>> {
|
||||
let name = {
|
||||
let contexts = context::contexts();
|
||||
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
|
||||
let context = context_lock.read();
|
||||
let name = context.name.read();
|
||||
let name_bytes: Box<[u8]> = name.clone().into();
|
||||
name_bytes.into_vec()
|
||||
};
|
||||
Ok(name)
|
||||
Ok(context::current()?.read().name.clone().into_owned().into_bytes())
|
||||
}
|
||||
|
||||
@@ -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.read().clone(), context.files.read().clone()));
|
||||
rows.push((*id, context.name.clone(), context.files.read().clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.read().clone(), context.syscall));
|
||||
rows.push((*id, context.name.clone(), context.syscall));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -294,7 +294,7 @@ impl UserInner {
|
||||
let context_lock = Arc::clone(context::contexts().current().ok_or(Error::new(ESRCH))?);
|
||||
let context = context_lock.read();
|
||||
if map.size % PAGE_SIZE != 0 {
|
||||
log::warn!("Unaligned map size for context {:?}", context.name.try_read().as_deref());
|
||||
log::warn!("Unaligned map size for context `{}`", context.name);
|
||||
}
|
||||
// TODO: Faster, cleaner mechanism to get descriptor
|
||||
let scheme = self.scheme_id.load(Ordering::SeqCst);
|
||||
|
||||
@@ -42,7 +42,7 @@ fn empty<'lock>(context_lock: &'lock RwLock<Context>, mut context: RwLockWriteGu
|
||||
|
||||
for grant in addr_space.grants.into_iter() {
|
||||
let unmap_result = if reaping {
|
||||
log::error!("{}: {}: Grant should not exist: {:?}", context.id.into(), *context.name.read(), grant);
|
||||
log::error!("{}: {}: Grant should not exist: {:?}", context.id.into(), context.name, grant);
|
||||
|
||||
grant.unmap(mapper, &mut InactiveFlusher::new())
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user