Browse Source

Plan 9 from Bell Labs 2003-02-08

David du Colombier 21 years ago
parent
commit
c6cff189a5

+ 28 - 27
dist/replica/plan9.db

@@ -3267,7 +3267,7 @@ sys/include/httpd.h - 664 sys sys 1014929064 5726
 sys/include/ip.h - 664 sys sys 1015700847 2395
 sys/include/keyboard.h - 664 sys sys 1014929064 799
 sys/include/libc.h - 664 sys sys 1037035097 18624
-sys/include/libsec.h - 664 sys sys 1037572309 8657
+sys/include/libsec.h - 664 sys sys 1044638428 8817
 sys/include/mach.h - 664 sys sys 1032058231 8101
 sys/include/memdraw.h - 664 sys sys 1039752978 5616
 sys/include/memlayer.h - 664 sys sys 1014929065 1810
@@ -3281,7 +3281,7 @@ sys/include/realtime.h - 664 sys sys 1037669237 869
 sys/include/regexp.h - 664 sys sys 1014929066 1308
 sys/include/scribble.h - 664 sys sys 1014929066 679
 sys/include/stdio.h - 664 sys sys 1014929066 4145
-sys/include/thread.h - 664 sys sys 1044429947 3582
+sys/include/thread.h - 664 sys sys 1044626123 3496
 sys/include/venti.h - 664 sys sys 1036470166 6630
 sys/lib - 20000000775 sys sys 1018580948 0
 sys/lib/acid - 20000000775 sys sys 1016926088 0
@@ -5015,10 +5015,10 @@ sys/src/9/boot/testboot.c - 664 sys sys 1039763734 496
 sys/src/9/ip - 20000000775 sys sys 1015278450 0
 sys/src/9/ip/arp.c - 664 sys sys 1026847564 10547
 sys/src/9/ip/chandial.c - 664 sys sys 1022588098 2276
-sys/src/9/ip/devip.c - 664 sys sys 1026847564 23458
+sys/src/9/ip/devip.c - 664 sys sys 1044630546 24033
 sys/src/9/ip/eipconvtest.c - 664 sys sys 1022588098 3135
 sys/src/9/ip/esp.c - 664 sys sys 1026847565 17081
-sys/src/9/ip/ethermedium.c - 664 sys sys 1026847565 14847
+sys/src/9/ip/ethermedium.c - 664 sys sys 1044630549 15013
 sys/src/9/ip/gre.c - 664 sys sys 1026847565 4702
 sys/src/9/ip/icmp.c - 664 sys sys 1039098191 9443
 sys/src/9/ip/icmp6.c - 644 sys sys 1032053255 18087
@@ -5028,19 +5028,19 @@ sys/src/9/ip/inferno.c - 664 sys sys 1022588098 517
 sys/src/9/ip/ip.c - 664 sys sys 1039098191 15147
 sys/src/9/ip/ip.h - 664 sys sys 1039098190 15812
 sys/src/9/ip/ipaux.c - 664 sys sys 1022588098 12656
-sys/src/9/ip/ipifc.c - 664 sys sys 1026847567 37441
-sys/src/9/ip/ipmux.c - 664 sys sys 1026847567 15406
+sys/src/9/ip/ipifc.c - 664 sys sys 1044630553 37714
+sys/src/9/ip/ipmux.c - 664 sys sys 1044630555 15352
 sys/src/9/ip/iproute.c - 664 sys sys 1022588099 14260
-sys/src/9/ip/ipv6.c - 664 sys sys 1026847568 14363
+sys/src/9/ip/ipv6.c - 664 sys sys 1044630557 14365
 sys/src/9/ip/ipv6.h - 644 sys sys 1022588099 4304
 sys/src/9/ip/loopbackmedium.c - 664 sys sys 1026847568 1651
 sys/src/9/ip/netdevmedium.c - 664 sys sys 1022588099 2680
 sys/src/9/ip/netlog.c - 664 sys sys 1026847568 4003
 sys/src/9/ip/nullmedium.c - 664 sys sys 1022588099 491
-sys/src/9/ip/pktmedium.c - 664 sys sys 1022588099 1186
+sys/src/9/ip/pktmedium.c - 664 sys sys 1044630559 1357
 sys/src/9/ip/ptclbsum.c - 664 sys sys 1022588099 1243
 sys/src/9/ip/rudp.c - 664 sys sys 1026847569 21413
-sys/src/9/ip/tcp.c - 664 sys sys 1032053256 61590
+sys/src/9/ip/tcp.c - 664 sys sys 1044630563 61645
 sys/src/9/ip/tripmedium.c - 664 sys sys 1022588099 7141
 sys/src/9/ip/udp.c - 664 sys sys 1026847570 13046
 sys/src/9/mkfile - 664 sys sys 1017795039 191
@@ -5083,7 +5083,7 @@ sys/src/9/pc/audio.h - 664 sys sys 1015014513 343
 sys/src/9/pc/cga.c - 664 sys sys 1015014513 1843
 sys/src/9/pc/clock.c - 664 sys sys 1032052912 899
 sys/src/9/pc/dat.h - 664 sys sys 1032052913 6070
-sys/src/9/pc/devarch.c - 664 sys sys 1036812831 16158
+sys/src/9/pc/devarch.c - 664 sys sys 1044630528 16357
 sys/src/9/pc/devether.c - 664 sys sys 1042004805 10072
 sys/src/9/pc/devfloppy.c - 664 sys sys 1015014514 19930
 sys/src/9/pc/devi82365.c - 664 sys sys 1020284820 19987
@@ -5123,7 +5123,7 @@ sys/src/9/pc/etherwavelan.c - 664 sys sys 1026847642 3722
 sys/src/9/pc/floppy.h - 664 sys sys 1015014518 3925
 sys/src/9/pc/fns.h - 664 sys sys 1026847643 4216
 sys/src/9/pc/hcwAMC.h - 664 sys sys 1026860163 166004
-sys/src/9/pc/i8253.c - 664 sys sys 1032052919 6791
+sys/src/9/pc/i8253.c - 664 sys sys 1044630532 6880
 sys/src/9/pc/i8259.c - 664 sys sys 1015014519 4423
 sys/src/9/pc/init9.c - 664 sys sys 1040002518 94
 sys/src/9/pc/initcode.s - 664 sys sys 1015014519 282
@@ -5158,10 +5158,10 @@ sys/src/9/pc/screen.c - 664 sys sys 1039753497 7266
 sys/src/9/pc/screen.h - 664 sys sys 1039753497 3742
 sys/src/9/pc/sd53c8xx.c - 664 sys sys 1033134905 51568
 sys/src/9/pc/sd53c8xx.n - 664 sys sys 1032059019 12455
-sys/src/9/pc/sdata.c - 664 sys sys 1042497924 44703
+sys/src/9/pc/sdata.c - 664 sys sys 1044630537 45002
 sys/src/9/pc/sdmylex.c - 664 sys sys 1015014523 27750
 sys/src/9/pc/sdscsi.c - 664 sys sys 1015014523 7412
-sys/src/9/pc/trap.c - 664 sys sys 1040002517 19364
+sys/src/9/pc/trap.c - 664 sys sys 1044630544 19368
 sys/src/9/pc/uarti8250.c - 664 sys sys 1020369766 12671
 sys/src/9/pc/uartpci.c - 664 sys sys 1015014524 2709
 sys/src/9/pc/usb.h - 664 sys sys 1015014524 3505
@@ -5219,7 +5219,7 @@ sys/src/9/port/devnmouse.c - 664 sys sys 1036812999 3738
 sys/src/9/port/devpipe.c - 664 sys sys 1032640439 5825
 sys/src/9/port/devpnp.c - 664 sys sys 1019864265 13027
 sys/src/9/port/devproc.c - 664 sys sys 1036813000 23484
-sys/src/9/port/devrealtime.c - 664 sys sys 1037669299 15991
+sys/src/9/port/devrealtime.c - 664 sys sys 1044630510 15975
 sys/src/9/port/devroot.c - 664 sys sys 1042304978 3593
 sys/src/9/port/devsd.c - 664 sys sys 1026847547 28679
 sys/src/9/port/devsdp.c - 664 sys sys 1026847548 44841
@@ -5228,9 +5228,9 @@ sys/src/9/port/devsrv.c - 664 sys sys 1014931174 5146
 sys/src/9/port/devssl.c - 664 sys sys 1026847548 26502
 sys/src/9/port/devtinyfs.c - 664 sys sys 1015278339 15347
 sys/src/9/port/devtls.c - 664 sys sys 1018721201 43664
