Fix pgrp / proc locking issue.
MODIFY
sys/kern/proc.c
sys/kern/proc.c
@@ -211,8 +211,9 @@ static void proc_reparent(proc_t *old_parent, proc_t *new_parent) {
__noreturn void proc_exit(int exitstatus) {
proc_t *p = proc_self();
+ assert(mtx_owned(&p->p_lock));
+
/* Mark this process as dying, so others don't attempt to disturb it. */
- WITH_PROC_LOCK(p) {
p->p_state = PS_DYING;
/* Clean up process resources. */
@@ -231,7 +232,8 @@ __noreturn void proc_exit(int exitstatus) {
/* Record process statistics that will stay maintained in zombie state. */
p->p_exitstatus = exitstatus;
- }
+
+ proc_unlock(p);
WITH_MTX_LOCK (all_proc_mtx) {
/* Process orphans, but firstly find init process. */
@@ -301,9 +303,11 @@ int proc_sendsig(pid_t pid, signo_t sig) {
}
WITH_MTX_LOCK (&pgrp->pg_lock) {
- TAILQ_FOREACH (target, &pgrp->pg_members, p_pglist)
+ TAILQ_FOREACH (target, &pgrp->pg_members, p_pglist) {
+ proc_lock(target);
sig_kill(target, sig);
}
+ }
return 0;
}

MODIFY
sys/kern/signal.c
sys/kern/signal.c
@@ -148,7 +148,6 @@ void sig_post(signo_t sig) {
/* Terminate this thread as result of a signal. */
if (sa->sa_handler == SIG_DFL && sig_default(sig) == SA_KILL) {
- proc_unlock(p);
sig_exit(td, sig);
}

MODIFY
sys/kern/syscalls.c
sys/kern/syscalls.c
@@ -36,6 +36,7 @@ static int sys_sbrk(proc_t *p, sbrk_args_t *args, register_t *res) {
/* https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html */
static int sys_exit(proc_t *p, exit_args_t *args, register_t *res) {
klog("exit(%d)", args->rval);
+ proc_lock(p);
proc_exit(MAKE_STATUS_EXIT(args->rval));
__unreachable();
}

Fix pgrp / proc locking issue.