From c4fac75773b766dca329165c9cb4096ec71e1038 Mon Sep 17 00:00:00 2001 From: claudio Date: Mon, 29 Jul 2024 09:49:49 +0000 Subject: [PATCH] Replace per thread P_CONTINUED with per process PS_CONTINUED flag 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 | 7 ++++--- sys/kern/kern_sig.c | 6 +++--- sys/sys/proc.h | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 43ef7a37fd9..4882de63652 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -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) { diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index a0d73ccaa95..dd54c552edc 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -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(); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 5e2960f8df7..8843c792684 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -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 -- 2.20.1