-sys/src/9/port/devuart.c - 664 sys sys 1036813001 11154
+sys/src/9/port/devuart.c - 664 sys sys 1044630513 11590
 sys/src/9/port/devwpsd.c - 664 sys sys 1018469561 28850
-sys/src/9/port/edf.c - 664 sys sys 1037669300 24710
+sys/src/9/port/edf.c - 664 sys sys 1044630516 24351
 sys/src/9/port/edf.h - 664 sys sys 1037669301 4398
 sys/src/9/port/error.h - 664 sys sys 1014931175 2583
 sys/src/9/port/fault.c - 664 sys sys 1032052807 6557
@@ -5253,8 +5253,8 @@ sys/src/9/port/nulledf.c - 664 sys sys 1037669300 821
 sys/src/9/port/page.c - 664 sys sys 1014931177 8086
 sys/src/9/port/parse.c - 664 sys sys 1014931177 2026
 sys/src/9/port/pgrp.c - 664 sys sys 1032052809 3925
-sys/src/9/port/portclock.c - 664 sys sys 1036813002 3919
-sys/src/9/port/portdat.h - 664 sys sys 1036813003 20954
+sys/src/9/port/portclock.c - 664 sys sys 1044630519 3919
+sys/src/9/port/portdat.h - 664 sys sys 1044630523 20955
 sys/src/9/port/portfns.h - 664 sys sys 1039753334 10472
 sys/src/9/port/portmkfile - 664 sys sys 1039753335 2372
 sys/src/9/port/print.c - 664 sys sys 1014931178 227
@@ -6387,20 +6387,20 @@ sys/src/cmd/acme/ecmd.c - 664 sys sys 1016833878 23321
 sys/src/cmd/acme/edit.c - 664 sys sys 1015701171 12055
 sys/src/cmd/acme/edit.h - 664 sys sys 969500816 2466
 sys/src/cmd/acme/elog.c - 664 sys sys 1041137125 6081
-sys/src/cmd/acme/exec.c - 664 sys sys 1021579991 26915
-sys/src/cmd/acme/file.c - 664 sys sys 1014926094 5718
-sys/src/cmd/acme/fns.h - 664 sys sys 1035591507 2829
+sys/src/cmd/acme/exec.c - 664 sys sys 1044626079 26945
+sys/src/cmd/acme/file.c - 664 sys sys 1044626079 5717
+sys/src/cmd/acme/fns.h - 664 sys sys 1044626080 2920
 sys/src/cmd/acme/fsys.c - 664 sys sys 1022512648 12727
 sys/src/cmd/acme/look.c - 664 sys sys 1041137125 14840
-sys/src/cmd/acme/mkfile - 664 sys sys 1035591506 566
+sys/src/cmd/acme/mkfile - 664 sys sys 1044626081 566
 sys/src/cmd/acme/regx.c - 664 sys sys 1014926094 16057
 sys/src/cmd/acme/rows.c - 664 sys sys 1016833877 14726
 sys/src/cmd/acme/scrl.c - 664 sys sys 1014926095 3072
 sys/src/cmd/acme/text.c - 664 sys sys 1019524601 24004
 sys/src/cmd/acme/time.c - 664 sys sys 1014926095 1783
-sys/src/cmd/acme/util.c - 664 sys sys 1039123179 5983
+sys/src/cmd/acme/util.c - 664 sys sys 1044626080 6433
 sys/src/cmd/acme/wind.c - 664 sys sys 1016833877 11063
-sys/src/cmd/acme/xfid.c - 664 sys sys 1023206853 19186
+sys/src/cmd/acme/xfid.c - 664 sys sys 1044626081 19191
 sys/src/cmd/ar.c - 664 sys sys 1014926693 23801
 sys/src/cmd/archfs.c - 664 sys sys 1014925694 3871
 sys/src/cmd/ascii.c - 664 sys sys 964457138 3989
@@ -9174,7 +9174,7 @@ sys/src/cmd/mk/var.c - 664 sys sys 944961025 539
 sys/src/cmd/mk/varsub.c - 664 sys sys 944961025 4438
 sys/src/cmd/mk/word.c - 664 sys sys 944961025 2595
 sys/src/cmd/mkdir.c - 664 sys sys 1014926614 422
-sys/src/cmd/mkfile - 664 sys sys 1038787188 2348
+sys/src/cmd/mkfile - 664 sys sys 1044621999 2354
 sys/src/cmd/mklib - 664 sys sys 1022112159 599
 sys/src/cmd/mkmany - 664 sys sys 1022112160 1196
 sys/src/cmd/mkone - 664 sys sys 1022112160 792
@@ -9927,8 +9927,8 @@ sys/src/cmd/tcs/kuten212.c - 664 sys sys 944961289 55407
 sys/src/cmd/tcs/kuten212.h - 664 sys sys 944961287 94
 sys/src/cmd/tcs/mkfile - 664 sys sys 1036724422 532
 sys/src/cmd/tcs/plan9.h - 664 sys sys 944961287 751
-sys/src/cmd/tcs/tcs.c - 664 sys sys 1036687544 51805
-sys/src/cmd/tcs/utf.c - 664 sys sys 944961288 9515
+sys/src/cmd/tcs/tcs.c - 664 sys sys 1044661975 51805
+sys/src/cmd/tcs/utf.c - 664 sys sys 1044661976 7951
 sys/src/cmd/tee.c - 664 sys sys 954970286 1062
 sys/src/cmd/telco - 20000000775 sys sys 1015701205 0
 sys/src/cmd/telco/mkfile - 664 sys sys 944961290 201
@@ -11593,6 +11593,7 @@ sys/src/libsec/port/reduce - 664 sys sys 984710524 306
 sys/src/libsec/port/rsaalloc.c - 664 sys sys 984710524 657
 sys/src/libsec/port/rsadecrypt.c - 664 sys sys 984710524 749
 sys/src/libsec/port/rsaencrypt.c - 664 sys sys 984710524 192
+sys/src/libsec/port/rsafill.c - 664 sys sys 1044638434 1104
 sys/src/libsec/port/rsagen.c - 664 sys sys 984710524 1451
 sys/src/libsec/port/rsaprivtopub.c - 664 sys sys 984710525 237
 sys/src/libsec/port/rsatest.c - 664 sys sys 984710525 1095

+ 29 - 0
dist/replica/plan9.log

@@ -17163,3 +17163,32 @@
 1044500463 0 c sys/src/cmd/history.c - 664 sys sys 1044498757 5157
 1044561782 0 c 386/bin/file - 775 sys sys 1044560286 117769
 1044561782 1 c sys/src/cmd/file.c - 664 sys sys 1044560289 20196
+1044622022 0 c sys/src/cmd/mkfile - 664 sys sys 1044621999 2354
+1044626570 0 c sys/include/thread.h - 664 sys sys 1044626123 3496
+1044626570 1 c sys/src/cmd/acme/exec.c - 664 sys sys 1044626079 26945
+1044626570 2 c sys/src/cmd/acme/file.c - 664 sys sys 1044626079 5717
+1044626570 3 c sys/src/cmd/acme/fns.h - 664 sys sys 1044626080 2920
+1044626570 4 c sys/src/cmd/acme/mkfile - 664 sys sys 1044626081 566
+1044626570 5 c sys/src/cmd/acme/util.c - 664 sys sys 1044626080 6433
+1044626570 6 c sys/src/cmd/acme/xfid.c - 664 sys sys 1044626081 19191
+1044631973 0 c sys/src/9/ip/devip.c - 664 sys sys 1044630546 24033
+1044631973 1 c sys/src/9/ip/ethermedium.c - 664 sys sys 1044630549 15013
+1044631973 2 c sys/src/9/ip/ipifc.c - 664 sys sys 1044630553 37714
+1044631973 3 c sys/src/9/ip/ipmux.c - 664 sys sys 1044630555 15352
+1044631973 4 c sys/src/9/ip/ipv6.c - 664 sys sys 1044630557 14365
+1044631973 5 c sys/src/9/ip/pktmedium.c - 664 sys sys 1044630559 1357
+1044631973 6 c sys/src/9/ip/tcp.c - 664 sys sys 1044630563 61645
+1044631973 7 c sys/src/9/pc/devarch.c - 664 sys sys 1044630528 16357
+1044631973 8 c sys/src/9/pc/i8253.c - 664 sys sys 1044630532 6880
+1044631973 9 c sys/src/9/pc/sdata.c - 664 sys sys 1044630537 45002
+1044631973 10 c sys/src/9/pc/trap.c - 664 sys sys 1044630544 19368
+1044631973 11 c sys/src/9/port/devrealtime.c - 664 sys sys 1044630510 15975
+1044631973 12 c sys/src/9/port/devuart.c - 664 sys sys 1044630513 11590
+1044631973 13 c sys/src/9/port/edf.c - 664 sys sys 1044630516 24351
+1044631973 14 c sys/src/9/port/portclock.c - 664 sys sys 1044630519 3919
+1044631973 15 c sys/src/9/port/portdat.h - 664 sys sys 1044630523 20955
+1044639183 0 a sys/src/libsec/port/rsafill.c - 664 sys sys 1044638434 1104
+9 1 a sys/src/libsec/port/rsafill.c - 664 sys sys 1044638434 1104
+1044660792 0 c sys/src/cmd/tcs/utf.c - 664 sys sys 1044660775 7929
+1044662471 0 c sys/src/cmd/tcs/tcs.c - 664 sys sys 1044661975 51805
+1044662471 1 c sys/src/cmd/tcs/utf.c - 664 sys sys 1044661976 7951

