From dd4068095b04c9b14ff6ce697a8296d6089b2085 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 12 Aug 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-08-12 --- carrera/main.c | 1 + pc/devvga.c | 4 +- pc/main.c | 1 + pc/trap.c | 2 +- port/alloc.c | 6 +++ port/chan.c | 2 +- port/pgrp.c | 17 ++++++++ port/portdat.h | 11 ++++- port/portfns.h | 4 +- port/proc.c | 18 +++----- port/sysproc.c | 113 +++++++++++++++++++++++++++---------------------- 11 files changed, 110 insertions(+), 69 deletions(-) diff --git a/carrera/main.c b/carrera/main.c index b4e484b202b0d7e0c2facda8823a0f4ad9a0329f..95950001b9d31f5956920039f9b26529b26a6437 100644 --- a/carrera/main.c +++ b/carrera/main.c @@ -359,6 +359,7 @@ userinit(void) p->egrp->ref = 1; p->fgrp = smalloc(sizeof(Fgrp)); p->fgrp->ref = 1; + p->rgrp = newrgrp(); p->procmode = 0640; strcpy(p->text, "*init*"); diff --git a/pc/devvga.c b/pc/devvga.c index 0bfaad9835e390d6b6a2a4b31da59f0e44796faa..a8242ef4f29981c29778785e870ed9985f38b503 100644 --- a/pc/devvga.c +++ b/pc/devvga.c @@ -625,7 +625,7 @@ setscreen(int maxx, int maxy, int ldepth) h = defont0.height; w = defont0.info[' '].width; window.min = Pt(48, 48); - window.max = add(window.min, Pt(10+w*64, 36*h)); + window.max = add(window.min, Pt(10+w*80, 50*h)); if(window.max.y >= gscreen.r.max.y) window.max.y = gscreen.r.max.y-1; if(window.max.x >= gscreen.r.max.x) @@ -635,7 +635,7 @@ setscreen(int maxx, int maxy, int ldepth) /* work areas change when dimensions change */ workinit(&chwork, w, h); - workinit(&scrollwork, 64*w, 1); + workinit(&scrollwork, 80*w, 1); workinit(&scrollwork, Dx(window), 1); cursorinit(); diff --git a/pc/main.c b/pc/main.c index 9f3474ffa52de25a5fb1b589889299638e1299d5..711728e7f6576947886c420fce9fd7401b77c8ce 100644 --- a/pc/main.c +++ b/pc/main.c @@ -150,6 +150,7 @@ userinit(void) p->egrp->ref = 1; p->fgrp = smalloc(sizeof(Fgrp)); p->fgrp->ref = 1; + p->rgrp = newrgrp(); p->procmode = 0640; strcpy(p->text, "*init*"); diff --git a/pc/trap.c b/pc/trap.c index 5b7562315f9d94d773178565420bd691254274fb..7f4e066d463e615aa3753b2f623919d5df448f6e 100644 --- a/pc/trap.c +++ b/pc/trap.c @@ -359,7 +359,7 @@ dumpstack(void) return; i = 0; - lim = 3; + lim = 6; for(l=(ulong)&l; l<(ulong)(up->kstack+BY2PG) && lim; l+=4){ v = *(ulong*)l; if(KTZERO < v && v < (ulong)&etext){ diff --git a/port/alloc.c b/port/alloc.c index 16f950380cd5d0cee8789338958c81dd29779466..3c3634efc17e5942a78465869081c76718cb1913 100644 --- a/port/alloc.c +++ b/port/alloc.c @@ -321,6 +321,12 @@ good: return bp->data; } +void* +malloc(ulong size) +{ + return mallocz(size, 1); +} + void* smalloc(ulong size) { diff --git a/port/chan.c b/port/chan.c index 419047e7813d2943decbafe057960ecad79eba78..a0eb28c639a143983ea35918785023c0ac5ee473 100644 --- a/port/chan.c +++ b/port/chan.c @@ -130,7 +130,7 @@ chanfree(Chan *c) void close(Chan *c) { - if(c->flag&CFREE) + if(c == 0 || (c->flag&CFREE)) panic("close"); if(decref(c)) diff --git a/port/pgrp.c b/port/pgrp.c index ffa922401f472118d1b344f4e2b20b6d5a442bce..0b5fb880610d85d21ec8fdcc686fd58c2d03c0dc 100644 --- a/port/pgrp.c +++ b/port/pgrp.c @@ -50,6 +50,23 @@ newpgrp(void) return p; } +Rgrp* +newrgrp(void) +{ + Rgrp *r; + + r = smalloc(sizeof(Rgrp)); + r->ref = 1; + return r; +} + +void +closergrp(Rgrp *r) +{ + if(decref(r) == 0) + free(r); +} + void closepgrp(Pgrp *p) { diff --git a/port/portdat.h b/port/portdat.h index cff3fffa3736fcfe1a043bcb635b94f800aac8c1..91fa531a43ac1185bfea149c6ef9041edef282e5 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -29,6 +29,7 @@ typedef struct QLock QLock; typedef struct Queue Queue; typedef struct Ref Ref; typedef struct Rendez Rendez; +typedef struct Rgrp Rgrp; typedef struct RWlock RWlock; typedef struct Sargs Sargs; typedef struct Schedq Schedq; @@ -389,12 +390,16 @@ enum struct Pgrp { Ref; /* also used as a lock when mounting */ - Pgrp *next; /* free list */ ulong pgrpid; QLock debug; /* single access via devproc.c */ RWlock ns; /* Namespace n read/one write lock */ QLock nsh; Mhead *mnthash[MNTHASH]; +}; + +struct Rgrp +{ + Ref; Proc *rendhash[RENDHASH]; /* Rendezvous tag hash */ }; @@ -456,7 +461,8 @@ enum RFNOWAIT = (1<<6), RFCNAMEG = (1<<10), RFCENVG = (1<<11), - RFCFDG = (1<<12) + RFCFDG = (1<<12), + RFREND = (1<<13), }; /* @@ -528,6 +534,7 @@ struct Proc Pgrp *pgrp; /* Process group for namespace */ Egrp *egrp; /* Environment group */ Fgrp *fgrp; /* File descriptor group */ + Rgrp *rgrp; /* Rendez group */ ulong parentpid; ulong time[6]; /* User, Sys, Real; child U, S, R */ diff --git a/port/portfns.h b/port/portfns.h index 133ca8913f1677527c172cee7a3eaebf7fad5ac4..72eb61a079a3cc2d4267a1c77bde94fff4677a69 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -33,6 +33,7 @@ void closeegrp(Egrp*); void closefgrp(Fgrp*); void closemount(Mount*); void closepgrp(Pgrp*); +void closergrp(Rgrp*); long clrfpintr(void); void confinit(void); void confinit1(int); @@ -122,8 +123,8 @@ void lockinit(void); Page* lookpage(Image*, ulong); int m3mouseputc(void*, int); void machinit(void); -#define malloc(s) mallocz(s, 1) void* mallocz(ulong, int); +void* malloc(ulong); void mfreeseg(Segment*, ulong, int); void mmurelease(Proc*); void mmuswitch(Proc*); @@ -145,6 +146,7 @@ Chan* newchan(void); Mount* newmount(Mhead*, Chan*, int, char*); Page* newpage(int, Segment **, ulong); Pgrp* newpgrp(void); +Rgrp* newrgrp(void); Proc* newproc(void); char* nextelem(char*, char*); void nexterror(void); diff --git a/port/proc.c b/port/proc.c index 62e96732af75a6429108cadd92eb2cd1e412572a..3c941859fb09565c1a987487f54d4f5343e47e2d 100644 --- a/port/proc.c +++ b/port/proc.c @@ -257,6 +257,7 @@ newproc(void) p->pgrp = 0; p->egrp = 0; p->fgrp = 0; + p->rgrp = 0; p->pdbg = 0; p->fpstate = FPinit; p->kp = 0; @@ -356,7 +357,7 @@ tfn(void *arg) void tsleep(Rendez *r, int (*fn)(void*), void *arg, int ms) { - ulong when, i; + ulong when; Proc *f, **l; when = MS2TK(ms)+MACHP(0)->ticks; @@ -364,7 +365,6 @@ tsleep(Rendez *r, int (*fn)(void*), void *arg, int ms) lock(&talarm); /* take out of list if checkalarm didn't */ if(up->trend) { -i = 0; l = &talarm.list; for(f = *l; f; f = f->tlink) { if(f == up) { @@ -372,12 +372,6 @@ i = 0; break; } l = &f->tlink; -if(i++ > 20) { - print("tlarm loop: %lux\n", talarm.list); - for(i = 20, f = talarm.list; f && i--; f = f->tlink) - print("%lux ", f); - for(;;); -} } } /* insert in increasing time order */ @@ -468,10 +462,10 @@ postnote(Proc *p, int dolock, char *n, int flag) return ret; /* Try and pull out of a rendezvous */ - lock(p->pgrp); + lock(p->rgrp); if(p->state == Rendezvous) { p->rendval = ~0; - l = &REND(p->pgrp, p->rendtag); + l = &REND(p->rgrp, p->rendtag); for(d = *l; d; d = d->rendhash) { if(d == p) { *l = p->rendhash; @@ -481,7 +475,7 @@ postnote(Proc *p, int dolock, char *n, int flag) } ready(p); } - unlock(p->pgrp); + unlock(p->rgrp); return ret; } @@ -561,6 +555,8 @@ pexit(char *exitstr, int freemem) closefgrp(up->fgrp); if(up->egrp) closeegrp(up->egrp); + if(up->rgrp) + closergrp(up->rgrp); close(up->dot); closepgrp(up->pgrp); diff --git a/port/sysproc.c b/port/sysproc.c index 105291abc2f03105198e70f134d6663f936f4245..5efec57f7e46080f376a078d232ad737168cd62f 100644 --- a/port/sysproc.c +++ b/port/sysproc.c @@ -63,6 +63,10 @@ sysrfork(ulong *arg) up->noteid = incref(¬eidalloc); if(flag & (RFMEM|RFNOWAIT)) error(Ebadarg); + if(flag & RFREND) { + closergrp(up->rgrp); + up->rgrp = newrgrp(); + } return 0; } /* Check flags before we commit */ @@ -122,6 +126,15 @@ sysrfork(ulong *arg) incref(p->pgrp); } + if(flag & RFREND) { + closergrp(up->rgrp); + up->rgrp = newrgrp(); + } + else { + incref(up->rgrp); + p->rgrp = up->rgrp; + } + /* Environment group */ if(flag & (RFENVG|RFCENVG)) { p->egrp = smalloc(sizeof(Egrp)); @@ -202,55 +215,52 @@ sysexec(ulong *arg) validaddr(arg[0], 1, 0); file = (char*)arg[0]; indir = 0; - Header: - tc = namec(file, Aopen, OEXEC, 0); - if(waserror()){ + for(;;){ + tc = namec(file, Aopen, OEXEC, 0); + if(waserror()){ + close(tc); + nexterror(); + } + if(!indir) + strcpy(elem, up->elem); + + n = (*devtab[tc->type].read)(tc, &exec, sizeof(Exec), 0); + if(n < 2) + error(Ebadexec); + magic = l2be(exec.magic); + text = l2be(exec.text); + entry = l2be(exec.entry); + if(n==sizeof(Exec) && (magic == AOUT_MAGIC)){ + if((text&KZERO) + || entry < UTZERO+sizeof(Exec) + || entry >= UTZERO+sizeof(Exec)+text) + error(Ebadexec); + break; /* for binary */ + } + + /* + * Process #! /bin/sh args ... + */ + memmove(line, &exec, sizeof(Exec)); + if(indir || line[0]!='#' || line[1]!='!') + error(Ebadexec); + n = shargs(line, n, progarg); + if(n == 0) + error(Ebadexec); + indir = 1; + /* + * First arg becomes complete file name + */ + progarg[n++] = file; + progarg[n] = 0; + validaddr(arg[1], BY2WD, 1); + arg[1] += BY2WD; + file = progarg[0]; + progarg[0] = elem; + poperror(); close(tc); - nexterror(); - } - if(!indir) - strcpy(elem, up->elem); - - n = (*devtab[tc->type].read)(tc, &exec, sizeof(Exec), 0); - if(n < 2) - Err: - error(Ebadexec); - magic = l2be(exec.magic); - text = l2be(exec.text); - entry = l2be(exec.entry); - if(n==sizeof(Exec) && (magic == AOUT_MAGIC)){ - if((text&KZERO) - || entry < UTZERO+sizeof(Exec) - || entry >= UTZERO+sizeof(Exec)+text) - goto Err; - goto Binary; } - /* - * Process #! /bin/sh args ... - */ - memmove(line, &exec, sizeof(Exec)); - if(indir || line[0]!='#' || line[1]!='!') - goto Err; - n = shargs(line, n, progarg); - if(n == 0) - goto Err; - indir = 1; - /* - * First arg becomes complete file name - */ - progarg[n++] = file; - progarg[n] = 0; - validaddr(arg[1], BY2WD, 1); - arg[1] += BY2WD; - file = progarg[0]; - progarg[0] = elem; - poperror(); - close(tc); - goto Header; - - Binary: - poperror(); data = l2be(exec.data); bss = l2be(exec.bss); t = (UTZERO+sizeof(Exec)+text+(BY2PG-1)) & ~(BY2PG-1); @@ -328,7 +338,7 @@ sysexec(ulong *arg) /* * Committed. * Free old memory. - * Special segments are maintained accross exec + * Special segments are maintained across exec */ for(i = SSEG; i <= BSEG; i++) { putseg(up->seg[i]); @@ -391,6 +401,7 @@ sysexec(ulong *arg) else up->basepri = 1; up->priority = up->basepri; + poperror(); close(tc); /* @@ -644,9 +655,9 @@ sysrendezvous(ulong *arg) Proc *p, **l; tag = arg[0]; - l = &REND(up->pgrp, tag); + l = &REND(up->rgrp, tag); - lock(up->pgrp); + lock(up->rgrp); for(p = *l; p; p = p->rendhash) { if(p->rendtag == tag) { *l = p->rendhash; @@ -656,7 +667,7 @@ sysrendezvous(ulong *arg) while(p->mach != 0) ; ready(p); - unlock(up->pgrp); + unlock(up->rgrp); return val; } l = &p->rendhash; @@ -668,7 +679,7 @@ sysrendezvous(ulong *arg) up->rendhash = *l; *l = up; up->state = Rendezvous; - unlock(up->pgrp); + unlock(up->rgrp); sched();