From 99e17d2be68bb57fa6bd607cff14b14bfb3c14d0 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 9 Mar 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-03-09 --- gnot/lib.h | 5 ++--- port/lib.h | 5 ++--- port/portdat.h | 2 +- port/proc.c | 30 ++++++++++++++---------------- port/sysproc.c | 30 ++++++++++++++++++++++++++++++ port/systab.h | 9 ++++++--- 6 files changed, 55 insertions(+), 26 deletions(-) diff --git a/gnot/lib.h b/gnot/lib.h index 4280cc0f1afc20bd234daa35c4b00234789906ad..29a424440bde2cb38378006e3d432924d6e8bd6f 100644 --- a/gnot/lib.h +++ b/gnot/lib.h @@ -118,8 +118,7 @@ struct Dir struct Waitmsg { - int pid; /* of loved one */ - int status; /* unused; a placeholder */ - ulong time[3]; /* of loved one */ + char pid[12]; /* of loved one */ + char time[3*12]; /* of loved one and descendants */ char msg[ERRLEN]; }; diff --git a/port/lib.h b/port/lib.h index 4280cc0f1afc20bd234daa35c4b00234789906ad..29a424440bde2cb38378006e3d432924d6e8bd6f 100644 --- a/port/lib.h +++ b/port/lib.h @@ -118,8 +118,7 @@ struct Dir struct Waitmsg { - int pid; /* of loved one */ - int status; /* unused; a placeholder */ - ulong time[3]; /* of loved one */ + char pid[12]; /* of loved one */ + char time[3*12]; /* of loved one and descendants */ char msg[ERRLEN]; }; diff --git a/port/portdat.h b/port/portdat.h index 156a11517b78ac4cbfb74d34e44720363747b561..75bdc95190854af82039adbb48cbdf1ce59ec3be 100644 --- a/port/portdat.h +++ b/port/portdat.h @@ -46,7 +46,7 @@ struct List struct Ref { Lock; - int ref; + long ref; }; struct Rendez diff --git a/port/proc.c b/port/proc.c index 8767ae2188cde141ff4c0589dc578c169e3e41d6..b92949d7fbb26fe9f94b8f07f4d86fac86cbf36c 100644 --- a/port/proc.c +++ b/port/proc.c @@ -5,11 +5,7 @@ #include "fns.h" #include "../port/error.h" -struct -{ - Lock; - ulong pid; -}pidalloc; +Ref pidalloc; struct { @@ -34,7 +30,8 @@ typedef struct Schedq runhiq, runloq; int nrdy; -char *statename[]={ /* BUG: generate automatically */ +char *statename[] = +{ /* BUG: generate automatically */ "Dead", "Moribund", "Ready", @@ -231,9 +228,7 @@ newproc(void) p->procctl = 0; p->notepending = 0; memset(p->seg, 0, sizeof p->seg); - lock(&pidalloc); - p->pid = ++pidalloc.pid; - unlock(&pidalloc); + p->pid = incref(&pidalloc); if(p->pid == 0) panic("pidalloc"); return p; @@ -448,7 +443,6 @@ postnote(Proc *p, int dolock, char *n, int flag) return ret; } - /* * weird thing: keep at most NBROKEN around */ @@ -527,12 +521,15 @@ pexit(char *exitstr, int freemem) panic("boot process died"); wq = newwaitq(); - wq->w.pid = c->pid; + readnum(0, wq->w.pid, NUMSIZE, c->pid, NUMSIZE); utime = c->time[TUser] + c->time[TCUser]; stime = c->time[TSys] + c->time[TCSys]; - wq->w.time[TUser] = TK2MS(utime); - wq->w.time[TSys] = TK2MS(stime); - wq->w.time[TReal] = TK2MS(MACHP(0)->ticks - c->time[TReal]); + readnum(0, &wq->w.time[TUser*12], NUMSIZE, + TK2MS(utime), NUMSIZE); + readnum(0, &wq->w.time[TSys*12], NUMSIZE, + TK2MS(stime), NUMSIZE); + readnum(0, &wq->w.time[TReal*12], NUMSIZE, + TK2MS(MACHP(0)->ticks - c->time[TReal]), NUMSIZE); if(exitstr && exitstr[0]){ n = sprint(wq->w.msg, "%s %d:", c->text, c->pid); strncpy(wq->w.msg+n, exitstr, ERRLEN-n); @@ -540,7 +537,8 @@ pexit(char *exitstr, int freemem) wq->w.msg[0] = '\0'; lock(&p->exl); - /* My parent still alive */ + /* My parent still alive, processes are limited to 128 Zombies to + * prevent badly written daemon consuming all the wait records */ if(p->pid == c->parentpid && p->state != Broken && p->nwait < 128) { p->nchild--; p->time[TCUser] += utime; @@ -631,7 +629,7 @@ pwait(Waitmsg *w) if(w) memmove(w, &wq->w, sizeof(Waitmsg)); - cpid = wq->w.pid; + cpid = atoi(wq->w.pid); freewaitq(wq); return cpid; } diff --git a/port/sysproc.c b/port/sysproc.c index bf7c85fdf4273f70f4c2c5b5bdb1304d7cac6e70..cd52abfe8d96331d6a1f02ff385b2cb624c01391 100644 --- a/port/sysproc.c +++ b/port/sysproc.c @@ -433,6 +433,36 @@ syswait(ulong *arg) return pwait((Waitmsg*)arg[0]); } +long +sys__wait__(ulong *arg) /* binary compatibility: BUG */ +{ + int i; + + struct oldWaitmsg + { + int pid; /* of loved one */ + int status; /* unused; a vestige */ + long time[3]; /* of loved one & descendants */ + char msg[ERRLEN]; + } *wp; + Waitmsg w; + + if(arg[0]){ + validaddr(arg[0], sizeof(struct oldWaitmsg), 1); + evenaddr(arg[0]); + i = pwait(&w); + wp = (struct oldWaitmsg*)arg[0]; + wp->pid = atoi(w.pid); + wp->status = 0; + wp->time[TUser] = atoi(w.time+TUser*NUMSIZE); + wp->time[TSys] = atoi(w.time+TSys*NUMSIZE); + wp->time[TReal] = atoi(w.time+TReal*NUMSIZE); + memmove(wp->msg, w.msg, ERRLEN); + return i; + } + return pwait(0); +} + long sysdeath(ulong *arg) { diff --git a/port/systab.h b/port/systab.h index 15eb4718c3cfc1168d0ffcbceade4b5ae0485a53..e3af2fde285e77b91200a522a6be3422d30016b0 100644 --- a/port/systab.h +++ b/port/systab.h @@ -22,7 +22,7 @@ Syscall sysread; Syscall sysseek; Syscall syssleep; Syscall sysstat; -Syscall syswait; +Syscall sys__wait__; Syscall syswrite; Syscall syspipe; Syscall syscreate; @@ -39,6 +39,7 @@ Syscall syssegfree; Syscall syssegflush; Syscall sysrendezvous; Syscall sysunmount; +Syscall syswait; Syscall *systab[]={ [SYSR1] sysr1, @@ -60,7 +61,7 @@ Syscall *systab[]={ [SEEK] sysseek, [SLEEP] syssleep, [STAT] sysstat, - [WAIT] syswait, + [__WAIT__] sys__wait__, [WRITE] syswrite, [PIPE] syspipe, [CREATE] syscreate, @@ -77,6 +78,7 @@ Syscall *systab[]={ [SEGFLUSH] syssegflush, [RENDEZVOUS] sysrendezvous, [UNMOUNT] sysunmount, + [WAIT] syswait, }; char *sysctab[]={ @@ -99,7 +101,7 @@ char *sysctab[]={ [SEEK] "Seek", [SLEEP] "Sleep", [STAT] "Stat", - [WAIT] "Wait", + [__WAIT__] "__wait_", [WRITE] "Write", [PIPE] "Pipe", [CREATE] "Create", @@ -116,4 +118,5 @@ char *sysctab[]={ [SEGFLUSH] "Segflush", [RENDEZVOUS] "Rendez", [UNMOUNT] "Unmount", + [WAIT] "Wait", };