+ 3 - 0
sys/include/libsec.h

@@ -216,6 +216,7 @@ struct RSApriv
 };
 
 RSApriv*	rsagen(int nlen, int elen, int rounds);
+RSApriv*	rsafill(mpint *n, mpint *e, mpint *d, mpint *p, mpint *q);
 mpint*		rsaencrypt(RSApub *k, mpint *in, mpint *out);
 mpint*		rsadecrypt(RSApriv *k, mpint *in, mpint *out);
 RSApub*		rsapuballoc(void);
@@ -225,8 +226,10 @@ void		rsaprivfree(RSApriv*);
 RSApub*		rsaprivtopub(RSApriv*);
 RSApub*		X509toRSApub(uchar*, int, char*, int);
 RSApriv*	asn1toRSApriv(uchar*, int);
+void		asn1dump(uchar *der, int len);
 uchar*		decodepem(char *s, char *type, int *len);
 uchar*		X509gen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);
+char*		X509verify(uchar *cert, int ncert, RSApub *pk);
 
 /////////////////////////////////////////////////////////
 // elgamal

+ 0 - 3
sys/include/thread.h

@@ -3,9 +3,6 @@
 
 #pragma	varargck	argpos	chanprint	2
 
-typedef struct Proc	Proc;
-typedef struct Thread	Thread;
-typedef struct Tqueue	Tqueue;
 typedef struct Alt	Alt;
 typedef struct Channel	Channel;
 typedef struct Ref	Ref;

+ 25 - 1
sys/src/9/ip/devip.c

@@ -32,6 +32,7 @@ enum
 	Qlocal,
 	Qremote,
 	Qstatus,
+	Qsnoop,
 
 	Logtype=	5,
 	Masktype=	(1<<Logtype)-1,
@@ -84,7 +85,7 @@ ip3gen(Chan *c, int i, Dir *dp)
 		devdir(c, q, "err", qlen(cv->eq), cv->owner, cv->perm, dp);
 		return 1;
 	case Qlisten:
-		devdir(c, q, "listen", qlen(cv->eq), cv->owner, cv->perm, dp);
+		devdir(c, q, "listen", 0, cv->owner, cv->perm, dp);
 		return 1;
 	case Qlocal:
 		p = "local";
@@ -92,6 +93,11 @@ ip3gen(Chan *c, int i, Dir *dp)
 	case Qremote:
 		p = "remote";
 		break;
+	case Qsnoop:
+		if(strcmp(cv->p->name, "ipifc") != 0)
+			return -1;
+		devdir(c, q, "snoop", qlen(cv->sq), cv->owner, 0400, dp);
+		return 1;
 	case Qstatus:
 		p = "status";
 		break;
@@ -235,6 +241,7 @@ ipgen(Chan *c, char*, Dirtab*, int, int s, Dir *dp)
 	case Qlocal:
 	case Qremote:
 	case Qstatus:
+	case Qsnoop:
 		return ip3gen(c, TYPE(c->qid), dp);
 	}
 	return -1;
@@ -391,6 +398,15 @@ ipopen(Chan* c, int omode)
 		if(omode != OREAD)
 			error(Eperm);
 		break;
+	case Qsnoop:
+		if(omode != OREAD)
+			error(Eperm);
+		p = f->p[PROTO(c->qid)];
+		cv = p->conv[CONV(c->qid)];
+		if(strcmp(ATTACHER(c), cv->owner) != 0 && !iseve())
+			error(Eperm);
+		incref(&cv->snoopers);
+		break;
 	case Qclone:
 		p = f->p[PROTO(c->qid)];
 		qlock(p);
@@ -575,6 +591,11 @@ ipclose(Chan* c)
 	case Qerr:
 		if(c->flag & COPEN)
 			closeconv(f->p[PROTO(c->qid)]->conv[CONV(c->qid)]);
+		break;
+	case Qsnoop:
+		if(c->flag & COPEN)
+			decref(&f->p[PROTO(c->qid)]->conv[CONV(c->qid)]->snoopers);
+		break;
 	}
 	free(((IPaux*)c->aux)->owner);
 	free(c->aux);
@@ -663,6 +684,9 @@ ipread(Chan *ch, void *a, long n, vlong off)
 	case Qerr:
 		c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
 		return qread(c->eq, a, n);
+	case Qsnoop:
+		c = f->p[PROTO(ch->qid)]->conv[CONV(ch->qid)];
+		return qread(c->sq, a, n);
 	case Qstats:
 		x = f->p[PROTO(ch->qid)];
 		if(x->stats == nil)

+ 8 - 2
sys/src/9/ip/ethermedium.c

@@ -573,6 +573,7 @@ recvarp(Ipifc *ifc)
 	Block *ebp, *rbp;
 	Etherarp *e, *r;
 	uchar ip[IPaddrlen];
+	static uchar eprinted[4];
 	Etherrock *er = ifc->arg;
 
 	ebp = devtab[er->achan->type]->bread(er->achan, ifc->maxmtu, 0);
@@ -608,8 +609,13 @@ recvarp(Ipifc *ifc)
 		/* check for machine using my ip or ether address */
 		v4tov6(ip, e->spa);
 		if(iplocalonifc(ifc, ip) || ipproxyifc(er->f, ifc, ip)){
-			if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) != 0)
-				print("arpreq: 0x%E also has ip addr %V\n", e->sha, e->spa);
+			if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) != 0){
+				if (memcmp(eprinted, e->spa, sizeof(e->spa))){
+					/* print only once */
+					print("arpreq: 0x%E also has ip addr %V\n", e->sha, e->spa);
+					memmove(eprinted, e->spa, sizeof(e->spa));
+				}
+			}
 		} else {
 			if(memcmp(e->sha, ifc->mac, sizeof(e->sha)) == 0){
 				print("arpreq: %V also has ether addr %E\n", e->spa, e->sha);

+ 19 - 8
sys/src/9/ip/ipifc.c

@@ -128,18 +128,22 @@ ipifcbind(Conv *c, char **argv, int argc)
 		nexterror();
 	}
 
+	/* do medium specific binding */
 	(*m->bind)(ifc, argc, argv);
+
+	/* set the bound device name */
 	if(argc > 2)
 		strncpy(ifc->dev, argv[2], sizeof(ifc->dev));
 	else
 		sprint(ifc->dev, "%s%d", m->name, c->x);
 	ifc->dev[sizeof(ifc->dev)-1] = 0;
+
+	/* set up parameters */
 	ifc->m = m;
 	ifc->minmtu = ifc->m->minmtu;
 	ifc->maxmtu = ifc->m->maxmtu;
 	if(ifc->m->unbindonclose == 0)
 		ifc->conv->inuse++;
-
 	ifc->rp.mflag	= 0;		// default not managed
 	ifc->rp.oflag	= 0;
 	ifc->rp.maxraint	= 600000;	// millisecs
@@ -148,10 +152,16 @@ ipifcbind(Conv *c, char **argv, int argc)
 	ifc->rp.reachtime	= 0;
 	ifc->rp.rxmitra	= 0;
 	ifc->rp.ttl	= MAXTTL;
-	ifc->rp.routerlt	= 3*(ifc->rp.maxraint);	
+	ifc->rp.routerlt	= 3*(ifc->rp.maxraint);
 
+	/* any ancillary structures (like routes) no longer pertain */
 	ifc->ifcid++;
 
+	/* reopen all the queues closed by a previous unbind */
+	qreopen(c->rq);
+	qreopen(c->eq);
+	qreopen(c->sq);
+
 	wunlock(ifc);
 	poperror();
 
@@ -188,9 +198,10 @@ ipifcunbind(Ipifc *ifc)
 	ifc->arg = nil;
 	ifc->reassemble = 0;
 
-	/* hangup queues to stop queuing of packets */
-	qhangup(ifc->conv->rq, "unbind");
-	qhangup(ifc->conv->wq, "unbind");
+	/* close queues to stop queuing of packets */
+	qclose(ifc->conv->rq);
+	qclose(ifc->conv->wq);
+	qclose(ifc->conv->sq);
 
 	/* disassociate logical interfaces */
 	av[0] = "remove";
@@ -301,8 +312,7 @@ ipifckick(void *x)
 }
 
 /*
- *  we'll have to have a kick routine at
- *  some point to deal with these
+ *  called when a new ipifc structure is created
  */
 static void
 ipifccreate(Conv *c)
