From 24b08bca030970592bc5241517b0462f603b05b1 Mon Sep 17 00:00:00 2001 From: jkim Date: Wed, 22 Dec 2010 00:18:42 +0000 Subject: Improve PCB flags handling and make it more robust. Add two new functions for manipulating pcb_flags. These inline functions are very similar to atomic_set_char(9) and atomic_clear_char(9) but without unnecessary LOCK prefix for SMP. Add comments about the rationale[1]. Use these functions wherever possible. Although there are some places where it is not strictly necessary (e.g., a PCB is copied to create a new PCB), it is done across the board for sake of consistency. Turn pcb_full_iret into a PCB flag as it is safe now. Move rarely used fields before pcb_flags and reduce size of pcb_flags to one byte. Fix some style(9) nits in pcb.h while I am in the neighborhood. Reviewed by: kib Submitted by: kib[1] MFC after: 2 months --- sys/amd64/ia32/ia32_signal.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'sys/amd64/ia32/ia32_signal.c') diff --git a/sys/amd64/ia32/ia32_signal.c b/sys/amd64/ia32/ia32_signal.c index e0f30e2..808790b 100644 --- a/sys/amd64/ia32/ia32_signal.c +++ b/sys/amd64/ia32/ia32_signal.c @@ -130,8 +130,10 @@ ia32_set_fpcontext(struct thread *td, const struct ia32_mcontext *mcp) static int ia32_get_mcontext(struct thread *td, struct ia32_mcontext *mcp, int flags) { + struct pcb *pcb; struct trapframe *tp; + pcb = td->td_pcb; tp = td->td_frame; PROC_LOCK(curthread->td_proc); @@ -163,9 +165,9 @@ ia32_get_mcontext(struct thread *td, struct ia32_mcontext *mcp, int flags) mcp->mc_ss = tp->tf_ss; mcp->mc_len = sizeof(*mcp); ia32_get_fpcontext(td, mcp); - mcp->mc_fsbase = td->td_pcb->pcb_fsbase; - mcp->mc_gsbase = td->td_pcb->pcb_gsbase; - td->td_pcb->pcb_full_iret = 1; + mcp->mc_fsbase = pcb->pcb_fsbase; + mcp->mc_gsbase = pcb->pcb_gsbase; + set_pcb_flags(pcb, PCB_FULL_IRET); return (0); } @@ -207,7 +209,7 @@ ia32_set_mcontext(struct thread *td, const struct ia32_mcontext *mcp) tp->tf_rflags = rflags; tp->tf_rsp = mcp->mc_esp; tp->tf_ss = mcp->mc_ss; - td->td_pcb->pcb_full_iret = 1; + set_pcb_flags(td->td_pcb, PCB_FULL_IRET); return (0); } @@ -397,7 +399,7 @@ freebsd4_ia32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) regs->tf_ss = _udatasel; regs->tf_ds = _udatasel; regs->tf_es = _udatasel; - td->td_pcb->pcb_full_iret = 1; + set_pcb_flags(td->td_pcb, PCB_FULL_IRET); /* leave user %fs and %gs untouched */ PROC_LOCK(p); mtx_lock(&psp->ps_mtx); @@ -518,7 +520,7 @@ ia32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) regs->tf_ss = _udatasel; regs->tf_ds = _udatasel; regs->tf_es = _udatasel; - td->td_pcb->pcb_full_iret = 1; + set_pcb_flags(td->td_pcb, PCB_FULL_IRET); /* XXXKIB leave user %fs and %gs untouched */ PROC_LOCK(p); mtx_lock(&psp->ps_mtx); @@ -613,7 +615,7 @@ freebsd4_freebsd32_sigreturn(td, uap) regs->tf_gs = ucp->uc_mcontext.mc_gs; kern_sigprocmask(td, SIG_SETMASK, &ucp->uc_sigmask, NULL, 0); - td->td_pcb->pcb_full_iret = 1; + set_pcb_flags(td->td_pcb, PCB_FULL_IRET); return (EJUSTRETURN); } #endif /* COMPAT_FREEBSD4 */ @@ -702,7 +704,7 @@ freebsd32_sigreturn(td, uap) regs->tf_flags = TF_HASSEGS; kern_sigprocmask(td, SIG_SETMASK, &ucp->uc_sigmask, NULL, 0); - td->td_pcb->pcb_full_iret = 1; + set_pcb_flags(td->td_pcb, PCB_FULL_IRET); return (EJUSTRETURN); } @@ -742,8 +744,7 @@ ia32_setregs(struct thread *td, struct image_params *imgp, u_long stack) fpstate_drop(td); /* Return via doreti so that we can change to a different %cs */ - pcb->pcb_flags |= PCB_32BIT; - pcb->pcb_flags &= ~PCB_GS32BIT; - td->td_pcb->pcb_full_iret = 1; + set_pcb_flags(pcb, PCB_32BIT | PCB_FULL_IRET); + clear_pcb_flags(pcb, PCB_GS32BIT); td->td_retval[1] = 0; } -- cgit v1.1