Replace most of the current_thread! usages via Context

This commit is contained in:
Zhang Junyang
2024-08-11 14:32:47 +00:00
committed by Tate, Hongliang Tian
parent 9200538175
commit 8cf7063150
10 changed files with 52 additions and 85 deletions

View File

@ -3,16 +3,13 @@
use super::SyscallReturn;
use crate::{
prelude::*,
process::{
posix_thread::PosixThreadExt,
signal::{SigStack, SigStackFlags},
},
process::signal::{SigStack, SigStackFlags},
};
pub fn sys_sigaltstack(
sig_stack_addr: Vaddr,
old_sig_stack_addr: Vaddr,
_ctx: &Context,
ctx: &Context,
) -> Result<SyscallReturn> {
debug!(
"sig_stack_addr = 0x{:x}, old_sig_stack_addr: 0x{:x}",
@ -20,14 +17,12 @@ pub fn sys_sigaltstack(
);
let old_stack = {
let current_thread = current_thread!();
let posix_thread = current_thread.as_posix_thread().unwrap();
let sig_stack = posix_thread.sig_stack().lock();
let sig_stack = ctx.posix_thread.sig_stack().lock();
sig_stack.clone()
};
get_old_stack(old_sig_stack_addr, old_stack.as_ref())?;
set_new_stack(sig_stack_addr, old_stack.as_ref())?;
set_new_stack(sig_stack_addr, old_stack.as_ref(), ctx)?;
Ok(SyscallReturn::Return(0))
}
@ -47,7 +42,7 @@ fn get_old_stack(old_sig_stack_addr: Vaddr, old_stack: Option<&SigStack>) -> Res
CurrentUserSpace::get().write_val(old_sig_stack_addr, &stack)
}
fn set_new_stack(sig_stack_addr: Vaddr, old_stack: Option<&SigStack>) -> Result<()> {
fn set_new_stack(sig_stack_addr: Vaddr, old_stack: Option<&SigStack>, ctx: &Context) -> Result<()> {
if sig_stack_addr == 0 {
return Ok(());
}
@ -65,9 +60,7 @@ fn set_new_stack(sig_stack_addr: Vaddr, old_stack: Option<&SigStack>) -> Result<
debug!("new_stack = {:?}", new_stack);
let current_thread = current_thread!();
let posix_thread = current_thread.as_posix_thread().unwrap();
*posix_thread.sig_stack().lock() = Some(new_stack);
*ctx.posix_thread.sig_stack().lock() = Some(new_stack);
Ok(())
}