@@ -310,6 +320,7 @@ ipifccreate(Conv *c)
 	Ipifc *ifc;
 
 	c->rq = qopen(QMAX, 0, 0, 0);
+	c->sq = qopen(2*QMAX, 0, 0, 0);
 	c->wq = qopen(QMAX, Qkick, ipifckick, c);
 	ifc = (Ipifc*)c->ptcl;
 	ifc->conv = c;
@@ -568,7 +579,7 @@ ipifcrem(Ipifc *ifc, char **argv, int argc, int dolock)
 
 	/*
 	 *  find address on this interface and remove from chain.
-	 *  for pt to pt we actually specify the remote address at the
+	 *  for pt to pt we actually specify the remote address as the
 	 *  addresss to remove.
 	 */
 	l = &ifc->lifc;

+ 33 - 33
sys/src/9/ip/ipmux.c

@@ -36,12 +36,12 @@ Ip4hdr *ipoff = 0;
 
 struct Ip6hdr
 {
-  uchar vcf[4];  /* version, class label, and flow label */ 
-  uchar ploadlen[2];  /* payload length */
-  uchar proto; /* next header, i.e. proto */
-  uchar ttl;   /* hop limit, i.e. ttl */
-  uchar src[16]; /* IP source */
-  uchar dst[16]; /* IP destination */
+	uchar vcf[4];		/* version, class label, and flow label */ 
+	uchar ploadlen[2];	/* payload length */
+	uchar proto;		/* next header, i.e. proto */
+	uchar ttl;		/* hop limit, i.e. ttl */
+	uchar src[16];		/* IP source */
+	uchar dst[16];		/* IP destination */
 };
 
 
@@ -49,7 +49,7 @@ enum
 {
 	Tproto,
 	Tdata,
-  Tiph,
+	Tiph,
 	Tdst,
 	Tsrc,
 	Tifc,
@@ -69,7 +69,7 @@ char *ftname[] =
 {
 [Tproto]	"proto",
 [Tdata]		"data",
-[Tiph]	  "iph",
+[Tiph]	 	"iph",
 [Tdst]		"dst",
 [Tsrc]		"src",
 [Tifc]		"ifc",
@@ -82,16 +82,16 @@ struct Ipmux
 {
 	Ipmux	*yes;
 	Ipmux	*no;
-	uchar	type;		 /* type of field (Txxxx) */
-	uchar	ctype;   /* tupe of comparison (Cxxxx) */
-	uchar	len;		 /* length in bytes of item to compare */
-	uchar	n;		   /* number of items val points to */
-	short	off;		 /* offset of comparison */
-	short	eoff;		 /* end offset of comparison */
-  uchar skiphdr; /* should offset start after ip header */
+	uchar	type;		/* type of field(Txxxx) */
+	uchar	ctype;		/* tupe of comparison(Cxxxx) */
+	uchar	len;		/* length in bytes of item to compare */
+	uchar	n;		/* number of items val points to */
+	short	off;		/* offset of comparison */
+	short	eoff;		/* end offset of comparison */
+	uchar	skiphdr;	/* should offset start after ipheader */
 	uchar	*val;
 	uchar	*mask;
-	uchar	*e;		/* val + n*len */
+	uchar	*e;		/* val+n*len*/
 
 	int	ref;		/* so we can garbage collect */
 	Conv	*conv;
@@ -164,14 +164,14 @@ parseop(char **pp)
 		p += 5;
 	}
 	else if(strncmp(p, "data", 4) == 0 || strncmp(p, "iph", 3) == 0){
-    if(strncmp(p, "data", 4) == 0) {
-		  type = Tdata;
-      p += 4;
-    }
-    else {
-      type = Tiph;
-	    p += 3;
-    }
+		if(strncmp(p, "data", 4) == 0) {
+			type = Tdata;
+			p += 4;
+		}
+		else {
+			type = Tiph;
+			p += 3;
+		}
 		p = skipwhite(p);
 		if(*p != '[')
 			return nil;
@@ -206,10 +206,10 @@ parseop(char **pp)
 	f->mask = nil;
 	f->n = 1;
 	f->ref = 1;
-  if(type == Tdata)
-    f->skiphdr = 1;
-  else
-    f->skiphdr = 0;
+	if(type == Tdata)
+		f->skiphdr = 1;
+	else
+		f->skiphdr = 0;
 
 	return f;	
 }
@@ -274,7 +274,7 @@ parsemux(char *p)
 			v4parseip(f->mask, mask);
 			break;
 		case Tdata:
-    case Tiph:
+		case Tiph:
 			f->mask = smalloc(f->len);
 			parseval(f->mask, mask, f->len);
 			break;
@@ -303,7 +303,7 @@ parsemux(char *p)
 			break;
 		case Tproto:
 		case Tdata:
-    case Tiph:
+		case Tiph:
 			parseval(v, vals[n], f->len);
 			break;
 		}
@@ -360,7 +360,7 @@ ipmuxcmp(Ipmux *a, Ipmux *b)
 
 	/* compare offsets, call earlier ones more specific */
 	n = (a->off+((int)a->skiphdr)*(ulong)ipoff->data) - 
-      (b->off+((int)b->skiphdr)*(ulong)ipoff->data);
+		(b->off+((int)b->skiphdr)*(ulong)ipoff->data);
 	if(n != 0)
 		return n;
 
@@ -684,8 +684,8 @@ ipmuxiput(Proto *p, Ipifc *ifc, Block *bp)
 	Ip4hdr *ip;
 	Ip6hdr *ip6;
 
-  ip = (Ip4hdr*)bp->rp;
-  hl = (ip->vihl&0x0F)<<2;
+	ip = (Ip4hdr*)bp->rp;
+	hl = (ip->vihl&0x0F)<<2;
 
 	if(p->priv == nil)
 		goto nomatch;

+ 1 - 1
sys/src/9/ip/ipv6.c

@@ -181,7 +181,7 @@ ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos)
 
 	r = v6lookup(f, eh->dst);
 	if(r == nil){
-		print("no route for %I, src %I free\n", eh->dst, eh->src);
+//		print("no route for %I, src %I free\n", eh->dst, eh->src);
 		ip->stats[OutNoRoutes]++;
 		netlog(f, Logip, "no interface %I\n", eh->dst);
 		goto free;

+ 6 - 1
sys/src/9/ip/pktmedium.c

@@ -52,6 +52,8 @@ pktbwrite(Ipifc *ifc, Block *bp, int, uchar*)
 {
 	/* enqueue onto the conversation's rq */
 	bp = concatblock(bp);
+	if(ifc->conv->snoopers.ref > 0)
+		qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
 	qpass(ifc->conv->rq, bp);
 }
 
@@ -63,8 +65,11 @@ pktin(Fs *f, Ipifc *ifc, Block *bp)
 {
 	if(ifc->lifc == nil)
 		freeb(bp);
-	else
+	else {
+		if(ifc->conv->snoopers.ref > 0)
+			qpass(ifc->conv->sq, copyblock(bp, BLEN(bp)));
 		ipiput4(f, ifc, bp);
+	}
 }
 
 void

+ 4 - 2
sys/src/9/ip/tcp.c

@@ -28,7 +28,7 @@ enum
 	TcptimerON	= 1,
 	TcptimerDONE	= 2,
 	MAX_TIME 	= (1<<20),	/* Forever */
-	TCP_ACK		= 200,		/* Timed ack sequence in ms */
+	TCP_ACK		= 50,		/* Timed ack sequence in ms */
 
 	URG		= 0x20,		/* Data marked urgent */
 	ACK		= 0x10,		/* Acknowledge is valid */
@@ -213,6 +213,7 @@ struct Tcpctl
 		ulong	urg;		/* Urgent pointer */
 		ulong	lastacked;	/* Last ack sent */
 		int	blocked;
+		int	una;		/* unacked data segs */
 	} rcv;
 	ulong	iss;			/* Initial sequence number */
 	ushort	cwind;			/* Congestion window */
