sync code with last improvements from OpenBSD

This commit is contained in:
purplerain 2023-09-29 20:20:09 +00:00
parent f463301edc
commit 96ee847eba
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
36 changed files with 904 additions and 117 deletions

View file

@ -1,4 +1,4 @@
/* $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 $ */
/*-
@ -284,7 +284,7 @@ sys_execve(struct proc *p, void *v, register_t *retval)
}
/* 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);
/*
@ -444,7 +444,7 @@ sys_execve(struct proc *p, void *v, register_t *retval)
* 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

View file

@ -1,4 +1,4 @@
/* $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 $ */
/*
@ -131,7 +131,7 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
} 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);
}

View file

@ -1,4 +1,4 @@
/* $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>
@ -578,9 +578,9 @@ pledge_fail(struct proc *p, int error, uint64_t code)
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);

View file

@ -1,4 +1,4 @@
/* $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 $ */
/*
@ -840,7 +840,7 @@ trapsignal(struct proc *p, int signum, u_long trapno, int code,
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);
@ -1290,7 +1290,7 @@ cursig(struct proc *p, struct sigctx *sctx)
*/
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);
@ -1559,7 +1559,7 @@ sigexit(struct proc *p, int signum)
/* 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;
@ -2066,16 +2066,16 @@ single_thread_check(struct proc *p, int deep)
* - 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;
@ -2146,7 +2146,7 @@ single_thread_set(struct proc *p, enum single_thread_mode mode, int wait)
}
SCHED_UNLOCK(s);
if (wait)
if ((flags & SINGLE_NOWAIT) == 0)
single_thread_wait(pr, 1);
return 0;