Make sigaltstack as per-threaded, because per-process sigaltstack state

is useless for threaded programs, multiple threads can not share same
stack.
The alternative signal stack is private for thread, no lock is needed,
the orignal P_ALTSTACK is now moved into td_pflags and renamed to
TDP_ALTSTACK.
For single thread or Linux clone() based threaded program, there is no
semantic changed, because those programs only have one kernel thread
in every process.

Reviewed by: deischen, dfr
This commit is contained in:
David Xu 2004-01-03 02:02:26 +00:00
parent 16844a97c8
commit a30ec4b99c
14 changed files with 175 additions and 181 deletions

View File

@ -1163,12 +1163,12 @@ osendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
* will fail if the process has not already allocated
* the space with a `brk'.
*/
if ((p->p_flag & P_ALTSTACK) && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sip = (osiginfo_t *)((caddr_t)p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - rndfsize);
sip = (osiginfo_t *)((caddr_t)td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - rndfsize);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sip = (osiginfo_t *)(alpha_pal_rdusp() - rndfsize);
@ -1263,8 +1263,8 @@ freebsd4_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/* save user context */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
@ -1287,12 +1287,12 @@ freebsd4_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
* will fail if the process has not already allocated
* the space with a `brk'.
*/
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct sigframe4 *)((caddr_t)p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - rndfsize);
sfp = (struct sigframe4 *)((caddr_t)td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - rndfsize);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sfp = (struct sigframe4 *)(alpha_pal_rdusp() - rndfsize);
@ -1386,8 +1386,8 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/* save user context */
bzero(&sf, sizeof(struct sigframe));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
@ -1411,12 +1411,12 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
* will fail if the process has not already allocated
* the space with a `brk'.
*/
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct sigframe *)((caddr_t)p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - rndfsize);
sfp = (struct sigframe *)((caddr_t)td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - rndfsize);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sfp = (struct sigframe *)(alpha_pal_rdusp() - rndfsize);
@ -1535,9 +1535,9 @@ osigreturn(struct thread *td,
* Restore the user-supplied information
*/
if (ksc.sc_onstack)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
/*
@ -1622,9 +1622,9 @@ freebsd4_sigreturn(struct thread *td,
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (uc.uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = uc.uc_sigmask;
@ -1698,9 +1698,9 @@ sigreturn(struct thread *td,
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (uc.uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = uc.uc_sigmask;

View File

@ -246,8 +246,8 @@ sendsig(catcher, sig, mask, code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
bcopy(regs, &sf.sf_uc.uc_mcontext.mc_rdi, sizeof(*regs));
@ -256,12 +256,12 @@ sendsig(catcher, sig, mask, code)
fpstate_drop(td);
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sp = p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct sigframe);
sp = td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct sigframe);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sp = (char *)regs->tf_rsp - sizeof(struct sigframe) - 128;
@ -403,9 +403,9 @@ sigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (ucp->uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = ucp->uc_sigmask;

View File

@ -194,9 +194,9 @@ freebsd4_ia32_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack.ss_sp = (uintptr_t)p->p_sigstk.ss_sp;
sf.sf_uc.uc_stack.ss_size = p->p_sigstk.ss_size;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack.ss_sp = (uintptr_t)td->td_sigstk.ss_sp;
sf.sf_uc.uc_stack.ss_size = td->td_sigstk.ss_size;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
sf.sf_uc.uc_mcontext.mc_gs = rgs();
@ -220,10 +220,10 @@ freebsd4_ia32_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
sf.sf_uc.uc_mcontext.mc_ss = regs->tf_ss;
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct ia32_sigframe4 *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(sf));
sfp = (struct ia32_sigframe4 *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(sf));
} else
sfp = (struct ia32_sigframe4 *)regs->tf_rsp - 1;
PROC_UNLOCK(p);
@ -308,9 +308,9 @@ ia32_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack.ss_sp = (uintptr_t)p->p_sigstk.ss_sp;
sf.sf_uc.uc_stack.ss_size = p->p_sigstk.ss_size;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack.ss_sp = (uintptr_t)td->td_sigstk.ss_sp;
sf.sf_uc.uc_stack.ss_size = td->td_sigstk.ss_size;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
sf.sf_uc.uc_mcontext.mc_gs = rgs();
@ -337,10 +337,10 @@ ia32_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
fpstate_drop(td);
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sp = p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(sf);
sp = td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(sf);
} else
sp = (char *)regs->tf_rsp - sizeof(sf);
/* Align to 16 bytes. */

View File

@ -271,12 +271,12 @@ osendsig(catcher, sig, mask, code)
oonstack = sigonstack(regs->tf_esp);
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct osigframe *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct osigframe));
fp = (struct osigframe *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct osigframe));
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
fp = (struct osigframe *)regs->tf_esp - 1;
@ -403,20 +403,20 @@ freebsd4_sendsig(catcher, sig, mask, code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
sf.sf_uc.uc_mcontext.mc_gs = rgs();
bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(*regs));
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct sigframe4 *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct sigframe4));
sfp = (struct sigframe4 *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct sigframe4));
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sfp = (struct sigframe4 *)regs->tf_esp - 1;
@ -537,8 +537,8 @@ sendsig(catcher, sig, mask, code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
sf.sf_uc.uc_mcontext.mc_gs = rgs();
@ -548,12 +548,12 @@ sendsig(catcher, sig, mask, code)
fpstate_drop(td);
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sp = p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct sigframe);
sp = td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct sigframe);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sp = (char *)regs->tf_esp - sizeof(struct sigframe);
@ -771,9 +771,9 @@ osigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (scp->sc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
SIGSETOLD(td->td_sigmask, scp->sc_mask);
SIG_CANTMASK(td->td_sigmask);
@ -878,9 +878,9 @@ freebsd4_sigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (ucp->uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = ucp->uc_sigmask;
@ -988,9 +988,9 @@ sigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (ucp->uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = ucp->uc_sigmask;

View File

@ -290,10 +290,10 @@ linux_rt_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/*
* Allocate space for the signal handler context.
*/
if ((p->p_flag & P_ALTSTACK) && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct l_rt_sigframe *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct l_rt_sigframe));
fp = (struct l_rt_sigframe *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct l_rt_sigframe));
} else
fp = (struct l_rt_sigframe *)regs->tf_esp - 1;
mtx_unlock(&psp->ps_mtx);
@ -323,9 +323,9 @@ linux_rt_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
frame.sf_sc.uc_flags = 0; /* XXX ??? */
frame.sf_sc.uc_link = NULL; /* XXX ??? */
frame.sf_sc.uc_stack.ss_sp = p->p_sigstk.ss_sp;
frame.sf_sc.uc_stack.ss_size = p->p_sigstk.ss_size;
frame.sf_sc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
frame.sf_sc.uc_stack.ss_sp = td->td_sigstk.ss_sp;
frame.sf_sc.uc_stack.ss_size = td->td_sigstk.ss_size;
frame.sf_sc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE;
PROC_UNLOCK(p);
@ -431,10 +431,10 @@ linux_sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/*
* Allocate space for the signal handler context.
*/
if ((p->p_flag & P_ALTSTACK) && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct l_sigframe *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct l_sigframe));
fp = (struct l_sigframe *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct l_sigframe));
} else
fp = (struct l_sigframe *)regs->tf_esp - 1;
mtx_unlock(&psp->ps_mtx);

View File

@ -882,8 +882,8 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/* save user context */
bzero(&sf, sizeof(struct sigframe));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
/*
@ -893,13 +893,13 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
* will fail if the process has not already allocated
* the space with a `brk'.
*/
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sbs = (u_int64_t)p->p_sigstk.ss_sp;
sbs = (u_int64_t)td->td_sigstk.ss_sp;
sbs = (sbs + 15) & ~15;
sfp = (struct sigframe *)(sbs + p->p_sigstk.ss_size);
sfp = (struct sigframe *)(sbs + td->td_sigstk.ss_size);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sfp = (struct sigframe *)sp;
@ -1016,9 +1016,9 @@ sigreturn(struct thread *td,
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (sigonstack(tf->tf_special.sp))
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = uc.uc_sigmask;
SIG_CANTMASK(td->td_sigmask);

View File

@ -483,6 +483,8 @@ fork1(td, flags, pages, procp)
(unsigned) RANGEOF(struct ksegrp, kg_startcopy, kg_endcopy));
#undef RANGEOF
td2->td_sigstk = td->td_sigstk;
/* Set up the thread as an active thread (as if runnable). */
ke2->ke_state = KES_THREAD;
ke2->ke_thread = td2;
@ -580,7 +582,8 @@ fork1(td, flags, pages, procp)
* Preserve some more flags in subprocess. P_PROFIL has already
* been preserved.
*/
p2->p_flag |= p1->p_flag & (P_ALTSTACK | P_SUGID);
p2->p_flag |= p1->p_flag & P_SUGID;
td2->td_pflags |= td->td_pflags & TDP_ALTSTACK;
SESS_LOCK(p1->p_session);
if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT)
p2->p_flag |= P_CONTROLT;

