From 41bea0086fbf8efff82bf917b5cc51eac005e44c Mon Sep 17 00:00:00 2001 From: Jeremy Soller <jeremy@system76.com> Date: Sat, 13 Feb 2021 13:01:20 -0700 Subject: [PATCH] Switch Context::actions to RwLock --- src/context/context.rs | 4 ++-- src/context/signal.rs | 2 +- src/ptrace.rs | 4 ++-- src/syscall/process.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/context/context.rs b/src/context/context.rs index fccd6b0e..5926a16f 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -241,7 +241,7 @@ pub struct Context { /// The open files in the scheme pub files: Arc<RwLock<Vec<Option<FileDescriptor>>>>, /// Signal actions - pub actions: Arc<Mutex<Vec<(SigAction, usize)>>>, + pub actions: Arc<RwLock<Vec<(SigAction, usize)>>>, /// The pointer to the user-space registers, saved after certain /// interrupts. This pointer is somewhere inside kstack, and the /// kstack address at the time of creation is the first element in @@ -295,7 +295,7 @@ impl Context { name: Arc::new(RwLock::new(String::new().into_boxed_str())), cwd: Arc::new(RwLock::new(Vec::new())), files: Arc::new(RwLock::new(Vec::new())), - actions: Arc::new(Mutex::new(vec![( + actions: Arc::new(RwLock::new(vec![( SigAction { sa_handler: unsafe { mem::transmute(SIG_DFL) }, sa_mask: [0; 2], diff --git a/src/context/signal.rs b/src/context/signal.rs index 05d3ff74..bc5add17 100644 --- a/src/context/signal.rs +++ b/src/context/signal.rs @@ -17,7 +17,7 @@ pub extern "C" fn signal_handler(sig: usize) { let contexts = contexts(); let context_lock = contexts.current().expect("context::signal_handler not inside of context"); let context = context_lock.read(); - let actions = context.actions.lock(); + let actions = context.actions.read(); actions[sig] }; diff --git a/src/ptrace.rs b/src/ptrace.rs index aeea28f2..6f0e7416 100644 --- a/src/ptrace.rs +++ b/src/ptrace.rs @@ -404,7 +404,7 @@ pub unsafe fn regs_for(context: &Context) -> Option<&InterruptStack> { None => None, Some((_, _, ref kstack, signum)) => { let is_user_handled = { - let actions = context.actions.lock(); + let actions = context.actions.read(); signal::is_user_handled(actions[signum as usize].0.sa_handler) }; if is_user_handled { @@ -425,7 +425,7 @@ pub unsafe fn regs_for_mut(context: &mut Context) -> Option<&mut InterruptStack> None => None, Some((_, _, ref mut kstack, signum)) => { let is_user_handled = { - let actions = context.actions.lock(); + let actions = context.actions.read(); signal::is_user_handled(actions[signum as usize].0.sa_handler) }; if is_user_handled { diff --git a/src/syscall/process.rs b/src/syscall/process.rs index 262ffff9..94d3766f 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -265,7 +265,7 @@ pub fn clone(flags: CloneFlags, stack_base: usize) -> Result<ContextId> { if flags.contains(CLONE_SIGHAND) { actions = Arc::clone(&context.actions); } else { - actions = Arc::new(Mutex::new(context.actions.lock().clone())); + actions = Arc::new(RwLock::new(context.actions.read().clone())); } } @@ -849,7 +849,7 @@ fn fexec_noreturn( drop(args); drop(vars); - context.actions = Arc::new(Mutex::new(vec![( + context.actions = Arc::new(RwLock::new(vec![( SigAction { sa_handler: unsafe { mem::transmute(SIG_DFL) }, sa_mask: [0; 2], @@ -1414,7 +1414,7 @@ pub fn sigaction(sig: usize, act_opt: Option<&SigAction>, oldact_opt: Option<&mu let contexts = context::contexts(); let context_lock = contexts.current().ok_or(Error::new(ESRCH))?; let context = context_lock.read(); - let mut actions = context.actions.lock(); + let mut actions = context.actions.write(); if let Some(oldact) = oldact_opt { *oldact = actions[sig].0; -- GitLab