summaryrefslogtreecommitdiffstats
path: root/sys/kern/sys_process.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2001-03-07 03:06:18 +0000
committerjhb <jhb@FreeBSD.org>2001-03-07 03:06:18 +0000
commit53e75509c01f5f00c09d9252fc9c6bd3410e90bf (patch)
treed734c38f6ed5a9da29f0554268b90ab2d66b30bb /sys/kern/sys_process.c
parent0bc406044c15e508f4feb23bd7fae164add2fce0 (diff)
downloadFreeBSD-src-53e75509c01f5f00c09d9252fc9c6bd3410e90bf.zip
FreeBSD-src-53e75509c01f5f00c09d9252fc9c6bd3410e90bf.tar.gz
- Proc locking.
- Remove some unneeded spl()'s.
Diffstat (limited to 'sys/kern/sys_process.c')
-rw-r--r--sys/kern/sys_process.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index d53bf72..a0efa6f 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -208,7 +208,6 @@ ptrace(curp, uap)
struct uio uio;
int error = 0;
int write;
- int s;
write = 0;
if (uap->req == PT_TRACE_ME)
@@ -234,8 +233,12 @@ ptrace(curp, uap)
return EINVAL;
/* Already traced */
- if (p->p_flag & P_TRACED)
+ PROC_LOCK(p);
+ if (p->p_flag & P_TRACED) {
+ PROC_UNLOCK(p);
return EBUSY;
+ }
+ PROC_UNLOCK(p);
if ((error = p_can(curp, p, P_CAN_DEBUG, NULL)))
return error;
@@ -272,24 +275,27 @@ ptrace(curp, uap)
case PT_SETDBREGS:
#endif
/* not being traced... */
- if ((p->p_flag & P_TRACED) == 0)
+ PROC_LOCK(p);
+ if ((p->p_flag & P_TRACED) == 0) {
+ PROC_UNLOCK(p);
return EPERM;
+ }
/* not being traced by YOU */
- PROCTREE_LOCK(PT_SHARED);
if (p->p_pptr != curp) {
- PROCTREE_LOCK(PT_RELEASE);
+ PROC_UNLOCK(p);
return EBUSY;
}
- PROCTREE_LOCK(PT_RELEASE);
/* not currently stopped */
mtx_lock_spin(&sched_lock);
if (p->p_stat != SSTOP || (p->p_flag & P_WAITED) == 0) {
mtx_unlock_spin(&sched_lock);
+ PROC_UNLOCK(p);
return EBUSY;
}
mtx_unlock_spin(&sched_lock);
+ PROC_UNLOCK(p);
/* OK */
break;
@@ -314,19 +320,23 @@ ptrace(curp, uap)
switch (uap->req) {
case PT_TRACE_ME:
/* set my trace flag and "owner" so it can read/write me */
+ PROCTREE_LOCK(PT_EXCLUSIVE);
+ PROC_LOCK(p);
p->p_flag |= P_TRACED;
- PROCTREE_LOCK(PT_SHARED);
p->p_oppid = p->p_pptr->p_pid;
+ PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
return 0;
case PT_ATTACH:
/* security check done above */
- p->p_flag |= P_TRACED;
PROCTREE_LOCK(PT_EXCLUSIVE);
+ PROC_LOCK(p);
+ p->p_flag |= P_TRACED;
p->p_oppid = p->p_pptr->p_pid;
if (p->p_pptr != curp)
proc_reparent(p, curp);
+ PROC_UNLOCK(p);
PROCTREE_LOCK(PT_RELEASE);
uap->data = SIGSTOP;
goto sendsig; /* in PT_CONTINUE below */
@@ -363,20 +373,23 @@ ptrace(curp, uap)
struct proc *pp;
pp = pfind(p->p_oppid);
+ PROC_LOCK(p);
proc_reparent(p, pp ? pp : initproc);
- }
- PROCTREE_LOCK(PT_RELEASE);
-
+ } else
+ PROC_LOCK(p);
p->p_flag &= ~(P_TRACED | P_WAITED);
p->p_oppid = 0;
+ PROC_UNLOCK(p);
+ PROCTREE_LOCK(PT_RELEASE);
+
/* should we send SIGCHLD? */
}
sendsig:
/* deliver or queue signal */
- s = splhigh();
+ PROC_LOCK(p);
mtx_lock_spin(&sched_lock);
if (p->p_stat == SSTOP) {
p->p_xstat = uap->data;
@@ -384,12 +397,11 @@ ptrace(curp, uap)
mtx_unlock_spin(&sched_lock);
} else {
mtx_unlock_spin(&sched_lock);
- if (uap->data) {
- mtx_assert(&Giant, MA_OWNED);
+ if (uap->data)
psignal(p, uap->data);
- }
+
}
- splx(s);
+ PROC_UNLOCK(p);
return 0;
case PT_WRITE_I:
@@ -577,7 +589,7 @@ stopevent(p, event, val)
unsigned int val;
{
- mtx_assert(&p->p_mtx, MA_OWNED | MA_NOTRECURSED);
+ PROC_LOCK_ASSERT(p, MA_OWNED | MA_NOTRECURSED);
p->p_step = 1;
do {
OpenPOWER on IntegriCloud