@@ -1353,7 +1354,7 @@ limbo(Conv *s, uchar *source, uchar *dest, Tcp *seg, int version)
 		if(ipcmp(lp->laddr, dest) != 0)
 			continue;
 
-		/* each new SYN restarts the retramsmits */
+		/* each new SYN restarts the retransmits */
 		lp->irs = seg->seq;
 		break;
 	}
@@ -2358,6 +2359,7 @@ tcpoutput(Conv *s)
 		tcprcvwin(s);
 
 		/* By default we will generate an ack */
+		tcb->rcv.una = 0;
 		seg.source = s->lport;
 		seg.dest = s->rport;
 		seg.flags = ACK;

+ 16 - 6
sys/src/9/pc/devarch.c

@@ -108,6 +108,9 @@ ioinit(void)
 
 	// a dummy entry at 2^16
 	ioalloc(0x10000, 1, 0, "dummy");
+	/*
+	 * Someone needs to explain why this was here...
+	 */
 	ioalloc(0x0fff, 1, 0, "dummy");	// i82557 is at 0x1000, the dummy
 					// entry is needed for swappable devs.
 
@@ -341,7 +344,7 @@ enum
 static long
 archread(Chan *c, void *a, long n, vlong offset)
 {
-	char buf[Linelen+1], *p;
+	char *buf, *p;
 	int port;
 	ushort *sp;
 	ulong *lp;
@@ -388,23 +391,30 @@ archread(Chan *c, void *a, long n, vlong offset)
 		break;
 	}
 
-	offset = offset/Linelen;
+	/* allocate a buffer to avoid page faults in the loop */
+	if((buf = malloc(n+1)) == nil)	/* +1 for the NUL */
+		error(Enomem);
+	p = buf;
 	n = n/Linelen;
-	p = a;
+	offset = offset/Linelen;
+
 	lock(&iomap);
 	for(m = iomap.m; n > 0 && m != nil; m = m->next){
 		if(offset-- > 0)
 			continue;
 		if(strcmp(m->tag, "dummy") == 0)
 			break;
-		sprint(buf, "%8lux %8lux %-12.12s\n", m->start, m->end-1, m->tag);
-		memmove(p, buf, Linelen);
+		snprint(p, Linelen+1, "%8lux %8lux %-12.12s\n", m->start, m->end-1, m->tag);
 		p += Linelen;
 		n--;
 	}
 	unlock(&iomap);
 
-	return p - (char*)a;
+	n = p - buf;
+	memmove(a, buf, n);
+	free(buf);
+
+	return n;
 }
 
 static long

+ 8 - 4
sys/src/9/pc/i8253.c

@@ -77,13 +77,14 @@ i8253init(void)
 	ioalloc(T0cntr, 4, 0, "i8253");
 	ioalloc(T2ctl, 1, 0, "i8253.cntr2ctl");
 
+	i8253.period = Freq/HZ;
+
 	/*
 	 *  enable a 1/HZ interrupt for providing scheduling interrupts
 	 */
 	outb(Tmode, Load0|Square);
 	outb(T0cntr, (Freq/HZ));	/* low byte */
 	outb(T0cntr, (Freq/HZ)>>8);	/* high byte */
-	i8253.period = Freq/HZ;
 
 	/*
 	 *  enable a longer period counter to use as a clock
@@ -91,7 +92,6 @@ i8253init(void)
 	outb(Tmode, Load2|Square);
 	outb(T2cntr, 0);		/* low byte */
 	outb(T2cntr, 0);		/* high byte */
-	i8253.period = Freq/HZ;
 	x = inb(T2ctl);
 	x |= T2gate;
 	outb(T2ctl, x);
@@ -188,10 +188,12 @@ guesscpuhz(int aalcycles)
 ulong i8253periodset;
 int i8253dotimerset = 1;
 
+ulong phist[128];
+
 void
 i8253timerset(uvlong next)
 {
-	ulong period;
+	long period;
 	ulong want;
 	ulong now;
 
@@ -212,11 +214,13 @@ i8253timerset(uvlong next)
 
 	/* hysteresis */
 	if(i8253.period != period){
+memmove(&phist[0], &phist[1], sizeof(phist)-sizeof(ulong));
+phist[nelem(phist)-1] = period;
 		ilock(&i8253);
 		/* load new value */
 		outb(Tmode, Load0|Square);
 		outb(T0cntr, period);		/* low byte */
-		outb(T0cntr, period>>8);	/* high byte */
+		outb(T0cntr, period >> 8);		/* high byte */
 
 		/* remember period */
 		i8253.period = period;

+ 9 - 3
sys/src/9/pc/sdata.c

@@ -1287,7 +1287,8 @@ atagenioretry(Drive* drive)
 	if(drive->dmactl){
 		drive->dmactl = 0;
 		print("atagenioretry: disabling dma\n");
-	}else if(drive->rwmctl)
+	}
+	else if(drive->rwmctl)
 		drive->rwmctl = 0;
 	else
 		return atasetsense(drive, SDcheck, 4, 8, drive->error);
@@ -1715,10 +1716,15 @@ atapnp(void)
 		case (0x0571<<16)|0x1106:	/* VIA 82C686 */
 		case (0x0211<<16)|0x1166:	/* ServerWorks IB6566 */
 		case (0x1230<<16)|0x8086:	/* 82371FB (PIIX) */
-		case (0x248A<<16)|0x8086:	/* 82801BAM ICH2-M */
 		case (0x7010<<16)|0x8086:	/* 82371SB (PIIX3) */
 		case (0x7111<<16)|0x8086:	/* 82371[AE]B (PIIX4[E]) */
-		case (0x24CB<<16)|0x8086:	/* 945 ?? */
+		case (0x2411<<16)|0x8086:	/* 82801AA (ICH) */
+		case (0x2421<<16)|0x8086:	/* 82801AB (ICH0) */
+		case (0x244A<<16)|0x8086:	/* 82801BA (ICH2, Mobile) */
+		case (0x244B<<16)|0x8086:	/* 82801BA (ICH2, High-End) */
+		case (0x248A<<16)|0x8086:	/* 82801CA (ICH3, Mobile) */
+		case (0x248B<<16)|0x8086:	/* 82801CA (ICH3, High-End) */
+		case (0x24CB<<16)|0x8086:	/* 82801DB (ICH4, High-End) */
 			break;
 		}
 

+ 2 - 1
sys/src/9/pc/trap.c

@@ -265,8 +265,9 @@ intrtime(Mach*, int vno)
 		m->perf.inidle -= diff;
 
 	diff /= m->cpumhz;
-	if(diff >= Ntimevec)
+	if(diff >= Ntimevec){
 		diff = Ntimevec-1;
+	}
 	intrtimes[vno][diff]++;
 }
 

+ 3 - 3
sys/src/9/port/devrealtime.c

@@ -5,9 +5,9 @@
 #include "fns.h"
 #include "io.h"
 #include "ureg.h"
-#include "../port/error.h"
-#include	"realtime.h"
-#include	"../port/edf.h"
+#include "error.h"
+#include "realtime.h"
+#include "edf.h"
 
 #pragma	varargck	type	"T"		vlong
 

+ 18 - 1
sys/src/9/port/devuart.c

@@ -350,6 +350,8 @@ uartctl(Uart *p, char *cmd)
 		switch(*f[i]){
 		case 'B':
 		case 'b':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			if((*p->phys->baud)(p, n) < 0)
 				return -1;
 			break;
@@ -359,6 +361,8 @@ uartctl(Uart *p, char *cmd)
 			break;
 		case 'D':
 		case 'd':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			(*p->phys->dtr)(p, n);
 			break;
 		case 'E':
@@ -379,19 +383,27 @@ uartctl(Uart *p, char *cmd)
 			break;
 		case 'i':
 		case 'I':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			(*p->phys->fifo)(p, n);
 			break;
 		case 'K':
 		case 'k':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			(*p->phys->dobreak)(p, n);
 			break;
 		case 'L':
 		case 'l':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			if((*p->phys->bits)(p, n) < 0)
 				return -1;
 			break;
 		case 'm':
 		case 'M':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			(*p->phys->modemctl)(p, n);
 			break;
 		case 'n':
@@ -401,6 +413,8 @@ uartctl(Uart *p, char *cmd)
 			break;
 		case 'P':
 		case 'p':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			if((*p->phys->parity)(p, *(f[i]+1)) < 0)
 				return -1;
 			break;
@@ -413,10 +427,14 @@ uartctl(Uart *p, char *cmd)
 			break;
 		case 'R':
 		case 'r':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			(*p->phys->rts)(p, n);
 			break;
 		case 'S':
 		case 's':
+			if(p->enabled)
+				sleep(&p->r, uartdrained, p);
 			if((*p->phys->stop)(p, n) < 0)
 				return -1;
 			break;
@@ -477,7 +495,6 @@ uartwrite(Chan *c, void *buf, long n, vlong)
 		}
 
 		/* let output drain */
