From 6273cbe67c9ce18f092a478d1c2b36ffcf33e786 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 28 May 2001 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2001-05-28 --- bitsy/devuda1341.c | 63 ++++++++++++++++++++++++---------------------- port/devdraw.c | 4 ++- port/error.h | 1 + port/sysfile.c | 10 ++++++-- 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/bitsy/devuda1341.c b/bitsy/devuda1341.c index ea00beed9e05a664a628ce361823b1d366316769..3a9605c17133cfa189f5ac703778195684394c64 100644 --- a/bitsy/devuda1341.c +++ b/bitsy/devuda1341.c @@ -10,6 +10,7 @@ * * The interface should be identical to that of devaudio.c */ + #include "u.h" #include "../port/lib.h" #include "mem.h" @@ -149,6 +150,7 @@ enum { Dirtab audiodir[] = { + ".", {Qdir, 0, QTDIR}, 0, DMDIR|0555, "audio", {Qaudio}, 0, 0666, "volume", {Qvolume}, 0, 0666, "speed", {Qspeed}, 0, 0666, @@ -766,27 +768,29 @@ sendaudio(IOstate *s) { return; } while (s->next != s->filling) { - assert(s->next->nbytes); - if ((n = dmastart(s->dma, s->next->phys, s->next->nbytes)) == 0) { - iostats.faildma++; - break; - } - iostats.totaldma++; - switch (n >> 8) { - case 1: - iostats.idledma++; - break; - case 3: - iostats.faildma++; - break; - } - if (debug) { - if (debug > 1) - print("dmastart @%p\n", s->next); - else - iprint("+"); + s->next->nbytes &= ~0x3; /* must be a multiple of 4 */ + if(s->next->nbytes) { + if ((n = dmastart(s->dma, s->next->phys, s->next->nbytes)) == 0) { + iostats.faildma++; + break; + } + iostats.totaldma++; + switch (n >> 8) { + case 1: + iostats.idledma++; + break; + case 3: + iostats.faildma++; + break; + } + if (debug) { + if (debug > 1) + print("dmastart @%p\n", s->next); + else + iprint("+"); + } + s->next->nbytes = 0; } - s->next->nbytes = 0; s->next++; if (s->next == &s->buf[Nbuf]) s->next = &s->buf[0]; @@ -901,15 +905,15 @@ audioattach(char *param) } static int -audiowalk(Chan *c, char *name) +audiowalk(Chan *c, Chan *nc, char **name, int nname) { - return devwalk(c, name, audiodir, nelem(audiodir), devgen); + return devwalk(c, nc, name, nname, audiodir, nelem(audiodir), devgen); } -static void -audiostat(Chan *c, char *db) +static int +audiostat(Chan *c, uchar *db, int n) { - devstat(c, db, audiodir, nelem(audiodir), devgen); + return devstat(c, db, n, audiodir, nelem(audiodir), devgen); } static Chan* @@ -918,7 +922,7 @@ audioopen(Chan *c, int mode) IOstate *s; int omode = mode; - switch(c->qid.path & ~CHDIR) { + switch((ulong)c->qid.path) { default: error(Eperm); break; @@ -986,7 +990,7 @@ audioclose(Chan *c) { IOstate *s; - switch(c->qid.path & ~CHDIR) { + switch((ulong)c->qid.path) { default: error(Eperm); break; @@ -1074,7 +1078,7 @@ audioread(Chan *c, void *v, long n, vlong off) n0 = n; p = v; - switch(c->qid.path & ~CHDIR) { + switch((ulong)c->qid.path) { default: error(Eperm); break; @@ -1212,7 +1216,7 @@ audiowrite(Chan *c, void *vp, long n, vlong) p = vp; n0 = n; - switch(c->qid.path & ~CHDIR) { + switch((ulong)c->qid.path) { default: error(Eperm); break; @@ -1373,7 +1377,6 @@ Dev uda1341devtab = { devreset, audioinit, audioattach, - devclone, audiowalk, audiostat, audioopen, diff --git a/port/devdraw.c b/port/devdraw.c index c40f29217d91f6fef5f48af98be003356ab97a58..919af85653826c100a7a17bfddeec7152aad647c 100644 --- a/port/devdraw.c +++ b/port/devdraw.c @@ -1509,8 +1509,10 @@ drawmesg(Client *client, void *av, int n) error(Enodrawimage); if(font->image->layer) error("can't use window as font"); - free(font->fchar); /* should we complain if non-zero? */ ni = BGLONG(a+5); + if(ni<=0 || ni>4096) + error("bad font size (4096 chars max)"); + free(font->fchar); /* should we complain if non-zero? */ font->fchar = malloc(ni*sizeof(FChar)); if(font->fchar == 0) error("no memory for font"); diff --git a/port/error.h b/port/error.h index 877fdfc39e1fe63311d46ea04c38838a57647a7c..5e571b947ff2cd9233a24e83fef454d0edd3b22b 100644 --- a/port/error.h +++ b/port/error.h @@ -46,3 +46,4 @@ extern char Enoreg[]; /* process has no saved registers */ extern char Enoattach[]; /* mount/attach disallowed */ extern char Eshortstat[]; /* stat buffer too small */ extern char Ebadstat[]; /* malformed stat buffer */ +extern char Enegoff[]; /* negative i/o offset */ diff --git a/port/sysfile.c b/port/sysfile.c index 3a62c9d24864d274f27740ede39b49e12d4768e2..17a7c4a29e28467dae525c931591644f31331aa2 100644 --- a/port/sysfile.c +++ b/port/sysfile.c @@ -363,7 +363,7 @@ read(ulong *arg, uvlong *offp) int dir; long n; Chan *c; - uvlong off; + vlong off; n = arg[2]; validaddr(arg[1], n, 1); @@ -385,6 +385,9 @@ read(ulong *arg, uvlong *offp) else off = *offp; + if(off < 0) + error(Enegoff); + if(dir && c->umh) n = unionread(c, (void*)arg[1], n); else @@ -430,7 +433,7 @@ write(ulong *arg, uvlong *offp) { Chan *c; long m, n; - uvlong off; + vlong off; validaddr(arg[1], arg[2], 0); n = 0; @@ -458,6 +461,9 @@ write(ulong *arg, uvlong *offp) }else off = *offp; + if(off < 0) + error(Enegoff); + m = devtab[c->type]->write(c, (void*)arg[1], n, off); if(offp == nil && m < n){