View File

@ -235,15 +235,15 @@ signotify(struct thread *td)
int
sigonstack(size_t sp)
{
struct proc *p = curthread->td_proc;
struct thread *td = curthread;
PROC_LOCK_ASSERT(p, MA_OWNED);
return ((p->p_flag & P_ALTSTACK) ?
return ((td->td_pflags & TDP_ALTSTACK) ?
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
((p->p_sigstk.ss_size == 0) ? (p->p_sigstk.ss_flags & SS_ONSTACK) :
((sp - (size_t)p->p_sigstk.ss_sp) < p->p_sigstk.ss_size))
((td->td_sigstk.ss_size == 0) ?
(td->td_sigstk.ss_flags & SS_ONSTACK) :
((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size))
#else
((sp - (size_t)p->p_sigstk.ss_sp) < p->p_sigstk.ss_size)
((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size)
#endif
: 0);
}
@ -582,11 +582,11 @@ siginit(p)
* Reset signals for an exec of the specified process.
*/
void
execsigs(p)
register struct proc *p;
execsigs(struct proc *p)
{
register struct sigacts *ps;
register int sig;
struct sigacts *ps;
int sig;
struct thread *td;
/*
* Reset caught signals. Held signals remain held
@ -594,6 +594,7 @@ execsigs(p)
* and are now ignored by default).
*/
PROC_LOCK_ASSERT(p, MA_OWNED);
td = FIRST_THREAD_IN_PROC(p);
ps = p->p_sigacts;
mtx_lock(&ps->ps_mtx);
while (SIGNOTEMPTY(ps->ps_sigcatch)) {
@ -606,7 +607,7 @@ execsigs(p)
/*
* There is only one thread at this point.
*/
SIGDELSET(FIRST_THREAD_IN_PROC(p)->td_siglist, sig);
SIGDELSET(td->td_siglist, sig);
}
ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL;
}
@ -614,10 +615,10 @@ execsigs(p)
* Reset stack state to the user stack.
* Clear set of signals caught on the signal stack.
*/
p->p_sigstk.ss_flags = SS_DISABLE;
p->p_sigstk.ss_size = 0;
p->p_sigstk.ss_sp = 0;
p->p_flag &= ~P_ALTSTACK;
td->td_sigstk.ss_flags = SS_DISABLE;
td->td_sigstk.ss_size = 0;
td->td_sigstk.ss_sp = 0;
td->td_pflags &= ~TDP_ALTSTACK;
/*
* Reset no zombies if child dies flag as Solaris does.
*/
@ -1208,7 +1209,6 @@ osigstack(td, uap)
struct thread *td;
register struct osigstack_args *uap;
{
struct proc *p = td->td_proc;
struct sigstack nss, oss;
int error = 0;
@ -1217,16 +1217,14 @@ osigstack(td, uap)
if (error)
return (error);
}
PROC_LOCK(p);
oss.ss_sp = p->p_sigstk.ss_sp;
oss.ss_sp = td->td_sigstk.ss_sp;
oss.ss_onstack = sigonstack(cpu_getstack(td));
if (uap->nss != NULL) {
p->p_sigstk.ss_sp = nss.ss_sp;
p->p_sigstk.ss_size = 0;
p->p_sigstk.ss_flags |= nss.ss_onstack & SS_ONSTACK;
p->p_flag |= P_ALTSTACK;
td->td_sigstk.ss_sp = nss.ss_sp;
td->td_sigstk.ss_size = 0;
td->td_sigstk.ss_flags |= nss.ss_onstack & SS_ONSTACK;
td->td_pflags |= TDP_ALTSTACK;
}
PROC_UNLOCK(p);
if (uap->oss != NULL)
error = copyout(&oss, uap->oss, sizeof(oss));
@ -1272,36 +1270,29 @@ kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss)
struct proc *p = td->td_proc;
int oonstack;
PROC_LOCK(p);
oonstack = sigonstack(cpu_getstack(td));
if (oss != NULL) {
*oss = p->p_sigstk;
oss->ss_flags = (p->p_flag & P_ALTSTACK)
*oss = td->td_sigstk;
oss->ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
}
if (ss != NULL) {
if (oonstack) {
PROC_UNLOCK(p);
if (oonstack)
return (EPERM);
}
if ((ss->ss_flags & ~SS_DISABLE) != 0) {
PROC_UNLOCK(p);
if ((ss->ss_flags & ~SS_DISABLE) != 0)
return (EINVAL);
}
if (!(ss->ss_flags & SS_DISABLE)) {
if (ss->ss_size < p->p_sysent->sv_minsigstksz) {
PROC_UNLOCK(p);
return (ENOMEM);
}
p->p_sigstk = *ss;
p->p_flag |= P_ALTSTACK;
td->td_sigstk = *ss;
td->td_pflags |= TDP_ALTSTACK;
} else {
p->p_flag &= ~P_ALTSTACK;
td->td_pflags &= ~TDP_ALTSTACK;
}
}
PROC_UNLOCK(p);
return (0);
}

View File

@ -285,12 +285,12 @@ osendsig(catcher, sig, mask, code)
oonstack = sigonstack(regs->tf_esp);
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct osigframe *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct osigframe));
fp = (struct osigframe *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct osigframe));
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
fp = (struct osigframe *)regs->tf_esp - 1;
@ -417,20 +417,20 @@ freebsd4_sendsig(catcher, sig, mask, code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
sf.sf_uc.uc_mcontext.mc_gs = rgs();
bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(*regs));
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct sigframe4 *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct sigframe4));
sfp = (struct sigframe4 *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct sigframe4));
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sfp = (struct sigframe4 *)regs->tf_esp - 1;
@ -551,8 +551,8 @@ sendsig(catcher, sig, mask, code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
sf.sf_uc.uc_mcontext.mc_gs = rgs();
@ -562,12 +562,12 @@ sendsig(catcher, sig, mask, code)
fpstate_drop(td);
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sp = p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct sigframe);
sp = td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct sigframe);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sp = (char *)regs->tf_esp - sizeof(struct sigframe);
@ -785,9 +785,9 @@ osigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (scp->sc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
SIGSETOLD(td->td_sigmask, scp->sc_mask);
SIG_CANTMASK(td->td_sigmask);
@ -892,9 +892,9 @@ freebsd4_sigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (ucp->uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = ucp->uc_sigmask;
@ -1002,9 +1002,9 @@ sigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (ucp->uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = ucp->uc_sigmask;

View File

@ -285,12 +285,12 @@ osendsig(catcher, sig, mask, code)
oonstack = sigonstack(regs->tf_esp);
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
fp = (struct osigframe *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct osigframe));
fp = (struct osigframe *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct osigframe));
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
fp = (struct osigframe *)regs->tf_esp - 1;
@ -417,20 +417,20 @@ freebsd4_sendsig(catcher, sig, mask, code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
sf.sf_uc.uc_mcontext.mc_gs = rgs();
bcopy(regs, &sf.sf_uc.uc_mcontext.mc_fs, sizeof(*regs));
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct sigframe4 *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct sigframe4));
sfp = (struct sigframe4 *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct sigframe4));
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sfp = (struct sigframe4 *)regs->tf_esp - 1;
@ -551,8 +551,8 @@ sendsig(catcher, sig, mask, code)
/* Save user context. */
bzero(&sf, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
sf.sf_uc.uc_mcontext.mc_gs = rgs();
@ -562,12 +562,12 @@ sendsig(catcher, sig, mask, code)
fpstate_drop(td);
/* Allocate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sp = p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct sigframe);
sp = td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct sigframe);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
#endif
} else
sp = (char *)regs->tf_esp - sizeof(struct sigframe);
@ -785,9 +785,9 @@ osigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (scp->sc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
SIGSETOLD(td->td_sigmask, scp->sc_mask);
SIG_CANTMASK(td->td_sigmask);
@ -892,9 +892,9 @@ freebsd4_sigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (ucp->uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = ucp->uc_sigmask;
@ -1002,9 +1002,9 @@ sigreturn(td, uap)
PROC_LOCK(p);
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
if (ucp->uc_mcontext.mc_onstack & 1)
p->p_sigstk.ss_flags |= SS_ONSTACK;
td->td_sigstk.ss_flags |= SS_ONSTACK;
else
p->p_sigstk.ss_flags &= ~SS_ONSTACK;
td->td_sigstk.ss_flags &= ~SS_ONSTACK;
#endif
td->td_sigmask = ucp->uc_sigmask;

View File

@ -424,8 +424,8 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
*/
memset(&sf, 0, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
@ -434,10 +434,10 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/*
* Allocate and validate space for the signal handler context.
*/
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct sigframe *)((caddr_t)p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - rndfsize);
sfp = (struct sigframe *)((caddr_t)td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - rndfsize);
} else {
sfp = (struct sigframe *)(tf->fixreg[1] - rndfsize);
}