-		sleep(&p->r, uartdrained, p);
 		if(uartctl(p, cmd) < 0)
 			error(Ebadarg);
 

+ 12 - 26
sys/src/9/port/edf.c

@@ -213,8 +213,6 @@ edfreleasetimer(void)
 	if ((t = qwaitrelease.head) == nil)
 		return;
 	DPRINT("edfreleasetimer clock\n");
-	if (releasetimer[m->machno].when)
-		timerdel(&releasetimer[m->machno]);
 	releasetimer[m->machno].when = t->r;
 	if (releasetimer[m->machno].when <= now)
 		releasetimer[m->machno].when = now;
@@ -356,8 +354,6 @@ edfadmit(Task *t)
 		}
 		assert(t->runq.n > 0 || (up && up->task == t));
 		edfpush(t);
-		if (deadlinetimer[m->machno].when)
-			timerdel(&deadlinetimer[m->machno]);
 		deadlinetimer[m->machno].when = t->d;
 		timeradd(&deadlinetimer[m->machno]);
 	}else{
@@ -431,14 +427,11 @@ edfreleaseintr(Ureg*, Timer*)
 
 	DPRINT("%d edfreleaseintr\n", m->machno);
 
-	timerdel(&releasetimer[m->machno]);
-	releasetimer[m->machno].when = 0;
-
 	if(panicking || active.exiting)
 		return;
 
-	ilock(&edflock);
 	now = fastticks(nil);
+	ilock(&edflock);
 	while((t = qwaitrelease.head) && t->r <= now){
 		/* There's something waiting to be released and its time has come */
 		edfdequeue(&qwaitrelease);
@@ -451,7 +444,7 @@ edfreleaseintr(Ureg*, Timer*)
 }
 
 static void
-edfdeadlineintr(Ureg*, Timer *timer)
+edfdeadlineintr(Ureg*, Timer *)
 {
 	/* Task reached deadline */
 
@@ -464,20 +457,18 @@ edfdeadlineintr(Ureg*, Timer *timer)
 
 	DPRINT("%d edfdeadlineintr\n", m->machno);
 
-	if (timer)
-		timer->when = 0;
-
 	if(panicking || active.exiting)
 		return;
 
+	now = fastticks(nil);
 	ilock(&edflock);
 	// If up is not set, we're running inside the scheduler
 	// for non-real-time processes.
 	noted = 0;
 	if (up && isedf(up)) {
-		now = fastticks(nil);
-
 		t = up->task;
+
+		assert(t->state == EdfRunning);
 		assert(t->scheduled > 0);
 	
 		used = now - t->scheduled;
@@ -523,7 +514,7 @@ edfdeadlineintr(Ureg*, Timer *timer)
 	}
 	iunlock(&edflock);
 	if (noted)
-		postnote(up, 1, buf, NUser);
+		postnote(up, 0, buf, NUser);
 	sched();
 	splhi();
 }
@@ -738,6 +729,7 @@ edfrunproc(void)
 		nilcount++;
 		return nil;
 	}
+
 	/* Figure out if the current proc should be preempted*/
 	ilock(&edflock);
 	now = fastticks(nil);
@@ -773,7 +765,7 @@ edfrunproc(void)
 		/* released task is better than current */
 		DPRINT("%d edfrunproc: released\n", m->machno);
 		edfdequeue(&qreleased);
-		assert(nt->runq.n >= 1);
+		assert(nt->runq.n >= 1 || (up && up->task == nt));
 		edfpush(nt);
 		t = nt;
 		t->scheduled = now;
@@ -805,12 +797,9 @@ runt:
 		DPRINT("%d edftimer: %T too late\n", m->machno, ticks2time(now-when));
 		when = now;
 	}
-	if (deadlinetimer[m->machno].when){
-		if(deadlinetimer[m->machno].when == when){
-			iunlock(&edflock);
-			return p;
-		}
-		timerdel(&deadlinetimer[m->machno]);
+	if(deadlinetimer[m->machno].when == when){
+		iunlock(&edflock);
+		return p;
 	}
 	deadlinetimer[m->machno].when = when;
 	timeradd(&deadlinetimer[m->machno]);
@@ -1079,8 +1068,7 @@ resacquire(Task *t, CSN *c)
 	if (t->curcsn)
 		t->curcsn->S -= used;
 	when = now + c->S;
-	if (when < deadlinetimer[m->machno].when){
-		timerdel(&deadlinetimer[m->machno]);
+	if (deadlinetimer[m->machno].when == 0 || when < deadlinetimer[m->machno].when){
 		deadlinetimer[m->machno].when = when;
 		timeradd(&deadlinetimer[m->machno]);
 	}
@@ -1118,8 +1106,6 @@ resrelease(Task *t)
 		t->Delta = Infinity;
 	c->S = 0LL;	/* don't allow reuse */
 	if(devrt) devrt(t, now, SResrel);
-	if (deadlinetimer[m->machno].when)
-		timerdel(&deadlinetimer[m->machno]);
 	deadlinetimer[m->machno].when = when;
 	timeradd(&deadlinetimer[m->machno]);
 

+ 1 - 1
sys/src/9/port/portclock.c

@@ -157,8 +157,8 @@ timerintr(Ureg *u, uvlong)
 	while(t = tt->head){
 		when = t->when;
 		if(when > now){
-			iunlock(tt);
 			timerset(when);
+			iunlock(tt);
 			m->splpc = pc;	/* for kernel profiling */
 			if(callhzclock)
 				hzclock(u);

+ 2 - 2
sys/src/9/port/portdat.h

@@ -845,10 +845,10 @@ extern	Uart*	consuart;
 struct Timer
 {
 	uvlong	when;			/* fastticks when f should be called */
+	ulong	period;
 	void	(*f)(Ureg*, Timer*);
 	void	*a;
 	Timer	*next;
-	ulong	period;
 };
 
 struct Edfinterface {
@@ -876,7 +876,7 @@ struct Perf
 	ulong	avg_inintr;	/* avg time per clock tick in interrupt handlers */
 	ulong	inidle;		/* time since last clock tick in idle loop */
 	ulong	avg_inidle;	/* avg time per clock tick in idle loop */
-	ulong	last;		/* value of perfticks() at last clock tick */
+	ulong	last;			/* value of perfticks() at last clock tick */
 	ulong	period;		/* perfticks() per clock tick */
 };
 

+ 6 - 6
sys/src/cmd/acme/exec.c

@@ -533,15 +533,15 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname)
 			f->qidpath = d->qid.path;
 			f->mtime = d->mtime;
 			if(f->unread)
-				warning(nil, "%s not written; file already exists\n", name);
+				warningew(w, nil, "%s not written; file already exists\n", name);
 			else
-				warning(nil, "%s modified%s%s since last read\n", name, d->muid[0]?" by ":"", d->muid);
+				warningew(w, nil, "%s modified%s%s since last read\n", name, d->muid[0]?" by ":"", d->muid);
 			goto Rescue1;
 		}
 	}
 	fd = create(name, OWRITE, 0666);
 	if(fd < 0){
-		warning(nil, "can't create file %s: %r\n", name);
+		warningew(w, nil, "can't create file %s: %r\n", name);
 		goto Rescue1;
 	}
 	r = fbufalloc();
@@ -550,7 +550,7 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname)
 	d = dirfstat(fd);
 	isapp = (d!=nil && d->length>0 && (d->qid.type&QTAPPEND));
 	if(isapp){
-		warning(nil, "%s not written; file is append only\n", name);
+		warningew(w, nil, "%s not written; file is append only\n", name);
 		goto Rescue2;
 	}
 
