From 12e45a7692e868748f3807490c64f4c14b8a7ca3 Mon Sep 17 00:00:00 2001 From: mpi Date: Thu, 4 Mar 2021 09:02:37 +0000 Subject: [PATCH] Merge issignal() and CURSIG() in preparation for turning it mp-safe. This makes appear some redundant & racy checks. ok semarie@ --- sys/kern/kern_sig.c | 32 ++++++++++++++++++++------------ sys/kern/kern_synch.c | 4 ++-- sys/sys/signalvar.h | 15 ++------------- sys/ufs/mfs/mfs_vfsops.c | 4 ++-- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 97d99967826..8f957beab20 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.273 2021/02/15 09:35:59 mpi Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.274 2021/03/04 09:02:37 mpi Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -1035,7 +1035,7 @@ ptsignal(struct proc *p, int signum, enum signal_type type) goto out; /* * Process is sleeping and traced... make it runnable - * so it can discover the signal in issignal() and stop + * so it can discover the signal in cursig() and stop * for the parent. */ if (pr->ps_flags & PS_TRACED) @@ -1159,28 +1159,36 @@ out: } /* + * Determine signal that should be delivered to process p, the current + * process, 0 if none. + * * If the current process has received a signal (should be caught or cause * termination, should interrupt current syscall), return the signal number. * Stop signals with default action are processed immediately, then cleared; * they aren't returned. This is checked after each entry to the system for - * a syscall or trap (though this can usually be done without calling issignal - * by checking the pending signal masks in the CURSIG macro.) The normal call - * sequence is + * a syscall or trap. The normal call sequence is * - * while (signum = CURSIG(curproc)) + * while (signum = cursig(curproc)) * postsig(signum); * * Assumes that if the P_SINTR flag is set, we're holding both the * kernel and scheduler locks. */ int -issignal(struct proc *p) +cursig(struct proc *p) { struct process *pr = p->p_p; - int signum, mask, prop; + int sigpending, signum, mask, prop; int dolock = (p->p_flag & P_SINTR) == 0; int s; + sigpending = (p->p_siglist | pr->ps_siglist); + if (sigpending == 0) + return 0; + + if (!ISSET(pr->ps_flags, PS_TRACED) && SIGPENDING(p) == 0) + return 0; + for (;;) { mask = SIGPENDING(p); if (pr->ps_flags & PS_PPWAIT) @@ -1304,7 +1312,7 @@ issignal(struct proc *p) */ if ((prop & SA_CONT) == 0 && (pr->ps_flags & PS_TRACED) == 0) - printf("issignal\n"); + printf("%s\n", __func__); break; /* == ignore */ default: /* @@ -1766,7 +1774,7 @@ sys___thrsigdivert(struct proc *p, void *v, register_t *retval) dosigsuspend(p, p->p_sigmask &~ mask); for (;;) { - si.si_signo = CURSIG(p); + si.si_signo = cursig(p); if (si.si_signo != 0) { sigset_t smask = sigmask(si.si_signo); if (smask & mask) { @@ -1907,7 +1915,7 @@ userret(struct proc *p) if (SIGPENDING(p) != 0) { KERNEL_LOCK(); - while ((signum = CURSIG(p)) != 0) + while ((signum = cursig(p)) != 0) postsig(p, signum); KERNEL_UNLOCK(); } @@ -1923,7 +1931,7 @@ userret(struct proc *p) p->p_sigmask = p->p_oldmask; KERNEL_LOCK(); - while ((signum = CURSIG(p)) != 0) + while ((signum = cursig(p)) != 0) postsig(p, signum); KERNEL_UNLOCK(); } diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 45f97b2e604..b476a6b4253 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_synch.c,v 1.176 2021/02/08 10:51:02 mpi Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.177 2021/03/04 09:02:37 mpi Exp $ */ /* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */ /* @@ -479,7 +479,7 @@ sleep_signal_check(void) if ((err = single_thread_check(p, 1)) != 0) return err; - if ((sig = CURSIG(p)) != 0) { + if ((sig = cursig(p)) != 0) { if (p->p_p->ps_sigacts->ps_sigintr & sigmask(sig)) return EINTR; else diff --git a/sys/sys/signalvar.h b/sys/sys/signalvar.h index a4629a8f96f..ea715ff5abc 100644 --- a/sys/sys/signalvar.h +++ b/sys/sys/signalvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: signalvar.h,v 1.45 2020/11/08 20:37:24 mpi Exp $ */ +/* $OpenBSD: signalvar.h,v 1.46 2021/03/04 09:02:38 mpi Exp $ */ /* $NetBSD: signalvar.h,v 1.17 1996/04/22 01:23:31 christos Exp $ */ /* @@ -71,17 +71,6 @@ struct sigacts { #define SIGPENDING(p) \ (((p)->p_siglist | (p)->p_p->ps_siglist) & ~(p)->p_sigmask) -/* - * Determine signal that should be delivered to process p, the current - * process, 0 if none. If there is a pending stop signal with default - * action, the process stops in issignal(). - */ -#define CURSIG(p) \ - ((((p)->p_siglist | (p)->p_p->ps_siglist) == 0 || \ - (((p)->p_p->ps_flags & PS_TRACED) == 0 && \ - SIGPENDING(p) == 0)) ? \ - 0 : issignal(p)) - /* * Clear a pending signal from a process. */ @@ -116,7 +105,7 @@ struct sigio_ref; */ int coredump(struct proc *p); void execsigs(struct proc *p); -int issignal(struct proc *p); +int cursig(struct proc *p); void pgsigio(struct sigio_ref *sir, int sig, int checkctty); void pgsignal(struct pgrp *pgrp, int sig, int checkctty); void psignal(struct proc *p, int sig); diff --git a/sys/ufs/mfs/mfs_vfsops.c b/sys/ufs/mfs/mfs_vfsops.c index 340e3fae531..dca5fe39285 100644 --- a/sys/ufs/mfs/mfs_vfsops.c +++ b/sys/ufs/mfs/mfs_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfs_vfsops.c,v 1.59 2020/02/18 12:13:40 mpi Exp $ */ +/* $OpenBSD: mfs_vfsops.c,v 1.60 2021/03/04 09:02:38 mpi Exp $ */ /* $NetBSD: mfs_vfsops.c,v 1.10 1996/02/09 22:31:28 christos Exp $ */ /* @@ -188,7 +188,7 @@ mfs_start(struct mount *mp, int flags, struct proc *p) * EINTR/ERESTART. */ if (sleepreturn != 0) { - sig = CURSIG(p); + sig = cursig(p); if (vfs_busy(mp, VB_WRITE|VB_NOWAIT) || dounmount(mp, (sig == SIGKILL) ? MNT_FORCE : 0, p)) CLRSIG(p, sig); -- 2.20.1