-/* $OpenBSD: kern_exec.c,v 1.250 2023/07/10 03:31:57 guenther Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.251 2023/09/29 12:47:34 claudio Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
}
/* get other threads to stop */
- if ((error = single_thread_set(p, SINGLE_UNWIND, 1)))
+ if ((error = single_thread_set(p, SINGLE_UNWIND | SINGLE_DEEP)))
return (error);
/*
* we're committed: any further errors will kill the process, so
* kill the other threads now.
*/
- single_thread_set(p, SINGLE_EXIT, 1);
+ single_thread_set(p, SINGLE_EXIT);
/*
* Prepare vmspace for remapping. Note that uvmspace_exec can replace
-/* $OpenBSD: kern_exit.c,v 1.216 2023/09/21 13:49:25 claudio Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.217 2023/09/29 12:47:34 claudio Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
} else {
/* nope, multi-threaded */
if (flags == EXIT_NORMAL)
- single_thread_set(p, SINGLE_EXIT, 1);
+ single_thread_set(p, SINGLE_EXIT);
else if (flags == EXIT_THREAD)
single_thread_check(p, 0);
}
-/* $OpenBSD: kern_pledge.c,v 1.308 2023/09/19 10:43:33 claudio Exp $ */
+/* $OpenBSD: kern_pledge.c,v 1.309 2023/09/29 12:47:34 claudio Exp $ */
/*
* Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
p->p_p->ps_comm, p->p_p->ps_pid, codes, p->p_pledge_syscall);
p->p_p->ps_acflag |= APLEDGE;
- /* Stop threads immediately, because this process is suspect */
+ /* Try to stop threads immediately, because this process is suspect */
if (P_HASSIBLING(p))
- single_thread_set(p, SINGLE_UNWIND, 1);
+ single_thread_set(p, SINGLE_UNWIND | SINGLE_DEEP);
/* Send uncatchable SIGABRT for coredump */
sigabort(p);
-/* $OpenBSD: kern_sig.c,v 1.318 2023/09/19 10:43:33 claudio Exp $ */
+/* $OpenBSD: kern_sig.c,v 1.319 2023/09/29 12:47:34 claudio Exp $ */
/* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */
/*
signum != SIGKILL && (p->p_sigmask & mask) != 0) {
int s;
- single_thread_set(p, SINGLE_SUSPEND, 0);
+ single_thread_set(p, SINGLE_SUSPEND | SINGLE_NOWAIT);
pr->ps_xsig = signum;
SCHED_LOCK(s);
*/
if (((pr->ps_flags & (PS_TRACED | PS_PPWAIT)) == PS_TRACED) &&
signum != SIGKILL) {
- single_thread_set(p, SINGLE_SUSPEND, 0);
+ single_thread_set(p, SINGLE_SUSPEND | SINGLE_NOWAIT);
pr->ps_xsig = signum;
SCHED_LOCK(s);
/* if there are other threads, pause them */
if (P_HASSIBLING(p))
- single_thread_set(p, SINGLE_UNWIND, 1);
+ single_thread_set(p, SINGLE_UNWIND);
if (coredump(p) == 0)
signum |= WCOREFLAG;
* - SINGLE_EXIT: unwind to kernel boundary and exit
*/
int
-single_thread_set(struct proc *p, enum single_thread_mode mode, int wait)
+single_thread_set(struct proc *p, int flags)
{
struct process *pr = p->p_p;
struct proc *q;
- int error, s;
+ int error, s, mode = flags & SINGLE_MASK;
KASSERT(curproc == p);
SCHED_LOCK(s);
- error = single_thread_check_locked(p, (mode == SINGLE_UNWIND), s);
+ error = single_thread_check_locked(p, flags & SINGLE_DEEP, s);
if (error) {
SCHED_UNLOCK(s);
return error;
}
SCHED_UNLOCK(s);
- if (wait)
+ if ((flags & SINGLE_NOWAIT) == 0)
single_thread_wait(pr, 1);
return 0;
-/* $OpenBSD: proc.h,v 1.351 2023/09/13 14:25:49 claudio Exp $ */
+/* $OpenBSD: proc.h,v 1.352 2023/09/29 12:47:34 claudio Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
dorefreshcreds(pr, p);
}
-enum single_thread_mode {
- SINGLE_SUSPEND, /* other threads to stop wherever they are */
- SINGLE_UNWIND, /* other threads to unwind and stop */
- SINGLE_EXIT /* other threads to unwind and then exit */
-};
-int single_thread_set(struct proc *, enum single_thread_mode, int);
+#define SINGLE_SUSPEND 0x01 /* other threads to stop wherever they are */
+#define SINGLE_UNWIND 0x02 /* other threads to unwind and stop */
+#define SINGLE_EXIT 0x03 /* other threads to unwind and then exit */
+#define SINGLE_MASK 0x0f
+/* extra flags for single_thread_set */
+#define SINGLE_DEEP 0x10 /* call is in deep */
+#define SINGLE_NOWAIT 0x20 /* do not wait for other threads to stop */
+
+int single_thread_set(struct proc *, int);
int single_thread_wait(struct process *, int);
void single_thread_clear(struct proc *, int);
int single_thread_check(struct proc *, int);