@@ -561,7 +561,7 @@ putfile(File *f, int q0, int q1, Rune *namer, int nname)
 		bufread(f, q, r, n);
 		m = snprint(s, BUFSIZE+1, "%.*S", n, r);
 		if(write(fd, s, m) != m){
-			warning(nil, "can't write file %s: %r\n", name);
+			warningew(w, nil, "can't write file %s: %r\n", name);
 			goto Rescue2;
 		}
 	}
@@ -624,7 +624,7 @@ put(Text *et, Text*, Text *argt, int, int, Rune *arg, int narg)
 	f = w->body.file;
 	name = getname(&w->body, argt, arg, narg, TRUE);
 	if(name == nil){
-		warning(nil, "no file name\n");
+		warningew(w, nil, "no file name\n");
 		return;
 	}
 	namer = bytetorune(name, &nname);

+ 1 - 1
sys/src/cmd/acme/file.c

@@ -179,7 +179,7 @@ fileredoseq(File *f)
 
 	delta = &f->epsilon;
 	if(delta->nc == 0)
-		return ~0;
+		return 0;
 	bufread(delta, delta->nc-Undosize, (Rune*)&u, Undosize);
 	return u.seq;
 }

+ 3 - 1
sys/src/cmd/acme/fns.h

@@ -1,6 +1,8 @@
 #pragma	varargck	argpos	warning	2
+#pragma	varargck	argpos	warningew	2
 
 void	warning(Mntdir*, char*, ...);
+void	warningew(Window*, Mntdir*, char*, ...);
 
 #define	fbufalloc()	emalloc(BUFSIZE)
 #define	fbuffree(x)	free(x)
@@ -23,7 +25,7 @@ void	clearmouse(void);
 void	allwindows(void(*)(Window*, void*), void*);
 uint loadfile(int, uint, int*, int(*)(void*, uint, Rune*, int), void*);
 
-Window*	errorwin(Mntdir*, int);
+Window*	errorwin(Mntdir*, int, Window*);
 Runestr cleanrname(Runestr);
 void	run(Window*, char*, Rune*, int, int, char*, char*, int);
 void fsysclose(void);

+ 2 - 2
sys/src/cmd/acme/mkfile

@@ -42,5 +42,5 @@ $O.out:	/$objtype/lib/libframe.a /$objtype/lib/libdraw.a /$objtype/lib/libthread
 edit.$O ecmd.$O elog.$O:	edit.h
 
 syms:V:
-	vc -a acme.c > syms
-	for(i in ????.c) vc -aa $i >> syms
+	8c -a acme.c > syms
+	for(i in ????.c) 8c -aa $i >> syms

+ 38 - 12
sys/src/cmd/acme/util.c

@@ -88,7 +88,7 @@ errorwin1(Rune *dir, int ndir, Rune **incl, int nincl)
 
 /* make new window, if necessary; return with it locked */
 Window*
-errorwin(Mntdir *md, int owner)
+errorwin(Mntdir *md, int owner, Window *e)
 {
 	Window *w;
 
@@ -97,27 +97,24 @@ errorwin(Mntdir *md, int owner)
 			w = errorwin1(nil, 0, nil, 0);
 		else
 			w = errorwin1(md->dir, md->ndir, md->incl, md->nincl);
-		winlock(w, owner);
+		if(w != e)
+			winlock(w, owner);
 		if(w->col != nil)
 			break;
 		/* window was deleted too fast */
-		winunlock(w);
+		if(w != e)
+			winunlock(w);
 	}
 	return w;
 }
 
-void
-warning(Mntdir *md, char *s, ...)
+static void
+printwarning(Window *ew, Mntdir *md, Rune *r)
 {
-	Rune *r;
 	int nr, q0, owner;
 	Window *w;
 	Text *t;
-	va_list arg;
 
-	va_start(arg, s);
-	r = runevsmprint(s, arg);
-	va_end(arg);
 	if(r == nil)
 		error("runevsmprint failed");
 	nr = runestrlen(r);
@@ -130,7 +127,7 @@ warning(Mntdir *md, char *s, ...)
 			error("initializing columns in warning()");
 	}
 
-	w = errorwin(md, 'E');
+	w = errorwin(md, 'E', ew);
 	t = &w->body;
 	owner = w->owner;
 	if(owner == 0)
@@ -142,10 +139,39 @@ warning(Mntdir *md, char *s, ...)
 	textscrdraw(t);
 	w->owner = owner;
 	w->dirty = FALSE;
-	winunlock(w);
+	if(ew != w)
+		winunlock(w);
 	free(r);
 }
 
