shithub: riscv

Download patch

ref: 55d31f2cab0101dfbdeb2857e2fce2629080cf02
parent: df6b68092cf2806d7c517e15d2db57b0b19a9788
author: cinap_lenrek <[email protected]>
date: Fri Nov 22 17:29:31 EST 2013

pc kernel: kproc error and exit

catch the error() that can be thrown by sleep() and tsleep()
in kprocs.

add missing pexit() calls.

always set the freemem argument to pexit() from kproc otherwise
the process gets added to the broken list.

--- a/sys/src/9/pc/devpccard.c
+++ b/sys/src/9/pc/devpccard.c
@@ -449,10 +449,13 @@
 static void
 processevents(void *)
 {
-	while (1) {
-		int message;
-		Cardbus *cb;
+	int message;
+	Cardbus *cb;
 
+	while(waserror())
+		;
+
+	for(;;){
 		sleep(&revents, (int (*)(void *))eventoccured, nil);
 
 		cb = nil;
--- a/sys/src/9/pc/ether82543gc.c
+++ b/sys/src/9/pc/ether82543gc.c
@@ -1228,18 +1228,19 @@
 	Ctlr *ctlr;
 
 	edev = arg;
+	while(waserror())
+		;
 	for(;;){
 		tsleep(&up->sleep, return0, 0, 1000);
-
 		ctlr = edev->ctlr;
-		if(ctlr == nil){
-			print("%s: exiting\n", up->text);
-			pexit("disabled", 0);
-		}
+		if(ctlr == nil)
+			break;
 
 		gc82543checklink(ctlr);
 		gc82543replenish(ctlr);
 	}
+	print("%s: exiting\n", up->text);
+	pexit("disabled", 1);
 }
 
 static void
--- a/sys/src/9/pc/ether82557.c
+++ b/sys/src/9/pc/ether82557.c
@@ -348,6 +348,8 @@
 	static void txstart(Ether*);
 
 	ether = arg;
+	while(waserror())
+		;
 	for(;;){
 		tsleep(&up->sleep, return0, 0, 4000);
 
@@ -357,10 +359,8 @@
 		 * the future.
 		 */
 		ctlr = ether->ctlr;
-		if(ctlr == nil || ctlr->state == 0){
-			print("%s: exiting\n", up->text);
-			pexit("disabled", 0);
-		}
+		if(ctlr == nil || ctlr->state == 0)
+			break;
 
 		ilock(&ctlr->cblock);
 		if(ctlr->tick++){
@@ -369,6 +369,8 @@
 		}
 		iunlock(&ctlr->cblock);
 	}
+	print("%s: exiting\n", up->text);
+	pexit("disabled", 1);
 }
 
 static void
--- a/sys/src/9/pc/ether82563.c
+++ b/sys/src/9/pc/ether82563.c
@@ -853,6 +853,8 @@
 	i82563txinit(ctlr);
 
 	tdt = ctlr->tdt;
+	while(waserror())
+		;
 	for(;;){
 		n = NEXT(tdt, ctlr->ntd);
 		if(n == i82563cleanup(ctlr)){
@@ -986,6 +988,8 @@
 	}else
 		im = Rxt0|Rxo|Rxdmt0|Rxseq|Ack;
 
+	while(waserror())
+		;
 	for(;;){
 		i82563im(ctlr, im);
 		ctlr->rsleep++;
@@ -1163,9 +1167,13 @@
 	c = e->ctlr;
 
 	phyno = phyprobe(c, 3<<1);
-	if(phyno == ~0)
-		return;
+	if(phyno == ~0){
+		print("%s: no phy, exiting\n", up->text);
+		pexit("no phy", 1);
+	}
 
+	while(waserror())
+		;
 	for(;;){
 		phy = phyread(c, phyno, Phystat);
 		if(phy == ~0){
@@ -1203,11 +1211,16 @@
 	c = e->ctlr;
 
 	phyno = phyprobe(c, 3<<1);
-	if(phyno == ~0)
-		return;
+	if(phyno == ~0){
+		print("%s: no phy, exiting\n", up->text);
+		pexit("no phy", 1);
+	}
 
 	if(c->type == i82573 && (phy = phyread(c, phyno, Phyier)) != ~0)
 		phywrite(c, phyno, Phyier, phy | Lscie | Ancie | Spdie | Panie);
+
+	while(waserror())
+		;
 	for(;;){
 		phy = phyread(c, phyno, Physsr);
 		if(phy == ~0){
@@ -1263,6 +1276,8 @@
 
 	if(c->type == i82575 || c->type == i82576)
 		csr32w(c, Connsw, Enrgirq);
+	while(waserror())
+		;
 	for(;;){
 		phy = csr32r(c, Pcsstat);
 		e->link = phy & Linkok;
@@ -1290,6 +1305,8 @@
 	e = v;
 	c = e->ctlr;
 
+	while(waserror())
+		;
 	for(;;){
 		rx = csr32r(c, Rxcw);
 		tx = csr32r(c, Txcw);
--- a/sys/src/9/pc/ether82598.c
+++ b/sys/src/9/pc/ether82598.c
@@ -375,6 +375,8 @@
 
 	e = v;
 	c = e->ctlr;
+	while(waserror())
+		;
 	for (;;) {
 		r = c->reg[Links];
 		e->link = (r & Lnkup) != 0;
@@ -467,6 +469,8 @@
 
 	e = v;
 	c = e->ctlr;
+	while(waserror())
+		;
 	for (;;) {
 		sleep(&c->trendez, tim, c);	/* transmit kicks us */
 		c->tim = 0;
@@ -551,6 +555,8 @@
 	c = e->ctlr;
 	m = c->nrd - 1;
 	rdh = 0;
+	while(waserror())
+		;
 loop:
 	replenish(c, rdh);
 	im(c, Irx0);
--- a/sys/src/9/pc/etherigbe.c
+++ b/sys/src/9/pc/etherigbe.c
@@ -782,6 +782,8 @@
 
 	edev = arg;
 	ctlr = edev->ctlr;
+	while(waserror())
+		;
 	for(;;){
 		if(ctlr->mii == nil || ctlr->mii->curphy == nil)
 			continue;
@@ -1090,6 +1092,9 @@
 	r = csr32r(ctlr, Rctl);
 	r |= Ren;
 	csr32w(ctlr, Rctl, r);
+
+	while(waserror())
+		;
 
 	for(;;){
 		ctlr->rim = 0;
--- a/sys/src/9/pc/etheriwl.c
+++ b/sys/src/9/pc/etheriwl.c
@@ -1997,11 +1997,10 @@
 
 	edev = arg;
 	ctlr = edev->ctlr;
+	while(waserror())
+		;
 	for(;;){
-		while(waserror())
-			;
 		tsleep(&up->sleep, return0, 0, 4000);
-		poperror();
 
 		qlock(ctlr);
 		for(;;){
--- a/sys/src/9/pc/etherm10g.c
+++ b/sys/src/9/pc/etherm10g.c
@@ -1082,6 +1082,8 @@
 
 	e = v;
 	c = e->ctlr;
+	while(waserror())
+		;
 	for(;;){
 		replenish(&c->sm);
 		replenish(&c->bg);
@@ -1144,6 +1146,8 @@
 	e = v;
 	c = e->ctlr;
 	tx = &c->tx;
+	while(waserror())
+		;
 	for(;;){
  		sleep(&c->txrendez, txcansleep, c);
 		txcleanup(tx, gbit32(c->stats->txcnt));
--- a/sys/src/9/pc/ethervt6102.c
+++ b/sys/src/9/pc/ethervt6102.c
@@ -440,6 +440,8 @@
 
 	edev = arg;
 	ctlr = edev->ctlr;
+	while(waserror())
+		;
 	for(;;){
 		if(ctlr->mii == nil || ctlr->mii->curphy == nil)
 			break;
--- a/sys/src/9/pc/ethervt6105m.c
+++ b/sys/src/9/pc/ethervt6105m.c
@@ -547,6 +547,8 @@
 
 	edev = arg;
 	ctlr = edev->ctlr;
+	while(waserror())
+		;
 	for(;;){
 		if(ctlr->mii == nil || ctlr->mii->curphy == nil)
 			break;
--- a/sys/src/9/pc/etheryuk.c
+++ b/sys/src/9/pc/etheryuk.c
@@ -1243,6 +1243,8 @@
 
 	txinit(e);
 	linkup(c, Txen);
+	while(waserror())
+		;
 	for(;;){
 		if((b = qbread(e->oq, 100000)) == nil)
 			break;
@@ -1381,6 +1383,8 @@
 
 	rxinit(e);
 	linkup(c, Rxen);
+	while(waserror())
+		;
 	for(;;)
 		if(replenish(e, c) == 0){
 			starve(k);
@@ -1750,7 +1754,8 @@
 	e = v;
 	c = e->ctlr;
 	k = &c->iproc;
-
+	while(waserror())
+		;
 	for(;;){
 		starve(k);
 		cause = c->reg[Eisr];
--- a/sys/src/9/pc/pcrandom.c
+++ b/sys/src/9/pc/pcrandom.c
@@ -44,10 +44,11 @@
 	up->basepri = PriNormal;
 	up->priority = up->basepri;
 
+	while(waserror())
+		;
 	for(;;){
-		for(;;)
-			if(++rb.randomcount > 100000)
-				break;
+		if(++rb.randomcount <= 100000)
+			continue;
 		if(anyhigher())
 			sched();
 		if(!rbnotfull(0))
--- a/sys/src/9/pc/sdiahci.c
+++ b/sys/src/9/pc/sdiahci.c
@@ -1177,6 +1177,8 @@
 {
 	int i;
 
+	while(waserror())
+		;
 	for(;;){
 		tsleep(&up->sleep, return0, 0, Nms);
 		for(i = 0; i < niadrive; i++)
--- a/sys/src/9/pc/sdmv50xx.c
+++ b/sys/src/9/pc/sdmv50xx.c
@@ -1100,6 +1100,8 @@
 {
 	int i;
 
+	while(waserror())
+		;
 	for(;;){
 		tsleep(&up->sleep, return0, 0, Nms);
 		for(i = 0; i < nmvsatadrive; i++)
--- a/sys/src/9/pc/sdodin.c
+++ b/sys/src/9/pc/sdodin.c
@@ -2272,6 +2272,8 @@
 {
 	int i;
 
+	while(waserror())
+		;
 	for(;;){
 		tsleep(&up->sleep, return0, 0, Nms);
 		for(i = 0; i < nmsdrive; i++)
--- a/sys/src/9/pc/wavelan.c
+++ b/sys/src/9/pc/wavelan.c
@@ -682,6 +682,8 @@
 	Ctlr* ctlr = (Ctlr*)ether->ctlr;
 
 	ctlr->timerproc = up;
+	while(waserror())
+		;
 	for(;;){
 		tsleep(&up->sleep, return0, 0, MSperTick);
 		ctlr = (Ctlr*)ether->ctlr;
@@ -732,7 +734,7 @@
 		}
 		iunlock(ctlr);
 	}
-	pexit("terminated", 0);
+	pexit("terminated", 1);
 }
 
 void
--- a/sys/src/9/pc/wifi.c
+++ b/sys/src/9/pc/wifi.c
@@ -450,9 +450,14 @@
 
 	b = nil;
 	wifi = arg;
+	while(waserror())
+		;
 	for(;;){
-		if(b != nil)
+		if(b != nil){
 			freeb(b);
+			b = nil;
+			continue;
+		}
 		if((b = qbread(wifi->iq, 100000)) == nil)
 			break;
 		w = (Wifipkt*)b->rp;
@@ -526,7 +531,7 @@
 			break;
 		}
 	}
-	pexit("wifi in queue closed", 0);
+	pexit("wifi in queue closed", 1);
 }
 
 static void
@@ -584,9 +589,11 @@
 
 	wifi = arg;
 	ether = wifi->ether;
+	while(waserror())
+		;
 	while((b = qbread(ether->oq, 1000000)) != nil)
 		wifietheroq(wifi, b);
-	pexit("ether out queue closed", 0);
+	pexit("ether out queue closed", 1);
 }
 
 static void