shithub: riscv

Download patch

ref: 3d3a29cd847f4146584f35e0e9dbabca8b1bec56
parent: e4db040bcf827f9e2493efc5ded4e7ba091d51a7
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Jul 15 03:54:22 EDT 2014

devproc: fix syscalltrace error handling, conistent use of nil for pointers

--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -171,7 +171,7 @@
 {
 	Tos *tos;
 
-	if(up == 0 || up->state != Running)
+	if(up == nil || up->state != Running)
 		return;
 
 	/* user profiling clock */
@@ -688,7 +688,7 @@
 
 	c = (Chan *)x;
 	p = proctab(SLOT(c->qid));
-	return p->pid != PID(c->qid) || p->waitq != 0;
+	return p->pid != PID(c->qid) || p->waitq != nil;
 }
 
 /*
@@ -764,11 +764,18 @@
 		return n;
 	case Qsyscall:
 		eqlock(&p->debug);
-		if(p->syscalltrace)
+		if(waserror()){
+			qunlock(&p->debug);
+			nexterror();
+		}
+		if(p->pid != PID(c->qid))
+			error(Eprocdied);
+		if(p->syscalltrace != nil)
 			n = readstr(offset, a, n, p->syscalltrace);
 		else
 			n = 0;
 		qunlock(&p->debug);
+		poperror();
 		return n;
 
 	case Qmem:
@@ -803,8 +810,8 @@
 		if(s == nil || s->profile == nil)
 			error("profile is off");
 		i = (s->top-s->base)>>LRESPROF;
-		i *= sizeof(*s->profile);
-		if(offset >= i)
+		i *= sizeof(s->profile[0]);
+		if(i < 0 || offset >= i)
 			return 0;
 		if(offset+n > i)
 			n = i - offset;
@@ -863,7 +870,7 @@
 		rptr = (uchar*)&p->fpsave;
 		rsize = sizeof(FPsave);
 	regread:
-		if(rptr == 0)
+		if(rptr == nil)
 			error(Enoreg);
 		if(offset >= rsize)
 			return 0;
@@ -879,7 +886,7 @@
 			n = STATSIZE - offset;
 
 		sps = p->psstate;
-		if(sps == 0)
+		if(sps == nil)
 			sps = statename[p->state];
 
 		memset(statbuf, ' ', sizeof statbuf);
@@ -906,7 +913,7 @@
 		j = 0;
 		for(i = 0; i < NSEG; i++) {
 			sg = p->seg[i];
-			if(sg == 0)
+			if(sg == nil)
 				continue;
 			j += sprint(statbuf+j, "%-6s %c%c %8p %8p %4ld\n",
 				sname[sg->type&SG_TYPE],
@@ -933,7 +940,7 @@
 		}
 
 		lock(&p->exl);
-		while(p->waitq == 0 && p->pid == PID(c->qid)) {
+		while(p->waitq == nil && p->pid == PID(c->qid)) {
 			if(up == p && p->nchild == 0) {
 				unlock(&p->exl);
 				error(Enochild);
@@ -975,7 +982,7 @@
 			return 0;
 		}
 		mntscan(mw, p);
-		if(mw->mh == 0){
+		if(mw->mh == nil){
 			mw->cddone = 1;
 			i = snprint(a, n, "cd %s\n", p->dot->path->s);
 			qunlock(&p->debug);
@@ -1023,13 +1030,13 @@
 	bestmid = ~0;
 
 	last = 0;
-	if(mw->mh)
+	if(mw->mh != nil)
 		last = mw->cm->mountid;
 
 	for(i = 0; i < MNTHASH; i++) {
-		for(f = pg->mnthash[i]; f; f = f->hash) {
-			for(t = f->mount; t; t = t->next) {
-				if(mw->mh == 0 ||
+		for(f = pg->mnthash[i]; f != nil; f = f->hash) {
+			for(t = f->mount; t != nil; t = t->next) {
+				if(mw->mh == nil ||
 				  (t->mountid > last && t->mountid < bestmid)) {
 					mw->cm = t;
 					mw->mh = f;
@@ -1040,7 +1047,7 @@
 		}
 	}
 	if(nxt == 0)
-		mw->mh = 0;
+		mw->mh = nil;
 
 	runlock(&pg->ns);
 }
@@ -1106,7 +1113,7 @@
 			n = 0;
 		else if(offset+n > sizeof(Ureg))
 			n = sizeof(Ureg) - offset;
-		if(p->dbgreg == 0)
+		if(p->dbgreg == nil)
 			error(Enoreg);
 		setregisters(p->dbgreg, (char*)(p->dbgreg)+offset, va, n);
 		break;
@@ -1218,7 +1225,7 @@
 	if(tc == nil)
 		error(Eprocdied);
 
-	if(incref(tc) == 1 || (tc->flag&COPEN) == 0 || tc->mode!=OREAD) {
+	if(incref(tc) == 1 || (tc->flag&COPEN) == 0 || tc->mode != OREAD) {
 		cclose(tc);
 		error(Eprocdied);
 	}
@@ -1239,7 +1246,7 @@
 {
 	int pid;
 
-	if(p->pdbg)
+	if(p->pdbg != nil)
 		error(Einuse);
 	if(procstopped(p) || p->state == Broken)
 		return;
@@ -1252,7 +1259,7 @@
 	qunlock(&p->debug);
 	up->psstate = "Stopwait";
 	if(waserror()) {
-		p->pdbg = 0;
+		p->pdbg = nil;
 		qlock(&p->debug);
 		nexterror();
 	}
@@ -1398,7 +1405,7 @@
 		break;
 	case CMprofile:
 		s = p->seg[TSEG];
-		if(s == 0 || (s->type&SG_TYPE) != SG_TEXT)
+		if(s == nil || (s->type&SG_TYPE) != SG_TEXT)
 			error(Ebadctl);
 		if(s->profile != nil)
 			free(s->profile);
@@ -1492,7 +1499,7 @@
 		p->edf->flags |= Sendnotes;
 		break;
 	case CMadmit:
-		if(p->edf == 0)
+		if(p->edf == nil)
 			error("edf params");
 		if(e = edfadmit(p))
 			error(e);
@@ -1503,12 +1510,12 @@
 		p->edf->flags |= Extratime;
 		break;
 	case CMexpel:
-		if(p->edf)
+		if(p->edf != nil)
 			edfstop(p);
 		break;
 	case CMevent:
 		pt = proctrace;
-		if(up->trace && pt)
+		if(up->trace && pt != nil)
 			pt(up, SUser, 0);
 		break;
 	}
@@ -1520,8 +1527,7 @@
 int
 procstopped(void *a)
 {
-	Proc *p = a;
-	return p->state == Stopped;
+	return ((Proc*)a)->state == Stopped;
 }
 
 ulong