From 0ebabc93a454467be57821c02ac5182e1bb34699 Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Sat, 2 Dec 2000 01:32:51 +0000 Subject: [PATCH] Protect p_stat with sched_lock. --- sys/kern/sys_process.c | 16 +++++++++++++--- sys/kern/tty.c | 12 ++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 533ba71f51d2..c9abad45c604 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -280,8 +280,12 @@ ptrace(curp, uap) return EBUSY; /* not currently stopped */ - if (p->p_stat != SSTOP || (p->p_flag & P_WAITED) == 0) + mtx_enter(&sched_lock, MTX_SPIN); + if (p->p_stat != SSTOP || (p->p_flag & P_WAITED) == 0) { + mtx_exit(&sched_lock, MTX_SPIN); return EBUSY; + } + mtx_exit(&sched_lock, MTX_SPIN); /* OK */ break; @@ -363,11 +367,17 @@ ptrace(curp, uap) sendsig: /* deliver or queue signal */ s = splhigh(); + mtx_enter(&sched_lock, MTX_SPIN); if (p->p_stat == SSTOP) { p->p_xstat = uap->data; setrunnable(p); - } else if (uap->data) { - psignal(p, uap->data); + mtx_exit(&sched_lock, MTX_SPIN); + } else { + mtx_exit(&sched_lock, MTX_SPIN); + if (uap->data) { + mtx_assert(&Giant, MA_OWNED); + psignal(p, uap->data); + } } splx(s); return 0; diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 1117708cb982..ce11ea52017c 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -2254,6 +2254,7 @@ ttyinfo(tp) if (proc_compare(pick, p)) pick = p; + mtx_enter(&sched_lock, MTX_SPIN); ttyprintf(tp, " cmd: %s %d [%s] ", pick->p_comm, pick->p_pid, pick->p_stat == SRUN ? "running" : pick->p_wmesg ? pick->p_wmesg : "iowait"); @@ -2278,6 +2279,7 @@ ttyinfo(tp) pick->p_stat == SIDL || pick->p_stat == SWAIT || pick->p_stat == SZOMB ? 0 : (long)pgtok(vmspace_resident_count(pick->p_vmspace))); + mtx_exit(&sched_lock, MTX_SPIN); } tp->t_rocount = 0; /* so pending input will be retyped if BS */ } @@ -2308,15 +2310,20 @@ proc_compare(p1, p2) if (p1 == NULL) return (1); + + mtx_enter(&sched_lock, MTX_SPIN); /* * see if at least one of them is runnable */ switch (TESTAB(ISRUN(p1), ISRUN(p2))) { case ONLYA: + mtx_exit(&sched_lock, MTX_SPIN); return (0); case ONLYB: + mtx_exit(&sched_lock, MTX_SPIN); return (1); case BOTH: + mtx_exit(&sched_lock, MTX_SPIN); /* * tie - favor one with highest recent cpu utilization */ @@ -2331,12 +2338,17 @@ proc_compare(p1, p2) */ switch (TESTAB(p1->p_stat == SZOMB, p2->p_stat == SZOMB)) { case ONLYA: + mtx_exit(&sched_lock, MTX_SPIN); return (1); case ONLYB: + mtx_exit(&sched_lock, MTX_SPIN); return (0); case BOTH: + mtx_exit(&sched_lock, MTX_SPIN); return (p2->p_pid > p1->p_pid); /* tie - return highest pid */ } + mtx_exit(&sched_lock, MTX_SPIN); + /* * pick the one with the smallest sleep time */