Replace per thread P_CONTINUED with per process PS_CONTINUED flag
authorclaudio <claudio@openbsd.org>
Mon, 29 Jul 2024 09:49:49 +0000 (09:49 +0000)
committerclaudio <claudio@openbsd.org>
Mon, 29 Jul 2024 09:49:49 +0000 (09:49 +0000)
dowait6() can only look at per process state so switch this over.
Right now SIGCONT handling in ptsignal is recursive and not quite
right but this is a step in the right direction. It fixes dowait6()
handling for multithreaded processes where the main thread exited.

OK mpi@

sys/kern/kern_exit.c
sys/kern/kern_sig.c
sys/sys/proc.h

index 43ef7a3..4882de6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_exit.c,v 1.227 2024/07/24 15:30:17 claudio Exp $ */
+/*     $OpenBSD: kern_exit.c,v 1.228 2024/07/29 09:49:49 claudio Exp $ */
 /*     $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $  */
 
 /*
@@ -597,9 +597,10 @@ loop:
                                memset(rusage, 0, sizeof(*rusage));
                        return (0);
                }
-               if ((options & WCONTINUED) && (p->p_flag & P_CONTINUED)) {
+               if ((options & WCONTINUED) && (pr->ps_flags & PS_CONTINUED)) {
                        if ((options & WNOWAIT) == 0)
-                               atomic_clearbits_int(&p->p_flag, P_CONTINUED);
+                               atomic_clearbits_int(&pr->ps_flags,
+                                   PS_CONTINUED);
 
                        *retval = pr->ps_pid;
                        if (info != NULL) {
index a0d73cc..dd54c55 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_sig.c,v 1.334 2024/07/24 15:31:08 claudio Exp $  */
+/*     $OpenBSD: kern_sig.c,v 1.335 2024/07/29 09:49:49 claudio Exp $  */
 /*     $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $   */
 
 /*
@@ -1097,7 +1097,7 @@ ptsignal(struct proc *p, int signum, enum signal_type type)
                         * an event, then it goes back to run state.
                         * Otherwise, process goes back to sleep state.
                         */
-                       atomic_setbits_int(&p->p_flag, P_CONTINUED);
+                       atomic_setbits_int(&pr->ps_flags, PS_CONTINUED);
                        atomic_clearbits_int(&p->p_flag, P_SUSPSIG);
                        wakeparent = 1;
                        if (action == SIG_DFL)
@@ -1260,7 +1260,7 @@ out:
        }
        if (prop & SA_STOP) {
                atomic_clearbits_int(siglist, CONTSIGMASK);
-               atomic_clearbits_int(&p->p_flag, P_CONTINUED);
+               atomic_clearbits_int(&pr->ps_flags, PS_CONTINUED);
        }
 
        SCHED_UNLOCK();
index 5e2960f..8843c79 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: proc.h,v 1.365 2024/07/22 09:43:47 claudio Exp $      */
+/*     $OpenBSD: proc.h,v 1.366 2024/07/29 09:49:49 claudio Exp $      */
 /*     $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $       */
 
 /*-
@@ -301,6 +301,7 @@ struct process {
 #define        PS_ITIMER       0x04000000      /* Virtual interval timers running */
 #define        PS_PIN          0x08000000      /* ld.so or static syscall pin */
 #define        PS_LIBCPIN      0x10000000      /* libc.so syscall pin */
+#define        PS_CONTINUED    0x20000000      /* Continued proc not yet waited for */
 
 #define        PS_BITS \
     ("\20" "\01CONTROLT" "\02EXEC" "\03INEXEC" "\04EXITING" "\05SUGID" \
@@ -309,7 +310,7 @@ struct process {
      "\017NOZOMBIE" "\020STOPPED" "\021SYSTEM" "\022EMBRYO" "\023ZOMBIE" \
      "\024NOBROADCASTKILL" "\025PLEDGE" "\026WXNEEDED" "\027EXECPLEDGE" \
      "\030ORPHAN" "\031CHROOT" "\032NOBTCFI" "\033ITIMER" "\034PIN" \
-     "\035LIBCPIN")
+     "\035LIBCPIN" "\036CONTINUED")
 
 struct kcov_dev;
 struct lock_list_entry;
@@ -436,7 +437,6 @@ struct proc {
 #define        P_WEXIT         0x00002000      /* Working on exiting. */
 #define        P_OWEUPC        0x00008000      /* Owe proc an addupc() at next ast. */
 #define        P_SUSPSINGLE    0x00080000      /* Need to stop for single threading. */
-#define P_CONTINUED    0x00800000      /* Proc has continued from a stopped state. */
 #define        P_THREAD        0x04000000      /* Only a thread, not a real process */
 #define        P_SUSPSIG       0x08000000      /* Stopped from signal. */
 #define P_CPUPEG       0x40000000      /* Do not move to another cpu. */
@@ -444,7 +444,7 @@ struct proc {
 #define        P_BITS \
     ("\20" "\01INKTR" "\02PROFPEND" "\03ALRMPEND" "\04SIGSUSPEND" \
      "\05CANTSLEEP" "\06WSLEEP" "\010SINTR" "\012SYSTEM" "\013TIMEOUT" \
-     "\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" "\030CONTINUED" "\033THREAD" \
+     "\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" "\033THREAD" \
      "\034SUSPSIG" "\037CPUPEG")
 
 #define        THREAD_PID_OFFSET       100000