diff --git a/src/panic.rs b/src/panic.rs index 3c5442f6b5..7c0d4a8730 100644 --- a/src/panic.rs +++ b/src/panic.rs @@ -31,7 +31,7 @@ fn rust_begin_unwind(info: &PanicInfo) -> ! { // This could deadlock, but at this point we are going to halt anyways { let context = context_lock.read(); - println!("NAME: {}", context.name); + println!("NAME: {}, DEBUG ID: {}", context.name, context.debug_id); if let Some([a, b, c, d, e, f]) = context.current_syscall() { println!("SYSCALL: {}", syscall::debug::format_call(a, b, c, d, e, f)); diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs index 67ed54aa53..94b9d3bb94 100644 --- a/src/scheme/mod.rs +++ b/src/scheme/mod.rs @@ -128,17 +128,7 @@ impl SchemeList { // TODO: impl TryFrom and bypass map for global schemes? { use GlobalSchemes::*; - insert_globals(&[ - Debug, - Event, - Memory, - Pipe, - Serio, - Irq, - Time, - Sys, - Proc, - ]); + insert_globals(&[Debug, Event, Memory, Pipe, Serio, Irq, Time, Sys, Proc]); #[cfg(feature = "acpi")] insert_globals(&[Acpi]); diff --git a/src/scheme/proc.rs b/src/scheme/proc.rs index b629fb74c4..9dc0ed6597 100644 --- a/src/scheme/proc.rs +++ b/src/scheme/proc.rs @@ -229,6 +229,20 @@ impl ProcScheme { "sched-affinity" => (ContextHandle::SchedAffinity, true), "status" => (ContextHandle::Status, false), "signal" => (ContextHandle::Signal, false), + _ if path.starts_with("attrs-") => { + let auth_fd = path["attrs-".len()..] + .parse::() + .map_err(|_| Error::new(ENOENT))?; + let (hopefully_this_scheme, number) = extract_scheme_number(auth_fd)?; + verify_scheme(hopefully_this_scheme)?; + if !matches!( + HANDLES.read().get(&number).ok_or(Error::new(ENOENT))?.kind, + ContextHandle::Authority + ) { + return Err(Error::new(ENOENT)); + } + (ContextHandle::Attr, false) + } _ => return Ok(None), })) } @@ -240,12 +254,14 @@ impl ProcScheme { ) -> Result<(usize, InternalFlags)> { let operation_name = operation_str.ok_or(Error::new(EINVAL))?; let (mut handle, positioned) = match ty { - OpenTy::Ctxt(context) => if let Some((kind, positioned)) = - self.openat_context(operation_name, Arc::clone(&context))? - { - (Handle { context, kind }, positioned) - } else { - return Err(Error::new(EINVAL)); + OpenTy::Ctxt(context) => { + if let Some((kind, positioned)) = + self.openat_context(operation_name, Arc::clone(&context))? + { + (Handle { context, kind }, positioned) + } else { + return Err(Error::new(EINVAL)); + } } OpenTy::Auth => { extern "C" fn ret() {} @@ -255,10 +271,13 @@ impl ProcScheme { _ => return Err(Error::new(ENOENT)), }; - (Handle { - context, - kind: ContextHandle::OpenViaDup, - }, false) + ( + Handle { + context, + kind: ContextHandle::OpenViaDup, + }, + false, + ) } }; @@ -545,11 +564,19 @@ impl KernelScheme for ProcScheme { let buf = &array[..raw_buf.len()]; new_handle(match info { - Handle { kind: ContextHandle::Authority, .. } => return self.open_inner(OpenTy::Auth, - Some(core::str::from_utf8(buf).map_err(|_| Error::new(EINVAL))?) + Handle { + kind: ContextHandle::Authority, + .. + } => { + return self + .open_inner( + OpenTy::Auth, + Some(core::str::from_utf8(buf).map_err(|_| Error::new(EINVAL))?) .filter(|s| !s.is_empty()), - O_RDWR | O_CLOEXEC, - ).map(|(r, fl)| OpenResult::SchemeLocal(r, fl)), + O_RDWR | O_CLOEXEC, + ) + .map(|(r, fl)| OpenResult::SchemeLocal(r, fl)) + } Handle { kind: ContextHandle::OpenViaDup, context, @@ -666,10 +693,7 @@ fn extract_scheme_number(fd: usize) -> Result<(KernelSchemes, usize)> { Ok((scheme, number)) } fn verify_scheme(scheme: KernelSchemes) -> Result<()> { - if !matches!( - scheme, - KernelSchemes::Global(GlobalSchemes::Proc) - ) { + if !matches!(scheme, KernelSchemes::Global(GlobalSchemes::Proc)) { return Err(Error::new(EBADF)); } Ok(()) @@ -1002,6 +1026,15 @@ impl ContextHandle { */ Err(Error::new(EOPNOTSUPP)) } + ContextHandle::Attr => { + let info = unsafe { buf.read_exact::()? }; + let mut guard = context.write(); + guard.pid = info.pid as usize; + guard.ens = (info.ens as usize).into(); + guard.euid = info.euid; + guard.egid = info.egid; + Ok(size_of::()) + } _ => Err(Error::new(EBADF)), } } diff --git a/src/syscall/debug.rs b/src/syscall/debug.rs index a912ce9bdc..aa527119a4 100644 --- a/src/syscall/debug.rs +++ b/src/syscall/debug.rs @@ -226,11 +226,7 @@ pub fn debug_start([a, b, c, d, e, f]: [usize; 6]) { let context_lock = crate::context::current(); { let context = context_lock.read(); - print!( - "{} (*{}*): ", - context.name, - context.debug_id, - ); + print!("{} (*{}*): ", context.name, context.debug_id,); } // Do format_call outside print! so possible exception handlers cannot reentrantly @@ -266,11 +262,7 @@ pub fn debug_end([a, b, c, d, e, f]: [usize; 6], result: Result) { let context_lock = crate::context::current(); { let context = context_lock.read(); - print!( - "{} (*{}*): ", - context.name, - context.debug_id, - ); + print!("{} (*{}*): ", context.name, context.debug_id,); } // Do format_call outside print! so possible exception handlers cannot reentrantly diff --git a/src/syscall/privilege.rs b/src/syscall/privilege.rs index d5353a6d2d..7b8fed4bf0 100644 --- a/src/syscall/privilege.rs +++ b/src/syscall/privilege.rs @@ -1,10 +1,6 @@ use alloc::vec::Vec; -use crate::{ - context, - scheme, - syscall::error::*, -}; +use crate::{context, scheme, syscall::error::*}; use super::{ copy_path_to_buf,