+void
+warning(Mntdir *md, char *s, ...)
+{
+	Rune *r;
+	va_list arg;
+
+	va_start(arg, s);
+	r = runevsmprint(s, arg);
+	va_end(arg);
+	printwarning(nil, md, r);
+}
+
+/*
+ * Warningew is like warning but avoids locking the error window
+ * if it's already locked by checking that ew!=error window.
+ */
+void
+warningew(Window *ew, Mntdir *md, char *s, ...)
+{
+	Rune *r;
+	va_list arg;
+
+	va_start(arg, s);
+	r = runevsmprint(s, arg);
+	va_end(arg);
+	printwarning(ew, md, r);
+}
+
 int
 runeeq(Rune *s1, uint n1, Rune *s2, uint n2)
 {

+ 1 - 1
sys/src/cmd/acme/xfid.c

@@ -382,7 +382,7 @@ xfidwrite(Xfid *x)
 	x->data[x->count] = 0;
 	switch(qid){
 	case Qcons:
-		w = errorwin(x->f->mntdir, 'X');
+		w = errorwin(x->f->mntdir, 'X', nil);
 		t=&w->body;
 		goto BodyTag;
 

+ 13 - 7
sys/src/cmd/mkfile

@@ -8,7 +8,7 @@ LDFLAGS=
 YFLAGS=-d
 
 NOTSYS=sml|dup
-BUGGERED=gc|lmlvideo|dwb|unix|perl|celp|mosml
+BUGGERED=gc|lmlvideo|dwb|unix|perl|celp|mosml|ovac|vfs
 OUTOFDATE=old|ssls
 
 NOMK=$NOTSYS|$BUGGERED|$OUTOFDATE
@@ -47,10 +47,13 @@ all:V:	$PROGS dirs
 %.install:V: $BIN/%
 
 %.safeinstall:	$O.%
-	test -e $cpuobjtype._cp || cp /bin/cp $cpuobjtype._cp
-	test -e $cpuobjtype._mv || cp /bin/mv $cpuobjtype._mv
-	test -e $BIN/$stem && $cpuobjtype._mv $BIN/$stem $BIN/_$stem
-	$cpuobjtype._cp $prereq $BIN/$stem
+	test -e $BIN/$stem && mv $BIN/$stem $BIN/_$stem
+	cp $prereq $BIN/$stem
+
+cp.safeinstall:	$O.cp
+	cp /bin/cp $cpuobjtype._cp
+	test -e $BIN/cp && mv $BIN/cp $BIN/_cp
+	$cpuobjtype._cp $prereq $BIN/cp
 
 %.safeinstallall:
 	for(objtype in $CPUS)
@@ -58,8 +61,11 @@ all:V:	$PROGS dirs
 	mk $stem.clean
 
 $BIN/%:	$O.%
-	test -e $cpuobjtype._cp || cp /bin/cp $cpuobjtype._cp
-	$cpuobjtype._cp $prereq $BIN/$stem
+	cp $prereq $BIN/$stem
+
+$BIN/cp:	$O.cp
+	cp /bin/cp $cpuobjtype._cp
+	$cpuobjtype._cp $prereq $BIN/cp
 
 %.directories:V:
 	for(i in $DIRS) @{

+ 1 - 1
sys/src/cmd/tcs/tcs.c

@@ -984,7 +984,7 @@ long tab8859_15[256] =		/* from anyrhine@cs.helsinki.fi (Aki Nyrhinen) */
 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
-0xa0,0xa1,0xa2,0xa3,0x20a0,0xa5,0x0160,0xa7,0x0161,0xa9,0xaa,0xab,0xac,0xad,
+0xa0,0xa1,0xa2,0xa3,0x20ac,0xa5,0x0160,0xa7,0x0161,0xa9,0xaa,0xab,0xac,0xad,
 0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0x017d,0xb5,0xb6,0xb7,0x017e,0xb9,0xba,0xbb,
 0x0152,0x0153,0x0178,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,
 0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,

+ 52 - 148
sys/src/cmd/tcs/utf.c

@@ -20,13 +20,6 @@
 	unsigned char.
 */
 
-#ifdef PLAN9
-long getrune(Biobuf *);
-long getisorune(Biobuf *);
-#else
-long getrune(FILE *);
-long getisorune(FILE *);
-#endif
 int our_wctomb(char *s, unsigned long wc);
 int our_mbtowc(unsigned long *p, char *s, unsigned n);
 int runetoisoutf(char *str, Rune *rune);
@@ -36,51 +29,37 @@ int isochartorune(Rune *rune, char *str);
 void
 utf_in(int fd, long *notused, struct convert *out)
 {
-#ifndef PLAN9
-	FILE *fp;
-#else /* PLAN9 */
-	Biobuf b;
-#endif /* PLAN9 */
-	Rune *r;
-	long l;
+	char buf[N];
+	int i, j, c, n, tot;
+	ulong l;
 
 	USED(notused);
-#ifndef PLAN9
-	if((fp = fdopen(fd, "r")) == NULL){
-		EPR "%s: input setup error: %s\n", argv0, strerror(errno));
-#else /* PLAN9 */
-	if(Binit(&b, fd, OREAD) < 0){
-		EPR "%s: input setup error: %r\n", argv0);
-#endif /* PLAN9 */
-		EXIT(1, "input error");
-	}
-	r = runes;
-	for(;;)
-#ifndef PLAN9
-		switch(l = getrune(fp))
-#else /* PLAN9 */
-		switch(l = getrune(&b))
-#endif /* PLAN9 */
-		{
-		case -1:
-			goto done;
-		case -2:
-			if(squawk)
-				EPR "%s: bad UTF sequence near byte %ld in input\n", argv0, ninput);
-			if(clean)
-				continue;
-			nerrors++;
-			l = Runeerror;
-		default:
-			*r++ = l;
-			if(r >= &runes[N]){
-				OUT(out, runes, r-runes);
-				r = runes;
+	tot = 0;
+	while((n = read(fd, buf+tot, N-tot)) >= 0){
+		tot += n;
+		for(i=j=0; i<tot; ){
+			c = our_mbtowc(&l, buf+i, tot-i);
+			if(c == -1)
+				break;
+			if(c == -2){
+				if(squawk)
+					EPR "%s: bad UTF sequence near byte %ld in input\n", argv0, ninput+i);
+				if(clean)
+					continue;
+				nerrors++;
+				l = Runeerror;
 			}
+			runes[j++] = l;
+			i += c;
 		}
-done:
-	if(r > runes)
-		OUT(out, runes, r-runes);
+		OUT(out, runes, j);
+		tot -= i;
+		ninput += i;
+		if(tot)
+			memmove(buf, buf+i, tot);
+		if(n == 0)
+			break;
+	}
 }
 
 void
@@ -101,51 +80,35 @@ utf_out(Rune *base, int n, long *notused)
 void
 isoutf_in(int fd, long *notused, struct convert *out)
 {
-#ifndef PLAN9
-	FILE *fp;
-#else /* PLAN9 */
-	Biobuf b;
-#endif /* PLAN9 */
-	Rune *r;
-	long l;
+	char buf[N];
+	int i, j, c, n, tot;
 
 	USED(notused);
-#ifndef PLAN9
-	if((fp = fdopen(fd, "r")) == 0){
-		EPR "%s: input setup error: %s\n", argv0, strerror(errno));
-#else /* PLAN9 */
-	if(Binit(&b, fd, OREAD) < 0){
-		EPR "%s: input setup error: %r\n", argv0);
-#endif /* PLAN9 */
-		EXIT(1, "input error");
-	}
-	r = runes;
-	for(;;)
-#ifndef PLAN9
-		switch(l = getisorune(fp))
-#else /* PLAN9 */
-		switch(l = getisorune(&b))
-#endif /* PLAN9 */
-		{
-		case -1:
-			goto done;
-		case -2:
-			if(squawk)
-				EPR "%s: bad UTF sequence near byte %ld in input\n", argv0, ninput);
-			if(clean)
-				continue;
-			nerrors++;
-			l = Runeerror;
-		default:
-			*r++ = l;
-			if(r >= &runes[N]){
-				OUT(out, runes, r-runes);
-				r = runes;
+	tot = 0;
+	while((n = read(fd, buf+tot, N-tot)) >= 0){
+		tot += n;
+		for(i=j=0; i<tot; ){
+			if(!fullisorune(buf+i, tot-i))
+				break;
+			c = isochartorune(&runes[j], buf+i);
+			if(runes[j] == Runeerror){
+				if(squawk)
+					EPR "%s: bad UTF sequence near byte %ld in input\n", argv0, ninput+i);
+				if(clean)
+					continue;
+				nerrors++;
 			}
+			j++;
+			i += c;
 		}
-done:
-	if(r > runes)
-		OUT(out, runes, r-runes);
+		OUT(out, runes, j);
+		tot -= i;
+		ninput += i;
+		if(tot)
+			memmove(buf, buf+i, tot);
+		if(n == 0)
+			break;
+	}
 }
 
 void
@@ -162,65 +125,6 @@ isoutf_out(Rune *base, int n, long *notused)
 	write(1, obuf, p-obuf);
 }
 
-long
-#ifndef PLAN9
-getrune(FILE *fp)
-#else /* PLAN9 */
-getrune(Biobuf *bp)
-#endif /* PLAN9 */
-{
-	int c, i;
-	char str[UTFmax];	/* MB_LEN_MAX really */
-	unsigned long l;
-	int n;
-
-	for(i = 0;;){
-#ifndef PLAN9
-		c = getc(fp);
-#else /* PLAN9 */
-		c = Bgetc(bp);
-#endif /* PLAN9 */
-		if(c < 0)
-			return(c);
-		ninput++;
-		str[i++] = c;
-		n = our_mbtowc(&l, str, i);
-		if(n == -1)
-			return(-2);
-		if(n > 0)
-			return(l);
-	}
-}
-
-long
-#ifndef PLAN9
-getisorune(FILE *fp)
-#else /* PLAN9 */
-getisorune(Biobuf *bp)
-#endif /* PLAN9 */
-{
-	int c, i;
-	Rune rune;
-	char str[UTFmax];	/* MB_LEN_MAX really */
-
-	for(i = 0;;){
-#ifndef PLAN9
-		c = getc(fp);
-#else /* PLAN9 */
-		c = Bgetc(bp);
-#endif /* PLAN9 */
-		if(c < 0)
-			return(c);
-		ninput++;
-		str[i++] = c;
-		if(fullisorune(str, i))
-			break;
-	}
-	isochartorune(&rune, str);
-	if(rune == Runeerror)
-		return -2;
-	return(rune);
-}
 
 enum
 {

+ 61 - 0
sys/src/libsec/port/rsafill.c

@@ -0,0 +1,61 @@
+#include "os.h"
+#include <mp.h>
+#include <libsec.h>
+
+RSApriv*
+rsafill(mpint *n, mpint *e, mpint *d, mpint *p, mpint *q)
+{
+	mpint *c2, *kq, *kp, *x;
+	RSApriv *rsa;
+
+	// make sure we're not being hoodwinked
+	if(!probably_prime(p, 10) || !probably_prime(q, 10)){
+		werrstr("rsafill: p or q not prime");
+		return nil;
+	}
+	x = mpnew(0);
+	mpmul(p, q, x);
+	if(mpcmp(n, x) != 0){
+		werrstr("rsafill: n != p*q");
+		mpfree(x);
+		return nil;
+	}
+	c2 = mpnew(0);
+	mpsub(p, mpone, c2);
+	mpsub(q, mpone, x);
+	mpmul(c2, x, x);
+	mpmul(e, d, c2);
+	mpmod(c2, x, x);
+	if(mpcmp(x, mpone) != 0){
+		werrstr("rsafill: e*d != (p-1)*(q-1) mod n");
+		mpfree(x);
+		mpfree(c2);
+		return nil;
+	}
+
+	// compute chinese remainder coefficient
+	mpinvert(p, q, c2);
+
+	// for crt a**k mod p == (a**(k mod p-1)) mod p
+	kq = mpnew(0);
+	kp = mpnew(0);
+	mpsub(p, mpone, x);
+	mpmod(d, x, kp);
+	mpsub(q, mpone, x);
+	mpmod(d, x, kq);
+
+	rsa = rsaprivalloc();
+	rsa->pub.ek = mpcopy(e);
+	rsa->pub.n = mpcopy(n);
+	rsa->dk = mpcopy(d);
+	rsa->kp = kp;
+	rsa->kq = kq;
+	rsa->p = mpcopy(p);
+	rsa->q = mpcopy(q);
+	rsa->c2 = c2;
+
+	mpfree(x);
+
+	return rsa;
+}
+