View File

@ -424,8 +424,8 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
*/
memset(&sf, 0, sizeof(sf));
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
@ -434,10 +434,10 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
/*
* Allocate and validate space for the signal handler context.
*/
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct sigframe *)((caddr_t)p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - rndfsize);
sfp = (struct sigframe *)((caddr_t)td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - rndfsize);
} else {
sfp = (struct sigframe *)(tf->fixreg[1] - rndfsize);
}

View File

@ -441,15 +441,15 @@ sendsig(sig_t catcher, int sig, sigset_t *mask, u_long code)
bzero(&sf, sizeof(sf));
get_mcontext(td, &sf.sf_uc.uc_mcontext, 0);
sf.sf_uc.uc_sigmask = *mask;
sf.sf_uc.uc_stack = p->p_sigstk;
sf.sf_uc.uc_stack.ss_flags = (p->p_flag & P_ALTSTACK)
sf.sf_uc.uc_stack = td->td_sigstk;
sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
/* Allocate and validate space for the signal handler context. */
if ((p->p_flag & P_ALTSTACK) != 0 && !oonstack &&
if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
SIGISMEMBER(psp->ps_sigonstack, sig)) {
sfp = (struct sigframe *)(p->p_sigstk.ss_sp +
p->p_sigstk.ss_size - sizeof(struct sigframe));
sfp = (struct sigframe *)(td->td_sigstk.ss_sp +
td->td_sigstk.ss_size - sizeof(struct sigframe));
} else
sfp = (struct sigframe *)sp - 1;
mtx_unlock(&psp->ps_mtx);

