From b8f5620387e59e51d65b9b46335611a490cc799b Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 15 Nov 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-11-15 --- gnot/devpipe.c | 18 ++++++++++++++++-- gnot/devproc.c | 2 +- gnot/main.c | 10 +++++----- gnot/sysproc.c | 10 ++++++++-- port/devpipe.c | 34 +++++++++++++++++++++------------- port/devproc.c | 2 +- port/page.c | 2 +- power/lock.c | 1 + 8 files changed, 54 insertions(+), 25 deletions(-) diff --git a/gnot/devpipe.c b/gnot/devpipe.c index c213aeb57863341a463519e99372e9888b8d03bc..db04fb3a7a565a13766283001aa89307acc4f865 100644 --- a/gnot/devpipe.c +++ b/gnot/devpipe.c @@ -27,7 +27,14 @@ struct Pipealloc static void pipeiput(Queue*, Block*); static void pipeoput(Queue*, Block*); static void pipestclose(Queue *); -Qinfo pipeinfo = { pipeiput, pipeoput, 0, pipestclose, "pipe" }; +Qinfo pipeinfo = +{ + pipeiput, + pipeoput, + 0, + pipestclose, + "pipe" +}; Dirtab pipedir[]={ "data", Sdataqid, 0, 0600, @@ -171,7 +178,7 @@ pipeopen(Chan *c, int omode) * pointer from the other stream. */ if(streamenter(local)<0) - panic("pipeattach"); + panic("pipeopen"); } unlock(p); poperror(); @@ -221,6 +228,11 @@ pipeclose(Chan *c) Pipe *p; p = &pipealloc.pipe[STREAMID(c->qid)/2]; + lock(p); + if(waserror()){ + unlock(p); + nexterror(); + } /* * take care of associated streams @@ -230,6 +242,8 @@ pipeclose(Chan *c) streamclose(c); /* close this stream */ streamexit(remote, 0); /* release stream for other half of pipe */ } + unlock(p); + poperror(); pipeexit(p); } diff --git a/gnot/devproc.c b/gnot/devproc.c index 9160c06aece3a8a86bdb9f4e5773d5fd66d9c705..8fb07ed1b380f2f66f590fbfd081d0fff140c057 100644 --- a/gnot/devproc.c +++ b/gnot/devproc.c @@ -152,7 +152,7 @@ procopen(Chan *c, int omode) break; case Qnotepg: - if(omode != OWRITE) + if(omode!=OWRITE || pg->pgrpid==1) /* easy to do by mistake */ error(0, Eperm); c->pgrpid = (pg->pgrpid<index+1)<p->bssend) + if(addr < u->p->bssend){ + pprint("addr below bss\n"); + pexit("Suicide", 0); error(0, Esegaddr); + } if(addr <= ((u->p->bssend+(BY2PG-1))&~(BY2PG-1))) /* still in DSEG */ goto Return; - if(segaddr(&u->p->seg[BSEG], u->p->seg[BSEG].minva, arg[0]) == 0) + if(segaddr(&u->p->seg[BSEG], u->p->seg[BSEG].minva, arg[0]) == 0){ + pprint("bad segaddr in brk\n"); + pexit("Suicide", 0); error(0, Esegaddr); + } Return: u->p->bssend = addr; return 0; diff --git a/port/devpipe.c b/port/devpipe.c index 5f6ced88435a35555edfa07e5ff239debafdfca8..404d4a51544bef7ba639d4cf433201137f3c7016 100644 --- a/port/devpipe.c +++ b/port/devpipe.c @@ -82,10 +82,8 @@ pipeattach(char *spec) } p = pipealloc.free; pipealloc.free = p->next; - if(++(p->ref) != 1){ - print("pipattach pipe half %d ref %d\n", p - pipealloc.pipe, p->ref); + if(incref(p) != 1) panic("pipeattach"); - } unlock(&pipealloc); c->qid = CHDIR|STREAMQID(2*(p - pipealloc.pipe), 0); @@ -209,6 +207,19 @@ pipewstat(Chan *c, char *db) error(0, Eperm); } +void +pipeexit(Pipe *p) +{ + if(decref(p) < 0) + panic("pipeexit"); + if(p->ref == 0){ + lock(&pipealloc); + p->next = pipealloc.free; + pipealloc.free = p; + unlock(&pipealloc); + } +} + void pipeclose(Chan *c) { @@ -217,6 +228,11 @@ pipeclose(Chan *c) Pipe *p; p = &pipealloc.pipe[STREAMID(c->qid)/2]; + lock(p); + if(waserror()){ + unlock(p); + nexterror(); + } /* * take care of associated streams @@ -226,17 +242,9 @@ pipeclose(Chan *c) streamclose(c); /* close this stream */ streamexit(remote, 0); /* release stream for other half of pipe */ } - - lock(p); - if(--(p->ref) < 0) - panic("pipeexit"); - if(p->ref == 0){ - lock(&pipealloc); - p->next = pipealloc.free; - pipealloc.free = p; - unlock(&pipealloc); - } unlock(p); + poperror(); + pipeexit(p); } long diff --git a/port/devproc.c b/port/devproc.c index 8aeb84d4e25b7fc1a32ba192830f833b99fdb53e..3944efcc42b12596929157a94ccf97c6d45889bf 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -155,7 +155,7 @@ procopen(Chan *c, int omode) break; case Qnotepg: - if(omode != OWRITE) + if(omode!=OWRITE || pg->pgrpid==1) /* easy to do by mistake */ error(0, Eperm); c->pgrpid = (pg->pgrpid<index+1)<pc); +dumpstack(); } int