From 43a47f3d29948ef91b666ad1a16d30270c8bb90b Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 16 Aug 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-08-16 --- gnot/chan.c | 4 ++++ gnot/dat.h | 1 + gnot/fns.h | 1 + gnot/l.s | 11 +++++++++++ gnot/lib.h | 2 ++ gnot/sysfile.c | 4 ++-- gnot/sysproc.c | 11 ++++++++++- gnot/trap.c | 14 +++++--------- port/chan.c | 6 +++++- port/lib.h | 2 ++ port/sysfile.c | 4 ++-- port/sysproc.c | 11 ++++++++++- power/dat.h | 1 + power/devhs.c | 5 ----- power/fns.h | 1 + power/trap.c | 4 ++-- 16 files changed, 59 insertions(+), 23 deletions(-) diff --git a/gnot/chan.c b/gnot/chan.c index dcaf98368bf6f06c8d8ab9ac410f9e49c4de36a8..4f416670441500bb0f9f2ee2a68b347369278c15 100644 --- a/gnot/chan.c +++ b/gnot/chan.c @@ -511,6 +511,8 @@ namec(char *name, int amode, int omode, ulong perm) c = nc; Open: c = (*devtab[c->type].open)(c, omode); + if(omode & OCEXEC) + c->flag |= CCEXEC; break; case Amount: @@ -533,6 +535,8 @@ namec(char *name, int amode, int omode, ulong perm) if((c->flag&(CMOUNT|CCREATE)) == CMOUNT) c = createdir(c); (*devtab[c->type].create)(c, elem, omode, perm); + if(omode & OCEXEC) + c->flag |= CCEXEC; break; default: diff --git a/gnot/dat.h b/gnot/dat.h index 9461f44c71096810549a4caf0123243dad2f2d64..487b595d57999ee653e69d08b66a7c825442c841 100644 --- a/gnot/dat.h +++ b/gnot/dat.h @@ -491,6 +491,7 @@ extern char *statename[]; #define COPEN 1 /* for i/o */ #define CMOUNT 2 /* is result of a mount/bind */ #define CCREATE 4 /* permits creation if CMOUNT */ +#define CCEXEC 8 /* close on exec */ /* * Proc.time diff --git a/gnot/fns.h b/gnot/fns.h index 806888e8949b1dc773ec2767f6ed8fb14112e446..bacd1ef504f53f5e011d516a953aa54b0704b622 100644 --- a/gnot/fns.h +++ b/gnot/fns.h @@ -42,6 +42,7 @@ void envpgclose(Env *); void error(Chan*, int); void exit(void); void fault(Ureg*, FFrame*); +void fdclose(int); Chan* fdtochan(int, int); void firmware(void); void flowctl(Queue*); diff --git a/gnot/l.s b/gnot/l.s index bcf958f9036c7888a823db702c1a6cc127a6a73e..09ea1146c1f71a9648a9a149e4c553ab5f8907c1 100644 --- a/gnot/l.s +++ b/gnot/l.s @@ -104,6 +104,17 @@ TEXT tas(SB), $0 tas_1: RTS +TEXT rfnote(SB), $0 + + MOVL uregpp+0(FP), A0 + MOVL (A0), A7 + MOVL A7, -(A7) + MOVL ((1+8+8)*BY2WD)(A7), A0 + MOVL A0, USP + MOVL ((1+8+6)*BY2WD)(A7), A6 + ADDL $((1+8+8+1)*4), A7 + RTE + TEXT illegal(SB), $0 SUBL $((8+8+1)*BY2WD), A7 diff --git a/gnot/lib.h b/gnot/lib.h index c180289a2c6543f253a452045902b31b30d4e22e..0a4f5906457259c13b30a14d4da02792c704d32a 100644 --- a/gnot/lib.h +++ b/gnot/lib.h @@ -71,6 +71,8 @@ extern long end; #define ORDWR 2 /* read and write */ #define OEXEC 3 /* execute, == read but check execute permission */ #define OTRUNC 16 /* or'ed in (except for exec), truncate file first */ +#define OCEXEC 32 /* or'ed in, close on exec */ +#define ORCLOSE 64 /* or'ed in, remove on close */ typedef struct Error Error; typedef struct Dir Dir; diff --git a/gnot/sysfile.c b/gnot/sysfile.c index 1a73b5306c5011f87441d479cb4b10e6de411d6a..4062f883ad458ee3efe3c203121a59f0b854a06f 100644 --- a/gnot/sysfile.c +++ b/gnot/sysfile.c @@ -44,10 +44,10 @@ fdtochan(int fd, int mode) int openmode(ulong o) { - if(o >= (OTRUNC|OEXEC)) + if(o >= (OTRUNC|OCEXEC|ORCLOSE|OEXEC)) Err: error(0, Ebadarg); - o &= ~OTRUNC; + o &= ~(OTRUNC|OCEXEC|ORCLOSE); if(o > OEXEC) goto Err; if(o == OEXEC) diff --git a/gnot/sysproc.c b/gnot/sysproc.c index 50d9e0371545386110618b989451a6e4847d4c6c..f346eb8ee29b73361009c2b0ea4991ca50862b94 100644 --- a/gnot/sysproc.c +++ b/gnot/sysproc.c @@ -157,7 +157,7 @@ sysexec(ulong *arg) Seg *s; ulong l, t, d, b, v; int i; - Chan *tc; + Chan *tc, *c; Orig *o; char **argv, **argp; char *a, *charp, *file; @@ -288,6 +288,15 @@ sysexec(ulong *arg) */ freesegs(ESEG); + /* + * Close on exec + */ + for(i=0; i<=u->maxfd; i++) + if((c=u->fd[i]) && c->flag&CCEXEC){ + close(c); + fdclose(i); + } + /* * Text. Shared. */ diff --git a/gnot/trap.c b/gnot/trap.c index d03e903e77f8504908dcc707823b021937bb6a0e..7aae8ca8e840f4cb632356c2a814447983f122fd 100644 --- a/gnot/trap.c +++ b/gnot/trap.c @@ -156,8 +156,7 @@ notify(Ureg *ur) if(!u->notified){ if(!u->notify) goto Die; - #ifdef asdfasdf - sp = ur->sp; + sp = ur->usp; sp -= sizeof(Ureg); u->ureg = (void*)sp; memcpy((Ureg*)sp, ur, sizeof(Ureg)); @@ -167,13 +166,11 @@ notify(Ureg *ur) *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ *(ulong*)(sp+1*BY2WD) = (ulong)u->ureg; /* arg 1 is ureg* */ *(ulong*)(sp+0*BY2WD) = 0; /* arg 0 is pc */ - ur->sp = sp; + ur->usp = sp; ur->pc = (ulong)u->notify; u->notified = 1; u->nnote--; memcpy(&u->note[0], &u->note[1], u->nnote*sizeof(Note)); - #endif - panic("notify"); } unlock(&u->p->debug); } @@ -184,7 +181,6 @@ notify(Ureg *ur) void noted(Ureg **urp) { - #ifdef asdfasdf lock(&u->p->debug); if(!u->notified){ unlock(&u->p->debug); @@ -195,8 +191,6 @@ noted(Ureg **urp) unlock(&u->p->debug); splhi(); rfnote(urp); - #endif - panic("noted"); } #undef CHDIR /* BUG */ @@ -206,7 +200,7 @@ typedef long Syscall(ulong*); Syscall sysr1, sysfork, sysexec, sysgetpid, syssleep, sysexits, syslasterr, syswait; Syscall sysopen, sysclose, sysread, syswrite, sysseek, syserrstr, sysaccess, sysstat, sysfstat; Syscall sysdup, syschdir, sysforkpgrp, sysbind, sysmount, syspipe, syscreate, sysuserstr; -Syscall sysbrk_, sysremove, syswstat, sysfwstat; +Syscall sysbrk_, sysremove, syswstat, sysfwstat, sysnotify, sysnoted; Syscall *systab[]={ sysr1, @@ -237,6 +231,8 @@ Syscall *systab[]={ sysremove, syswstat, sysfwstat, + sysnotify, + sysnoted, }; long diff --git a/port/chan.c b/port/chan.c index 639223fe60e2b844e264cb43deebab12cf47ab96..4f416670441500bb0f9f2ee2a68b347369278c15 100644 --- a/port/chan.c +++ b/port/chan.c @@ -447,7 +447,7 @@ namec(char *name, int amode, int omode, ulong perm) mntok = 0; if(!((ulong)name & KZERO)) validaddr((ulong)(name+1), 2, 0); - if(name[1]=='|' || ('A'<=name[1] && name[1]<='Z')) + if(name[1]=='|' || name[1]=='M') error(0, Enonexist); t = devno(name[1], 1); if(t == -1) @@ -511,6 +511,8 @@ namec(char *name, int amode, int omode, ulong perm) c = nc; Open: c = (*devtab[c->type].open)(c, omode); + if(omode & OCEXEC) + c->flag |= CCEXEC; break; case Amount: @@ -533,6 +535,8 @@ namec(char *name, int amode, int omode, ulong perm) if((c->flag&(CMOUNT|CCREATE)) == CMOUNT) c = createdir(c); (*devtab[c->type].create)(c, elem, omode, perm); + if(omode & OCEXEC) + c->flag |= CCEXEC; break; default: diff --git a/port/lib.h b/port/lib.h index c180289a2c6543f253a452045902b31b30d4e22e..0a4f5906457259c13b30a14d4da02792c704d32a 100644 --- a/port/lib.h +++ b/port/lib.h @@ -71,6 +71,8 @@ extern long end; #define ORDWR 2 /* read and write */ #define OEXEC 3 /* execute, == read but check execute permission */ #define OTRUNC 16 /* or'ed in (except for exec), truncate file first */ +#define OCEXEC 32 /* or'ed in, close on exec */ +#define ORCLOSE 64 /* or'ed in, remove on close */ typedef struct Error Error; typedef struct Dir Dir; diff --git a/port/sysfile.c b/port/sysfile.c index 1a73b5306c5011f87441d479cb4b10e6de411d6a..4062f883ad458ee3efe3c203121a59f0b854a06f 100644 --- a/port/sysfile.c +++ b/port/sysfile.c @@ -44,10 +44,10 @@ fdtochan(int fd, int mode) int openmode(ulong o) { - if(o >= (OTRUNC|OEXEC)) + if(o >= (OTRUNC|OCEXEC|ORCLOSE|OEXEC)) Err: error(0, Ebadarg); - o &= ~OTRUNC; + o &= ~(OTRUNC|OCEXEC|ORCLOSE); if(o > OEXEC) goto Err; if(o == OEXEC) diff --git a/port/sysproc.c b/port/sysproc.c index 1760edf1744626d5bcc7d48cff5de579833ecc16..ec664417d23ce326386049a10534ec7d92e446f9 100644 --- a/port/sysproc.c +++ b/port/sysproc.c @@ -157,7 +157,7 @@ sysexec(ulong *arg) Seg *s; ulong l, t, d, b, v; int i; - Chan *tc; + Chan *tc, *c; Orig *o; char **argv, **argp; char *a, *charp, *file; @@ -288,6 +288,15 @@ sysexec(ulong *arg) */ freesegs(ESEG); + /* + * Close on exec + */ + for(i=0; i<=u->maxfd; i++) + if((c=u->fd[i]) && c->flag&CCEXEC){ + close(c); + fdclose(i); + } + /* * Text. Shared. */ diff --git a/power/dat.h b/power/dat.h index 86ca8af6329a795accdb3f08f1a3f9c7a547f2e5..adad371fda02d1bd9616291f9d26d5a1b072a56c 100644 --- a/power/dat.h +++ b/power/dat.h @@ -634,6 +634,7 @@ extern char *statename[]; #define COPEN 1 /* for i/o */ #define CMOUNT 2 /* is result of a mount/bind */ #define CCREATE 4 /* permits creation if CMOUNT */ +#define CCEXEC 8 /* close on exec */ /* * Proc.time diff --git a/power/devhs.c b/power/devhs.c index 05aa23fa724d88392e99d6e263f742aa77caabfb..4a5ee9c5d2cab255a5d50f792c7525a0cc19ba69 100644 --- a/power/devhs.c +++ b/power/devhs.c @@ -484,10 +484,6 @@ hsvmekproc(void *arg) return; } - /* - * if we loop many times without finding a character, sleep - */ - for(miss = 0; miss < 10; miss++){ /* * 0xFFFF means an empty fifo */ @@ -517,7 +513,6 @@ hsvmekproc(void *arg) upstream(hp, 0); } } - } qunlock(hp); /* diff --git a/power/fns.h b/power/fns.h index 4cfdc937dca57fc266b77c3410cd0c72e3e5f7c7..1d4a84fc051fa80dbeaa2ad8110a1c70155f0d36 100644 --- a/power/fns.h +++ b/power/fns.h @@ -53,6 +53,7 @@ void error(Chan*, int); void evenaddr(ulong); void exit(void); void fault(Ureg*, int, int); +void fdclose(int); Chan* fdtochan(int, int); void firmware(void); void flowctl(Queue*); diff --git a/power/trap.c b/power/trap.c index 741f4eb2b262ed51983af215889d35a6582625b8..b1bf531e4c4eba9af03756d460297d486c26c238 100644 --- a/power/trap.c +++ b/power/trap.c @@ -342,7 +342,7 @@ notify(Ureg *ur) if(!u->notified){ if(!u->notify) goto Die; - sp = ur->sp; + sp = ur->usp; sp -= sizeof(Ureg); u->ureg = (void*)sp; memcpy((Ureg*)sp, ur, sizeof(Ureg)); @@ -352,7 +352,7 @@ notify(Ureg *ur) *(ulong*)(sp+2*BY2WD) = sp+3*BY2WD; /* arg 2 is string */ *(ulong*)(sp+1*BY2WD) = (ulong)u->ureg; /* arg 1 is ureg* */ *(ulong*)(sp+0*BY2WD) = 0; /* arg 0 is pc */ - ur->sp = sp; + ur->usp = sp; ur->pc = (ulong)u->notify; u->notified = 1; u->nnote--;