View File

@ -302,6 +302,7 @@ struct thread {
sigset_t *td_waitset; /* (c) Wait set for sigwait. */
TAILQ_ENTRY(thread) td_umtx; /* (c?) Link for when we're blocked. */
volatile u_int td_generation; /* (k) Enable detection of preemption */
stack_t td_sigstk; /* (k) Stack ptr and on-stack flag. */
#define td_endzero td_base_pri
@ -363,6 +364,7 @@ struct thread {
#define TDP_INKTRACE 0x0004 /* Thread is currently in KTRACE code. */
#define TDP_UPCALLING 0x0008 /* This thread is doing an upcall. */
#define TDP_COWINPROGRESS 0x0010 /* Snapshot copy-on-write in progress. */
#define TDP_ALTSTACK 0x0020 /* Have alternate signal stack. */
#define TDI_SUSPENDED 0x0001 /* On suspension queue. */
#define TDI_SLEEPING 0x0002 /* Actually asleep! (tricky). */
@ -586,11 +588,10 @@ struct proc {
struct thread *p_singlethread;/* (c + j) If single threading this is it */
int p_suspcount; /* (c) # threads in suspended mode */
/* End area that is zeroed on creation. */
#define p_endzero p_sigstk
#define p_endzero p_magic
/* The following fields are all copied upon creation in fork. */
#define p_startcopy p_endzero
stack_t p_sigstk; /* (c) Stack ptr and on-stack flag. */
u_int p_magic; /* (b) Magic number. */
char p_comm[MAXCOMLEN + 1]; /* (b) Process name. */
struct pgrp *p_pgrp; /* (c + e) Pointer to process group. */
@ -648,7 +649,6 @@ struct proc {
#define P_SIGEVENT 0x200000 /* Process pending signals changed. */
#define P_JAILED 0x1000000 /* Process is in jail. */
#define P_ALTSTACK 0x2000000 /* Have alternate signal stack. */
#define P_INEXEC 0x4000000 /* Process is in execve(). */
#define P_STOPPED (P_STOPPED_SIG|P_STOPPED_SINGLE|P_STOPPED_TRACE)