From 26a7fc41718474d9e89b13507e324ce25e9168fd Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 27 Jun 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-06-27 --- gnot/devhifi.c | 2 +- gnot/devisdn.c | 2 +- port/devbit.c | 124 ++++++++++++++++++++++++------------------------- port/devconc.c | 4 +- port/devip.c | 61 ++++++++++++++++++++---- port/ipdat.h | 2 + port/stlapd.c | 16 +++---- 7 files changed, 126 insertions(+), 85 deletions(-) diff --git a/gnot/devhifi.c b/gnot/devhifi.c index b97ecabed51a8bd219961dce274fcfe369cec0f5..f22834b254043fe3a557df1bc064b1dbbb4b405f 100644 --- a/gnot/devhifi.c +++ b/gnot/devhifi.c @@ -99,7 +99,7 @@ int hifidebug = 1; void hifireset(void) { - hifichan = ialloc(2*conf.nisdn*sizeof(Hifichan), 0); + hifichan = xalloc(2*conf.nisdn*sizeof(Hifichan)); hifichanN = &hifichan[2*conf.nisdn]; } diff --git a/gnot/devisdn.c b/gnot/devisdn.c index 1b623feb683b72e3425cef7e74547ad0ae9449ce..db897949dc243de8b80dc9167ffd61d46d1c43db 100644 --- a/gnot/devisdn.c +++ b/gnot/devisdn.c @@ -57,7 +57,7 @@ int isdndebug; void isdnreset(void) { - isdndev = ialloc(conf.nisdn*sizeof(Isdn), 0); + isdndev = xalloc(conf.nisdn*sizeof(Isdn)); isdndevN = &isdndev[conf.nisdn]; } diff --git a/port/devbit.c b/port/devbit.c index a0909bbcaf4a82eb86ebe65f075c71f87058871b..ba1fdd840e971a4dc3eb35658d37b630dbcd225d 100644 --- a/port/devbit.c +++ b/port/devbit.c @@ -352,7 +352,7 @@ bitread(Chan *c, void *va, long n, ulong offset) uchar *p, *q; long miny, maxy, t, x, y; ulong l, nw, ws, rv, gv, bv; - int off, j, dn; + int off, j; Fontchar *i; GBitmap *src; @@ -436,11 +436,11 @@ bitread(Chan *c, void *va, long n, ulong offset) * 'I' 1 * ldepth 1 * rectangle 16 - * if count great enough, also + * clip rectangle 16 * font info 3*12 * fontchars 6*(defont->n+1) */ - if(n < 18) + if(n < 34) error(Ebadblt); p[0] = 'I'; p[1] = gscreen.ldepth; @@ -448,16 +448,12 @@ bitread(Chan *c, void *va, long n, ulong offset) PLONG(p+6, gscreen.r.min.y); PLONG(p+10, gscreen.r.max.x); PLONG(p+14, gscreen.r.max.y); - dn = 18; - if(bit.init=='j' && n>=18+16){ - PLONG(p+18, gscreen.clipr.min.x); - PLONG(p+22, gscreen.clipr.min.y); - PLONG(p+26, gscreen.clipr.max.x); - PLONG(p+30, gscreen.clipr.max.y); - dn += 16; - } - if(n >= dn+3*12+6*(defont->n+1)){ - p += dn; + PLONG(p+18, gscreen.clipr.min.x); + PLONG(p+22, gscreen.clipr.min.y); + PLONG(p+26, gscreen.clipr.max.x); + PLONG(p+30, gscreen.clipr.max.y); + if(n >= 34+3*12+6*(defont->n+1)){ + p += 34; sprint((char*)p, "%11d %11d %11d ", defont->n, defont->height, defont->ascent); p += 3*12; @@ -468,9 +464,9 @@ bitread(Chan *c, void *va, long n, ulong offset) p[4] = i->left; p[5] = i->width; } - n = dn+3*12+6*(defont->n+1); + n = 34+3*12+6*(defont->n+1); }else - n = dn; + n = 34; bit.init = 0; }else if(bit.lastid > 0){ /* @@ -782,13 +778,12 @@ bitwrite(Chan *c, void *va, long n, ulong offset) break; case 'i': - case 'j': /* * init * - * 'i','j' 1 + * 'i' 1 */ - bit.init = *p; + bit.init = 1; m -= 1; p += 1; break; @@ -905,12 +900,14 @@ bitwrite(Chan *c, void *va, long n, ulong offset) * height 1 * ascent 1 * ldepth 2 + * ncache 2 * next read returns allocated font id */ - if(m < 5) + if(m < 7) error(Ebadblt); v = GSHORT(p+3); - if(v < 0) + t = GSHORT(p+5); + if(v<0 || t<0) error(Ebadblt); for(i=0; incache = t; + ff->cache = smalloc(t*sizeof(GCacheinfo)); bit.font[i] = ff; ff = bit.font[i]; ff->height = p[1]; @@ -929,8 +928,8 @@ bitwrite(Chan *c, void *va, long n, ulong offset) ff->ldepth = v; ff->width = 0; ff->b = 0; - m -= 5; - p += 5; + m -= 7; + p += 7; bit.lastfid = i; break; @@ -1016,53 +1015,16 @@ bitwrite(Chan *c, void *va, long n, ulong offset) m -= 11; break; - case 't': - /* - * texture - * 't' 1 - * dst id 2 - * rect 16 - * src id 2 - * fcode 2 - */ - if(m < 23) - error(Ebadblt); - v = GSHORT(p+1); - if(v<0 || v>=bit.nmap || (dst=bit.map[v])==0) - error(Ebadbitmap); - off = 0; - fc = GSHORT(p+21) & 0xF; - if(v == 0){ - if(flipping) - fc = flipD[fc]; - off = 1; - } - rect.min.x = GLONG(p+3); - rect.min.y = GLONG(p+7); - rect.max.x = GLONG(p+11); - rect.max.y = GLONG(p+15); - v = GSHORT(p+19); - if(v<0 || v>=bit.nmap || (src=bit.map[v])==0) - error(Ebadbitmap); - if(off && !isoff){ - cursoroff(1); - isoff = 1; - } - gtexture(dst, rect, src, fc); - m -= 23; - p += 23; - break; - - case 'u': + case 's': /* * string - * 'u' 1 + * 's' 1 * id 2 * pt 8 * font id 2 * code 2 * n 2 - * cache indexes 2*n (not null terminated) + * cache indices 2*n (not null terminated) */ if(m < 17) error(Ebadblt); @@ -1095,6 +1057,43 @@ bitwrite(Chan *c, void *va, long n, ulong offset) p += l; break; + case 't': + /* + * texture + * 't' 1 + * dst id 2 + * rect 16 + * src id 2 + * fcode 2 + */ + if(m < 23) + error(Ebadblt); + v = GSHORT(p+1); + if(v<0 || v>=bit.nmap || (dst=bit.map[v])==0) + error(Ebadbitmap); + off = 0; + fc = GSHORT(p+21) & 0xF; + if(v == 0){ + if(flipping) + fc = flipD[fc]; + off = 1; + } + rect.min.x = GLONG(p+3); + rect.min.y = GLONG(p+7); + rect.max.x = GLONG(p+11); + rect.max.y = GLONG(p+15); + v = GSHORT(p+19); + if(v<0 || v>=bit.nmap || (src=bit.map[v])==0) + error(Ebadbitmap); + if(off && !isoff){ + cursoroff(1); + isoff = 1; + } + gtexture(dst, rect, src, fc); + m -= 23; + p += 23; + break; + case 'v': /* * clear font cache and bitmap @@ -1380,6 +1379,7 @@ fontfree(GFont *f) { if(f->b) bitfree(f->b); + free(f->cache); free(f); } diff --git a/port/devconc.c b/port/devconc.c index c27b37930c260fcbf834ff13929e7aa6e5a0d9b9..6b658f1342f1e085e75ec2c50ea843a409da1243 100644 --- a/port/devconc.c +++ b/port/devconc.c @@ -6,8 +6,6 @@ #include "io.h" #include "../port/error.h" -#include "fcall.h" - #define concdebug 1 #define DPRINT if(concdebug)kprint @@ -285,7 +283,7 @@ concdevstclose(Queue *q) q->ptr = 0; q->other->ptr = 0; dp->rq = 0; - streamexit(cp->s); + streamexit(cp->s, 1); qunlock(cp); } diff --git a/port/devip.c b/port/devip.c index ace70054a215e7dc32726461d8b728071f512d30..95eec41e91bc7658ede7681853d82574512ddca6 100644 --- a/port/devip.c +++ b/port/devip.c @@ -382,6 +382,9 @@ ipwrite(Chan *c, char *a, long n, ulong offset) backlog = 5; cp->backlog = backlog; } + else if(strcmp(field[0], "headers") == 0) { + cp->headers = 1; /* include addr/port in user packet */ + } else return streamwrite(c, a, n, 0); @@ -419,6 +422,7 @@ udprcvmsg(Ipifc *ifc, Block *bp) Port dport, sport; ushort sum, len; Ipaddr addr; + Block *nbp; uh = (Udphdr *)(bp->rptr); @@ -457,9 +461,20 @@ udprcvmsg(Ipifc *ifc, Block *bp) if(bp == 0) return; - /* Stuff the src address into the remote file */ - cp->dst = addr; - cp->pdst = sport; + if(cp->headers){ + /* pass the src address to the stream head */ + nbp = allocb(Udphdrsize); + nbp->next = bp; + bp = nbp; + hnputl(bp->wptr, addr); + bp->wptr += 4; + hnputs(bp->wptr, sport); + bp->wptr += 2; + } else { + /* save the src address in the conversation struct */ + cp->dst = addr; + cp->pdst = sport; + } PUTNEXT(cp->readq, bp); return; } @@ -471,18 +486,19 @@ udprcvmsg(Ipifc *ifc, Block *bp) void udpstoput(Queue *q, Block *bp) { - Ipconv *ipc; + Ipconv *cp; Udphdr *uh; int dlen, ptcllen, newlen; + Ipaddr addr; + Port port; if(bp->type == M_CTL) { PUTNEXT(q, bp); return; } - /* Prepend udp header to packet and pass on to ip layer */ - ipc = (Ipconv *)(q->ptr); - if(ipc->psrc == 0) + cp = (Ipconv *)(q->ptr); + if(cp->psrc == 0) error(Enoport); if(bp->type != M_DATA) { @@ -496,6 +512,25 @@ udpstoput(Queue *q, Block *bp) error(Emsgsize); } + /* + * if we're in header mode, rip off the first 64 bytes as the + * destination. The destination is in ascii in the form + * %d.%d.%d.%d!%d + */ + if(cp->headers){ + /* get user specified addresses */ + bp = pullup(bp, Udphdrsize); + if(bp == 0){ + freeb(bp); + error(Emsgsize); + } + addr = nhgetl(bp->rptr); + bp->rptr += 4; + port = nhgets(bp->rptr); + bp->rptr += 2; + } else + addr = port = 0; + /* Round packet up to even number of bytes and check we can * send it */ @@ -517,10 +552,15 @@ udpstoput(Queue *q, Block *bp) uh->frag[0] = 0; uh->frag[1] = 0; hnputs(uh->udpplen, ptcllen); - hnputl(uh->udpdst, ipc->dst); hnputl(uh->udpsrc, Myip[Myself]); - hnputs(uh->udpsport, ipc->psrc); - hnputs(uh->udpdport, ipc->pdst); + hnputs(uh->udpsport, cp->psrc); + if(cp->headers){ + hnputl(uh->udpdst, addr); + hnputs(uh->udpdport, port); + } else { + hnputl(uh->udpdst, cp->dst); + hnputs(uh->udpdport, cp->pdst); + } hnputs(uh->udplen, ptcllen); uh->udpcksum[0] = 0; uh->udpcksum[1] = 0; @@ -536,6 +576,7 @@ udpstclose(Queue *q) ipc = (Ipconv *)(q->ptr); + ipc->headers = 0; ipc->psrc = 0; ipc->pdst = 0; ipc->dst = 0; diff --git a/port/ipdat.h b/port/ipdat.h index db109b9408c28b5bae461797a71646b2ea69606e..16aba00b9cbd841b3a16d398803d4311007a2954 100644 --- a/port/ipdat.h +++ b/port/ipdat.h @@ -291,6 +291,7 @@ struct Ipconv char *err; /* Async protocol error */ int backlog; /* Maximum number of waiting connections */ + int headers; /* include header in packet */ int curlog; /* Number of waiting connections */ Ipconv *newcon; /* This is the start of a connection */ @@ -361,6 +362,7 @@ enum /* Tcp connection states */ enum { Nipconv= 512, /* max conversations per interface */ + Udphdrsize= 6, /* size if a to/from user Udp header */ }; /* diff --git a/port/stlapd.c b/port/stlapd.c index fc9f8b0b85e55c1ce1462faeb8b03789466454ef..2722591cf7a4bce8584116742914bafad8bd6ae4 100644 --- a/port/stlapd.c +++ b/port/stlapd.c @@ -75,6 +75,7 @@ struct Lapd { QLock; /* access, state change */ Rendez; /* waiting for state change */ + int klocked;/* locked by kernel proc */ int state; int flags; Queue * rq; @@ -723,12 +724,14 @@ static void lapdkproc(void *arg) { Lapd *lp = (Lapd *)arg; - int locked = 0; + + lp->klocked = 0; lp->kstarted = 1; if(waserror()){ - if (locked) + if(lp->klocked) qunlock(lp); + lp->klocked = 0; print("lapdkproc %d error\n", lp-lapd); lp->kstarted = 0; wakeup(lp); @@ -739,12 +742,10 @@ lapdkproc(void *arg) if(!lp->t200 || NOW < lp->t200) continue; qlock(lp); - locked = 1; - USED(locked); + lp->klocked = 1; if(lp->flags & Hungup){ qunlock(lp); - locked = 0; - USED(locked); + lp->klocked = 0; break; } switch(lp->state){ @@ -762,8 +763,7 @@ lapdkproc(void *arg) break; } qunlock(lp); - locked = 0; - USED(locked); + lp->klocked = 0; } lp->kstarted = 0; wakeup(lp);