From 69439fae6705a125047246c889384ed3aeb4d104 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 00:06:35 -0500 Subject: 9c: use -fcommon for clang Fixes #469. --- bin/9c | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/9c b/bin/9c index 59adda7f..9dfc082e 100755 --- a/bin/9c +++ b/bin/9c @@ -83,6 +83,7 @@ useclang() -Wno-unneeded-internal-declaration \ -fsigned-char \ -fno-caret-diagnostics \ + -fcommon \ " cflags="$cflags -g" cflags="$cflags $CC9FLAGS" -- cgit v1.2.3 From 5b37d9126474864b5299426e27b2af37fcc96dd0 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 00:06:35 -0500 Subject: libthread: delete NetBSD special case I added a direct call from thread.c to pthread.c's _threadpthreadstart in May, and no one has complained about NetBSD being broken. So probably no one is using this on NetBSD at all. Make pthread the only option. --- src/libthread/NetBSD-386-asm.s | 7 - src/libthread/NetBSD-power-asm.s | 16 -- src/libthread/NetBSD.c | 437 --------------------------------------- src/libthread/sysofiles.sh | 9 +- 4 files changed, 4 insertions(+), 465 deletions(-) delete mode 100644 src/libthread/NetBSD-386-asm.s delete mode 100644 src/libthread/NetBSD-power-asm.s delete mode 100644 src/libthread/NetBSD.c diff --git a/src/libthread/NetBSD-386-asm.s b/src/libthread/NetBSD-386-asm.s deleted file mode 100644 index 197f12b5..00000000 --- a/src/libthread/NetBSD-386-asm.s +++ /dev/null @@ -1,7 +0,0 @@ -.globl _tas -_tas: - movl $0xCAFEBABE, %eax - movl 4(%esp), %ecx - xchgl %eax, 0(%ecx) - ret - diff --git a/src/libthread/NetBSD-power-asm.s b/src/libthread/NetBSD-power-asm.s deleted file mode 100644 index d6e21c15..00000000 --- a/src/libthread/NetBSD-power-asm.s +++ /dev/null @@ -1,16 +0,0 @@ - .globl _tas -_tas: - li %r0, 0 - mr %r4, %r3 - lis %r5, 0xcafe - ori %r5, %r5, 0xbabe -1: - lwarx %r3, %r0, %r4 - cmpwi %r3, 0 - bne 2f - stwcx. %r5, %r0, %r4 - bne- 1b -2: - sync - blr - diff --git a/src/libthread/NetBSD.c b/src/libthread/NetBSD.c deleted file mode 100644 index 2b14146b..00000000 --- a/src/libthread/NetBSD.c +++ /dev/null @@ -1,437 +0,0 @@ -#include "threadimpl.h" - -#undef exits -#undef _exits - -static int -timefmt(Fmt *fmt) -{ - static char *mon[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - vlong ns; - Tm tm; - ns = nsec(); - tm = *localtime(time(0)); - return fmtprint(fmt, "%s %2d %02d:%02d:%02d.%03d", - mon[tm.mon], tm.mday, tm.hour, tm.min, tm.sec, - (int)(ns%1000000000)/1000000); -} - -/* - * spin locks - */ -extern int _tas(int*); - -void -_threadunlock(Lock *l, ulong pc) -{ - USED(pc); - - l->held = 0; -} - -int -_threadlock(Lock *l, int block, ulong pc) -{ - int i; -static int first=1; -if(first) {first=0; fmtinstall('\001', timefmt);} - - USED(pc); - - /* once fast */ - if(!_tas(&l->held)) - return 1; - if(!block) - return 0; - - /* a thousand times pretty fast */ - for(i=0; i<1000; i++){ - if(!_tas(&l->held)) - return 1; - sched_yield(); - } - /* now increasingly slow */ - for(i=0; i<10; i++){ - if(!_tas(&l->held)) - return 1; - usleep(1); - } -fprint(2, "%\001 %s: lock loop1 %p from %lux\n", argv0, l, pc); - for(i=0; i<10; i++){ - if(!_tas(&l->held)) - return 1; - usleep(10); - } -fprint(2, "%\001 %s: lock loop2 %p from %lux\n", argv0, l, pc); - for(i=0; i<10; i++){ - if(!_tas(&l->held)) - return 1; - usleep(100); - } -fprint(2, "%\001 %s: lock loop3 %p from %lux\n", argv0, l, pc); - for(i=0; i<10; i++){ - if(!_tas(&l->held)) - return 1; - usleep(1000); - } -fprint(2, "%\001 %s: lock loop4 %p from %lux\n", argv0, l, pc); - for(i=0; i<10; i++){ - if(!_tas(&l->held)) - return 1; - usleep(10*1000); - } -fprint(2, "%\001 %s: lock loop5 %p from %lux\n", argv0, l, pc); - for(i=0; i<1000; i++){ - if(!_tas(&l->held)) - return 1; - usleep(100*1000); - } -fprint(2, "%\001 %s: lock loop6 %p from %lux\n", argv0, l, pc); - /* take your time */ - while(_tas(&l->held)) - usleep(1000*1000); - return 1; -} - -/* - * sleep and wakeup - */ -static void -ign(int x) -{ - USED(x); -} - -static void /*__attribute__((constructor))*/ -ignusr1(int restart) -{ - struct sigaction sa; - - memset(&sa, 0, sizeof sa); - sa.sa_handler = ign; - sigemptyset(&sa.sa_mask); - sigaddset(&sa.sa_mask, SIGUSR1); - if(restart) - sa.sa_flags = SA_RESTART; - sigaction(SIGUSR1, &sa, nil); -} - -void -_procsleep(_Procrendez *r) -{ - sigset_t mask; - - /* - * Go to sleep. - * - * Block USR1, set the handler to interrupt system calls, - * unlock the vouslock so our waker can wake us, - * and then suspend. - */ -again: - r->asleep = 1; - r->pid = getpid(); - - sigprocmask(SIG_SETMASK, nil, &mask); - sigaddset(&mask, SIGUSR1); - sigprocmask(SIG_SETMASK, &mask, nil); - ignusr1(0); - unlock(r->l); - sigdelset(&mask, SIGUSR1); - sigsuspend(&mask); - - /* - * We're awake. Make USR1 not interrupt system calls. - */ - lock(r->l); - ignusr1(1); - if(r->asleep && r->pid == getpid()){ - /* Didn't really wake up - signal from something else */ - goto again; - } -} - -void -_procwakeupandunlock(_Procrendez *r) -{ - int pid; - - pid = 0; - if(r->asleep){ - r->asleep = 0; - assert(r->pid >= 1); - pid = r->pid; - } - assert(r->l); - unlock(r->l); - if(pid) - kill(pid, SIGUSR1); -} - -/* - * process creation and exit - */ -typedef struct Stackfree Stackfree; -struct Stackfree -{ - Stackfree *next; - int pid; - int pid1; -}; -static Lock stacklock; -static Stackfree *stackfree; - -static void -delayfreestack(uchar *stk, int pid, int pid1) -{ - Stackfree *sf; - - sf = (Stackfree*)stk; - sf->pid = pid; - sf->pid1 = pid1; - lock(&stacklock); - sf->next = stackfree; - stackfree = sf; - unlock(&stacklock); -} - -static void -dofreestacks(void) -{ - Stackfree *sf, *last, *next; - - if(stackfree==nil || !canlock(&stacklock)) - return; - - for(last=nil,sf=stackfree; sf; last=sf,sf=next){ - next = sf->next; - if(sf->pid >= 1 && kill(sf->pid, 0) < 0 && errno == ESRCH) - if(sf->pid1 >= 1 && kill(sf->pid1, 0) < 0 && errno == ESRCH){ - free(sf); - if(last) - last->next = next; - else - stackfree = next; - sf = last; - } - } - unlock(&stacklock); -} - -static int -startprocfn(void *v) -{ - void **a; - uchar *stk; - void (*fn)(void*); - Proc *p; - int pid0, pid1; - - a = (void**)v; - fn = a[0]; - p = a[1]; - stk = a[2]; - pid0 = (int)a[4]; - pid1 = getpid(); - free(a); - p->osprocid = pid1; - - (*fn)(p); - - delayfreestack(stk, pid0, pid1); - _exit(0); - return 0; -} - -/* - * indirect through here so that parent need not wait for child zombie - * - * slight race - if child exits and then another process starts before we - * manage to exit, we'll be running on a freed stack. - */ -static int -trampnowait(void *v) -{ - void **a; - int *kidpid; - - a = (void*)v; - kidpid = a[3]; - a[4] = (void*)getpid(); - *kidpid = clone(startprocfn, a[2]+65536-512, CLONE_VM|CLONE_FILES, a); - _exit(0); - return 0; -} - -void -_procstart(Proc *p, void (*fn)(Proc*)) -{ - void **a; - uchar *stk; - int pid, kidpid, status; - - dofreestacks(); - a = malloc(5*sizeof a[0]); - if(a == nil) - sysfatal("_procstart malloc: %r"); - stk = malloc(65536); - if(stk == nil) - sysfatal("_procstart malloc stack: %r"); - - a[0] = fn; - a[1] = p; - a[2] = stk; - a[3] = &kidpid; - kidpid = -1; - - pid = clone(trampnowait, stk+65536-16, CLONE_VM|CLONE_FILES, a); - if(pid > 0) - if(wait4(pid, &status, __WALL, 0) < 0) - fprint(2, "ffork wait4: %r\n"); - if(pid < 0 || kidpid < 0){ - fprint(2, "_procstart clone: %r\n"); - abort(); - } -} - -static char *threadexitsmsg; -void -sigusr2handler(int s) -{ -/* fprint(2, "%d usr2 %d\n", time(0), getpid()); */ - if(threadexitsmsg) - _exits(threadexitsmsg); -} - -void -threadexitsall(char *msg) -{ - static int pid[1024]; - int i, npid, mypid; - Proc *p; - - if(msg == nil) - msg = ""; - - /* - * Only one guy, ever, gets to run this. - * If two guys do it, inevitably they end up - * tripping over each other in the underlying - * C library exit() implementation, which is - * trying to run the atexit handlers and apparently - * not thread safe. This has been observed on - * both Linux and OpenBSD. Sigh. - */ - { - static Lock onelock; - if(!canlock(&onelock)) - _exits(threadexitsmsg); - threadexitsmsg = msg; - } - - mypid = getpid(); - lock(&_threadprocslock); - npid = 0; - for(p=_threadprocs; p; p=p->next) - if(p->osprocid != mypid && p->osprocid >= 1) - pid[npid++] = p->osprocid; - for(i=0; ipid == pid) - return p; - if(p->pid == 0){ - print("found 0 at %d (h=%d)\n", (i+h)%nelem(perproc), h); - break; - } - } - fprint(2, "myperproc %d (%s): cannot find self\n", pid, argv0); - abort(); - return nil; -} - -static Perproc* -newperproc(void) -{ - int i, pid, h; - Perproc *p; - - lock(&perlock); - pid = getpid(); - h = pid%nelem(perproc); - for(i=0; ipid == pid || p->pid == -1 || p->pid == 0){ - p->pid = pid; - unlock(&perlock); - return p; - } - } - fprint(2, "newperproc %d: out of procs\n", pid); - abort(); - return nil; -} - -Proc* -_threadproc(void) -{ - return myperproc()->proc; -} - -void -_threadsetproc(Proc *p) -{ - Perproc *pp; - - if(p) - p->osprocid = getpid(); - pp = newperproc(); - pp->proc = p; - if(p == nil) - pp->pid = -1; -} - -void -_pthreadinit(void) -{ - signal(SIGUSR2, sigusr2handler); -} - -void -_threadpexit(void) -{ - _exit(0); -} diff --git a/src/libthread/sysofiles.sh b/src/libthread/sysofiles.sh index 833afbe0..cf9e0234 100644 --- a/src/libthread/sysofiles.sh +++ b/src/libthread/sysofiles.sh @@ -2,15 +2,14 @@ test -f $PLAN9/config && . $PLAN9/config +echo pthread.o + case "$SYSNAME" in -NetBSD) - echo ${SYSNAME}-${OBJTYPE}-asm.o $SYSNAME.o stkmalloc.o - ;; OpenBSD) - echo pthread.o stkmmap.o + echo stkmmap.o ;; *) - echo pthread.o stkmalloc.o + echo stkmalloc.o esac # Various libc don't supply swapcontext, makecontext, so we do. -- cgit v1.2.3 From b3a20a96eb2b91a5b0b8a8fb506e20a2fb50ebe8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 00:10:11 -0500 Subject: libthread: add threadmaybackground Programs that want to background themselves now need to define threadmaybackground returning 1. This avoids a confusing (to people and debuggers) extra parent process for all the threaded programs that will never want to background themselves. --- include/thread.h | 7 +++++-- man/man3/thread.3 | 34 ++++++++++++++++++++++------------ src/cmd/9pfuse/main.c | 6 ++++++ src/cmd/9pserve.c | 6 ++++++ src/cmd/auth/factotum/main.c | 6 ++++++ src/cmd/auth/ssh-agent.c | 6 ++++++ src/cmd/fossil/fossil.c | 6 ++++++ src/cmd/import.c | 6 ++++++ src/cmd/ndb/dns.c | 6 ++++++ src/cmd/plumb/plumber.c | 6 ++++++ src/cmd/smugfs/main.c | 6 ++++++ src/cmd/upas/fs/fs.c | 6 ++++++ src/cmd/upas/nfs/main.c | 6 ++++++ src/cmd/venti/srv/venti.c | 6 ++++++ src/lib9p/ramfs.c | 6 ++++++ src/libthread/bg.c | 7 +++++++ src/libthread/daemonize.c | 12 ++++++------ src/libthread/mkfile | 1 + src/libthread/thread.c | 2 +- 19 files changed, 120 insertions(+), 21 deletions(-) create mode 100644 src/libthread/bg.c diff --git a/include/thread.h b/include/thread.h index c01cd516..8c800829 100644 --- a/include/thread.h +++ b/include/thread.h @@ -1,7 +1,7 @@ #ifndef _THREAD_H_ #define _THREAD_H_ 1 #if defined(__cplusplus) -extern "C" { +extern "C" { #endif AUTOLIB(thread) @@ -15,6 +15,7 @@ void threadexits(char *); void threadexitsall(char *); void threadsetname(char*, ...); void threadsetstate(char*, ...); +void threadneedbackground(void); char *threadgetname(void); int threadyield(void); int threadidle(void); @@ -60,6 +61,8 @@ void **threaddata(void); void threadmain(int argc, char *argv[]); extern int mainstacksize; +int threadmaybackground(void); + /* * channel communication */ @@ -180,7 +183,7 @@ int threadspawnl(int[3], char*, ...); Channel* threadwaitchan(void); /* - * alternate interface to threadwaitchan - don't use both! + * alternate interface to threadwaitchan - don't use both! */ Waitmsg* procwait(int pid); diff --git a/man/man3/thread.3 b/man/man3/thread.3 index 6c6b4602..02e4c868 100644 --- a/man/man3/thread.3 +++ b/man/man3/thread.3 @@ -33,6 +33,7 @@ threadintgrp, threadkill, threadkillgrp, threadmain, +threadmaybackground, threadnotify, threadid, threadpid, @@ -80,6 +81,7 @@ struct Alt { .ft L .ta \w'\fLChannel* 'u +4n +4n +4n +4n void threadmain(int argc, char *argv[]) +int threadmaybackground(void) int mainstacksize int proccreate(void (*fn)(void*), void *arg, uint stacksize) int threadcreate(void (*fn)(void*), void *arg, uint stacksize) @@ -171,7 +173,7 @@ initialized to the desired value .BR 1024 ). When using the .I pthread -library, +library, .B mainstacksize is ignored, as is the stack size argument to .BR proccreate : @@ -185,7 +187,7 @@ executes .I fn(arg) on a stack of size .IR stacksize . -Thread stacks are allocated in shared memory, making it valid to pass +Thread stacks are allocated in shared memory, making it valid to pass pointers to stack variables between threads and procs. .I Proccreate creates a new proc, and inside that proc creates @@ -207,7 +209,7 @@ returning the id of the created thread. .\" in .\" .IR rforkflag .) .\" .I Proccreate -.\" is identical to +.\" is identical to .\" .I procrfork .\" with .\" .I rforkflag @@ -238,6 +240,14 @@ When the last thread in .IR threadmain 's proc exits, the program will appear to its parent to have exited. The remaining procs will still run together, but as a background program. +This functionality can only be relied upon if the program defines a function +.I threadmaybackground +returning a non-zero result. +Programs that do not define such a +.I threadmaybackground +will crash instead should the last thread in +.IR threadmain 's +proc exit leaving behind other running procs. .PP The threads in a proc are coroutines, scheduled nonpreemptively in a round-robin fashion. @@ -341,18 +351,18 @@ Also for debugging, threads have a string state associated with them. .I Threadsetstate sets the state string. -There is no +There is no .IR threadgetstate ; since the thread scheduler resets the state to .B Running -every time it runs the thread, +every time it runs the thread, it is only useful for debuggers to inspect the state. .PP .I Threaddata returns a pointer to a per-thread pointer that may be modified by threaded programs for per-thread storage. -Similarly, +Similarly, .I procdata returns a pointer to a per-proc pointer. .PP @@ -398,11 +408,11 @@ response. .I Threadexecl and .I threadexec -will duplicate +will duplicate (see .MR dup (3) ) the three file descriptors in -.I fd +.I fd onto standard input, output, and error for the external program and then close them in the calling thread. Beware of code that sets @@ -467,9 +477,9 @@ operation blocks until the corresponding operation occurs and .IR "vice versa" . .IR Chancreate -allocates a new channel +allocates a new channel for messages of size -.I elsize +.I elsize and with a buffer holding .I nel messages. @@ -645,7 +655,7 @@ from the main proc before any other procs have been created. To create new processes, use .IR proccreate . .\" .PP -.\" It is safe to use +.\" It is safe to use .\" .IR rfork .\" (see .\" .IR fork (3)) @@ -663,7 +673,7 @@ To create new processes, use .\" .BR RFCENVG. .\" (To create new processes, use .\" .I proccreate -.\" and +.\" and .\" .IR procrfork .) .\" As mentioned above, .\" the thread library depends on all procs being in the diff --git a/src/cmd/9pfuse/main.c b/src/cmd/9pfuse/main.c index 69d1ad75..4fa330a0 100644 --- a/src/cmd/9pfuse/main.c +++ b/src/cmd/9pfuse/main.c @@ -98,6 +98,12 @@ usage(void) void fusereader(void*); void watchfd(void*); +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/9pserve.c b/src/cmd/9pserve.c index 255bcbb2..e26eef14 100644 --- a/src/cmd/9pserve.c +++ b/src/cmd/9pserve.c @@ -137,6 +137,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + uchar vbuf[128]; extern int _threaddebuglevel; void diff --git a/src/cmd/auth/factotum/main.c b/src/cmd/auth/factotum/main.c index b3ace12c..6dfc2a40 100644 --- a/src/cmd/auth/factotum/main.c +++ b/src/cmd/auth/factotum/main.c @@ -20,6 +20,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/auth/ssh-agent.c b/src/cmd/auth/ssh-agent.c index c3b0c7ef..e944e390 100644 --- a/src/cmd/auth/ssh-agent.c +++ b/src/cmd/auth/ssh-agent.c @@ -90,6 +90,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/fossil/fossil.c b/src/cmd/fossil/fossil.c index 002e8510..c5672c86 100644 --- a/src/cmd/fossil/fossil.c +++ b/src/cmd/fossil/fossil.c @@ -59,6 +59,12 @@ readCmdPart(char *file, char ***pcmd, int *pncmd) *pncmd = ncmd; } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char* argv[]) { diff --git a/src/cmd/import.c b/src/cmd/import.c index 0be2f5b6..7da70966 100644 --- a/src/cmd/import.c +++ b/src/cmd/import.c @@ -51,6 +51,12 @@ fatal(char *fmt, ...) threadexitsall("fatal"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/ndb/dns.c b/src/cmd/ndb/dns.c index cb317052..723989b9 100644 --- a/src/cmd/ndb/dns.c +++ b/src/cmd/ndb/dns.c @@ -121,6 +121,12 @@ checkaddress(void) fprint(2, "warning: announce mismatch %s %s\n", udpaddr, tcpaddr); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/plumb/plumber.c b/src/cmd/plumb/plumber.c index c99282f0..5ead2e93 100644 --- a/src/cmd/plumb/plumber.c +++ b/src/cmd/plumb/plumber.c @@ -26,6 +26,12 @@ makeports(Ruleset *rules[]) addport(rules[i]->port); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/smugfs/main.c b/src/cmd/smugfs/main.c index e1c2745f..31c9a752 100644 --- a/src/cmd/smugfs/main.c +++ b/src/cmd/smugfs/main.c @@ -51,6 +51,12 @@ smuglogin(void) printerrors = 0; } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/upas/fs/fs.c b/src/cmd/upas/fs/fs.c index dc6ff3ba..32968e67 100644 --- a/src/cmd/upas/fs/fs.c +++ b/src/cmd/upas/fs/fs.c @@ -155,6 +155,12 @@ notifyf(void *a, char *s) noted(NDFLT); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/upas/nfs/main.c b/src/cmd/upas/nfs/main.c index c72a4849..68ae141b 100644 --- a/src/cmd/upas/nfs/main.c +++ b/src/cmd/upas/nfs/main.c @@ -26,6 +26,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/cmd/venti/srv/venti.c b/src/cmd/venti/srv/venti.c index 1725537a..67fda91e 100644 --- a/src/cmd/venti/srv/venti.c +++ b/src/cmd/venti/srv/venti.c @@ -23,6 +23,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/lib9p/ramfs.c b/src/lib9p/ramfs.c index b7a07c7d..7cf6489d 100644 --- a/src/lib9p/ramfs.c +++ b/src/lib9p/ramfs.c @@ -125,6 +125,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char **argv) { diff --git a/src/libthread/bg.c b/src/libthread/bg.c new file mode 100644 index 00000000..2edbc0e4 --- /dev/null +++ b/src/libthread/bg.c @@ -0,0 +1,7 @@ +#include "threadimpl.h" + +int +threadmaybackground(void) +{ + return 0; +} diff --git a/src/libthread/daemonize.c b/src/libthread/daemonize.c index 387d1527..f994ffe1 100644 --- a/src/libthread/daemonize.c +++ b/src/libthread/daemonize.c @@ -8,7 +8,7 @@ #undef wait static int sigpid; -static int threadpassfd; +static int threadpassfd = -1; static int gotsigchld; static void @@ -163,9 +163,9 @@ _threadsetupdaemonize(void) void _threaddaemonize(void) { - if(threadpassfd >= 0){ - write(threadpassfd, "0", 1); - close(threadpassfd); - threadpassfd = -1; - } + if(threadpassfd < 0) + sysfatal("threads in main proc exited w/o threadmaybackground"); + write(threadpassfd, "0", 1); + close(threadpassfd); + threadpassfd = -1; } diff --git a/src/libthread/mkfile b/src/libthread/mkfile index 8a77a316..eca4f4df 100644 --- a/src/libthread/mkfile +++ b/src/libthread/mkfile @@ -4,6 +4,7 @@ SYSOFILES=`{sh ./sysofiles.sh} LIB=libthread.a OFILES=\ $SYSOFILES\ + bg.$O\ channel.$O\ daemonize.$O\ exec.$O\ diff --git a/src/libthread/thread.c b/src/libthread/thread.c index 65e65194..7151e875 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -844,7 +844,7 @@ main(int argc, char **argv) // Easier to just run in pthread-per-thread mode. pthreadperthread = 1; #endif - if(strstr(opts, "nodaemon") == nil && getenv("NOLIBTHREADDAEMONIZE") == nil) + if(threadmaybackground() && strstr(opts, "nodaemon") == nil && getenv("NOLIBTHREADDAEMONIZE") == nil) _threadsetupdaemonize(); threadargc = argc; -- cgit v1.2.3 From b73633b1b4e9d3dbd680edf900b2b53befbf5a9a Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 00:15:37 -0500 Subject: libthread: fix pthreadperthread bugs --- src/libthread/thread.c | 293 ++++++++++++++++++++++++++++----------------- src/libthread/threadimpl.h | 1 + 2 files changed, 187 insertions(+), 107 deletions(-) diff --git a/src/libthread/thread.c b/src/libthread/thread.c index 7151e875..94173ebc 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -1,6 +1,6 @@ #include "threadimpl.h" -int _threaddebuglevel; +int _threaddebuglevel = 0; static uint threadnproc; static uint threadnsysproc; @@ -20,13 +20,16 @@ static void contextswitch(Context *from, Context *to); static void procmain(Proc*); static void procscheduler(Proc*); static int threadinfo(void*, char*); +static void pthreadscheduler(Proc *p); +static void pthreadsleepschedlocked(Proc *p, _Thread *t); +static void pthreadwakeupschedlocked(Proc *p, _Thread *self, _Thread *t); +static _Thread* procnext(Proc*, _Thread*); static void -_threaddebug(char *fmt, ...) +_threaddebug(_Thread *t, char *fmt, ...) { va_list arg; char buf[128]; - _Thread *t; char *p; static int fd = -1; @@ -52,7 +55,8 @@ _threaddebug(char *fmt, ...) va_start(arg, fmt); vsnprint(buf, sizeof buf, fmt, arg); va_end(arg); - t = proc()->thread; + if(t == nil) + t = proc()->thread; if(t) fprint(fd, "%p %d.%d: %s\n", proc(), getpid(), t->id, buf); else @@ -181,10 +185,15 @@ _threadcreate(Proc *p, void (*fn)(void*), void *arg, uint stack) stack = 0; // not using it t = threadalloc(fn, arg, stack); t->proc = p; - if(p->nthread == 0) - p->thread0 = t; - else if(pthreadperthread) - _threadpthreadstart(p, t); + if(pthreadperthread) { + if(p->nthread != 0) + _threadpthreadstart(p, t); + else + t->mainthread = 1; + } else { + if(p->nthread == 0) + p->thread0 = t; + } p->nthread++; addthreadinproc(p, t); _threadready(t); @@ -197,6 +206,7 @@ threadcreate(void (*fn)(void*), void *arg, uint stack) _Thread *t; t = _threadcreate(proc(), fn, arg, stack); + _threaddebug(nil, "threadcreate %d", t->id); return t->id; } @@ -210,41 +220,11 @@ proccreate(void (*fn)(void*), void *arg, uint stack) p = procalloc(); t = _threadcreate(p, fn, arg, stack); id = t->id; /* t might be freed after _procstart */ + _threaddebug(t, "proccreate %p", p); _procstart(p, procmain); return id; } -// For pthreadperthread mode, procswitch flips -// between the threads. -static void -procswitch(Proc *p, _Thread *from, _Thread *to) -{ - _threaddebug("procswitch %p %d %d", p, from?from->id:-1, to?to->id:-1); - lock(&p->schedlock); - from->schedrend.l = &p->schedlock; - if(to) { - p->schedthread = to; - to->schedrend.l = &p->schedlock; - _threaddebug("procswitch wakeup %p %d", p, to->id); - _procwakeup(&to->schedrend); - } - if(p->schedthread != from) { - if(from->exiting) { - unlock(&p->schedlock); - _threadpexit(); - _threaddebug("procswitch exit wakeup!!!\n"); - } - while(p->schedthread != from) { - _threaddebug("procswitch sleep %p %d", p, from->id); - _procsleep(&from->schedrend); - _threaddebug("procswitch awake %p %d", p, from->id); - } - if(p->schedthread != from) - sysfatal("_procswitch %p %p oops", p->schedthread, from); - } - unlock(&p->schedlock); -} - void _threadswitch(void) { @@ -255,10 +235,10 @@ _threadswitch(void) /*print("threadswtch %p\n", p); */ - if(p->thread == p->thread0) + if(pthreadperthread) + pthreadscheduler(p); + else if(p->thread == p->thread0) procscheduler(p); - else if(pthreadperthread) - procswitch(p, p->thread, p->thread0); else contextswitch(&p->thread->context, &p->schedcontext); } @@ -390,7 +370,10 @@ void _threadpthreadmain(Proc *p, _Thread *t) { _threadsetproc(p); - procswitch(p, t, nil); + lock(&p->lock); + pthreadsleepschedlocked(p, t); + unlock(&p->lock); + _threaddebug(nil, "startfn"); t->startfn(t->startarg); threadexits(nil); } @@ -400,76 +383,47 @@ procscheduler(Proc *p) { _Thread *t; - _threaddebug("scheduler enter"); + _threaddebug(nil, "scheduler enter"); //print("s %p\n", p); -Top: - lock(&p->lock); - t = p->thread; - p->thread = nil; - if(t->exiting){ - delthreadinproc(p, t); - p->nthread--; -/*print("nthread %d\n", p->nthread); */ - _threadstkfree(t->stk, t->stksize); - /* - * Cannot free p->thread0 yet: it is used for the - * context switches back to the scheduler. - * Instead, we will free it at the end of this function. - * But all the other threads can be freed now. - */ - if(t != p->thread0) - free(t); - } - - for(;;){ - if((t = p->pinthread) != nil){ - while(!onlist(&p->runqueue, t)){ - p->runrend.l = &p->lock; - _threaddebug("scheduler sleep (pin)"); - _procsleep(&p->runrend); - _threaddebug("scheduler wake (pin)"); - } - }else - while((t = p->runqueue.head) == nil){ - if(p->nthread == 0) - goto Out; - if((t = p->idlequeue.head) != nil){ - /* - * Run all the idling threads once. - */ - while((t = p->idlequeue.head) != nil){ - delthread(&p->idlequeue, t); - addthread(&p->runqueue, t); - } - continue; - } - p->runrend.l = &p->lock; - _threaddebug("scheduler sleep"); - _procsleep(&p->runrend); - _threaddebug("scheduler wake"); + for(;;) { + /* Finish running current thread. */ + lock(&p->lock); + t = p->thread; + p->thread = nil; + if(t->exiting){ + delthreadinproc(p, t); + p->nthread--; + /*print("nthread %d\n", p->nthread); */ + _threadstkfree(t->stk, t->stksize); + /* + * Cannot free p->thread0 yet: it is used for the + * context switches back to the scheduler. + * Instead, we will free it at the end of this function. + * But all the other threads can be freed now. + */ + if(t != p->thread0) + free(t); } - if(p->pinthread && p->pinthread != t) - fprint(2, "p->pinthread %p t %p\n", p->pinthread, t); - assert(p->pinthread == nil || p->pinthread == t); - delthread(&p->runqueue, t); + + /* Pick next thread. */ + t = procnext(p, nil); + if(t == nil) + break; + _threaddebug(nil, "run %d (%s)", t->id, t->name); + //print("run %p %p %p %p\n", t, *(uintptr*)(t->context.uc.mc.sp), t->context.uc.mc.di, t->context.uc.mc.si); unlock(&p->lock); - p->thread = t; - p->nswitch++; - _threaddebug("run %d (%s)", t->id, t->name); -//print("run %p %p %p %p\n", t, *(uintptr*)(t->context.uc.mc.sp), t->context.uc.mc.di, t->context.uc.mc.si); + + /* Switch to next thread. */ if(t == p->thread0) return; - if(pthreadperthread) - procswitch(p, p->thread0, t); - else - contextswitch(&p->schedcontext, &t->context); - _threaddebug("back in scheduler"); -/*print("back in scheduler\n"); */ - goto Top; + contextswitch(&p->schedcontext, &t->context); + + _threaddebug(nil, "back in scheduler"); + /*print("back in scheduler\n"); */ } -Out: - _threaddebug("scheduler exit"); + /* No more threads in proc. Clean up. */ + _threaddebug(nil, "scheduler exit"); if(p->mainproc){ /* * Stupid bug - on Linux 2.6 and maybe elsewhere, @@ -502,6 +456,125 @@ Out: _threadpexit(); } +static void +pthreadsleepschedlocked(Proc *p, _Thread *t) +{ + _threaddebug(t, "pthreadsleepsched %p %d", p, t->id);; + t->schedrend.l = &p->lock; + while(p->schedthread != t) + _procsleep(&t->schedrend); +} + +static void +pthreadwakeupschedlocked(Proc *p, _Thread *self, _Thread *t) +{ + _threaddebug(self, "pthreadwakeupschedlocked %p %d", p, t->id);; + t->schedrend.l = &p->schedlock; + p->schedthread = t; + _procwakeup(&t->schedrend); +} + +static void +pthreadscheduler(Proc *p) +{ + _Thread *self, *t; + + _threaddebug(nil, "scheduler"); + lock(&p->lock); + self = p->thread; + p->thread = nil; + _threaddebug(self, "pausing"); + + if(self->exiting) { + _threaddebug(self, "exiting"); + delthreadinproc(p, self); + p->nthread--; + } + + t = procnext(p, self); + if(t != nil) { + pthreadwakeupschedlocked(p, self, t); + if(!self->exiting) { + pthreadsleepschedlocked(p, self); + _threaddebug(nil, "resume %d", self->id); + unlock(&p->lock); + return; + } + } + + if(t == nil) { + /* Tear down proc bookkeeping. Wait to free p. */ + delproc(p); + lock(&threadnproclock); + if(p->sysproc) + --threadnsysproc; + if(--threadnproc == threadnsysproc) + threadexitsall(p->msg); + unlock(&threadnproclock); + } + + /* Tear down pthread. */ + if(self->mainthread && p->mainproc) { + _threaddaemonize(); + _threaddebug(self, "sleeper"); + unlock(&p->lock); + /* + * Avoid bugs with main pthread exiting. + * When all procs are gone, threadexitsall above will happen. + */ + for(;;) + sleep(60*60*1000); + } + _threadsetproc(nil); + free(self); + unlock(&p->lock); + if(t == nil) + free(p); + _threadpexit(); +} + +static _Thread* +procnext(Proc *p, _Thread *self) +{ + _Thread *t; + + if((t = p->pinthread) != nil){ + while(!onlist(&p->runqueue, t)){ + p->runrend.l = &p->lock; + _threaddebug(self, "scheduler sleep (pin)"); + _procsleep(&p->runrend); + _threaddebug(self, "scheduler wake (pin)"); + } + } else + while((t = p->runqueue.head) == nil){ + if(p->nthread == 0) + return nil; + if((t = p->idlequeue.head) != nil){ + /* + * Run all the idling threads once. + */ + while((t = p->idlequeue.head) != nil){ + delthread(&p->idlequeue, t); + addthread(&p->runqueue, t); + } + continue; + } + p->runrend.l = &p->lock; + _threaddebug(self, "scheduler sleep"); + _procsleep(&p->runrend); + _threaddebug(self, "scheduler wake"); + } + + if(p->pinthread && p->pinthread != t) + fprint(2, "p->pinthread %p t %p\n", p->pinthread, t); + assert(p->pinthread == nil || p->pinthread == t); + delthread(&p->runqueue, t); + + p->thread = t; + p->nswitch++; + return t; +} + void _threadsetsysproc(void) { @@ -784,14 +857,18 @@ threadrwakeup(Rendez *r, int all, ulong pc) int i; _Thread *t; + _threaddebug(nil, "rwakeup %p %d", r, all); for(i=0;; i++){ if(i==1 && !all) break; if((t = r->waiting.head) == nil) break; + _threaddebug(nil, "rwakeup %p %d -> wake %d", r, all, t->id); delthread(&r->waiting, t); _threadready(t); + _threaddebug(nil, "rwakeup %p %d -> loop", r, all); } + _threaddebug(nil, "rwakeup %p %d -> total %d", r, all, i); return i; } @@ -827,6 +904,7 @@ int main(int argc, char **argv) { Proc *p; + _Thread *t; char *opts; argv0 = argv[0]; @@ -875,7 +953,8 @@ main(int argc, char **argv) if(mainstacksize == 0) mainstacksize = 256*1024; atnotify(threadinfo, 1); - _threadcreate(p, threadmainstart, nil, mainstacksize); + t = _threadcreate(p, threadmainstart, nil, mainstacksize); + t->mainthread = 1; procmain(p); sysfatal("procscheduler returned in threadmain!"); /* does not return */ diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h index 8d22a161..14646031 100644 --- a/src/libthread/threadimpl.h +++ b/src/libthread/threadimpl.h @@ -97,6 +97,7 @@ struct _Thread uchar *stk; uint stksize; int exiting; + int mainthread; Proc *proc; char name[256]; char state[256]; -- cgit v1.2.3 From e68f07d46f5f168dc2076286627279540bf1f99e Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 00:16:10 -0500 Subject: libthread: make pthreadperthread the default --- man/man3/thread.3 | 34 ++++++++++++++-------------------- src/libthread/thread.c | 2 +- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/man/man3/thread.3 b/man/man3/thread.3 index 02e4c868..c0a59091 100644 --- a/man/man3/thread.3 +++ b/man/man3/thread.3 @@ -158,27 +158,21 @@ by The thread library provides a .I main function that sets up a proc with a single thread executing -.I threadmain -on a stack of size -.I mainstacksize -(default eight kilobytes). -To set -.IR mainstacksize , -declare a global variable -initialized to the desired value -.RI ( e.g. , -.B int -.B mainstacksize -.B = -.BR 1024 ). -When using the +.IR threadmain . +.PP +Every thread is backed by an operating system-provided .I pthread -library, -.B mainstacksize -is ignored, as is the stack size argument to -.BR proccreate : -the first thread in each proc -runs on the native system stack. +and runs on its system-provided stack; +.I mainstacksize +and the the stack size arguments to +.I proccreate +and +.I threadcreate +are ignored. +Although each thread is backed by a separate +.IR pthread , +the threads in a proc are still scheduled non-preemptively +as on Plan 9 and as described below. .PP .I Threadcreate creates a new thread in the calling proc, returning a unique integer diff --git a/src/libthread/thread.c b/src/libthread/thread.c index 94173ebc..0c764000 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -7,7 +7,7 @@ static uint threadnsysproc; static Lock threadnproclock; static Ref threadidref; static Proc *threadmainproc; -static int pthreadperthread; +static int pthreadperthread = 1; static void addproc(Proc*); static void delproc(Proc*); -- cgit v1.2.3 From 18571208068d5fe2f0bf7b4e980525a7f577c503 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 07:18:30 -0500 Subject: libthread: simplify Now that everything uses pthreads and pthreadperthread, can delete various conditionals, all the custom context code, and so on. Also update documents. Fixes #355. --- include/libc.h | 2 - include/u.h | 7 +- src/libthread/386-ucontext.c | 22 -- src/libthread/386-ucontext.h | 119 --------- src/libthread/COPYING.SPARC64-CONTEXT | 458 ---------------------------------- src/libthread/COPYRIGHT | 9 - src/libthread/Linux-arm-asm.s | 41 --- src/libthread/Linux-sparc64-context.S | 135 ---------- src/libthread/OpenBSD-386-asm.s | 45 ---- src/libthread/OpenBSD-power-asm.S | 73 ------ src/libthread/OpenBSD-x86_64-asm.S | 44 ---- src/libthread/arm-ucontext.c | 24 -- src/libthread/mkfile | 3 +- src/libthread/power-ucontext.c | 26 -- src/libthread/power-ucontext.h | 36 --- src/libthread/sparc64-ucontext.c | 49 ---- src/libthread/stkmalloc.c | 13 - src/libthread/stkmmap.c | 25 -- src/libthread/sysofiles.sh | 27 -- src/libthread/thread.c | 217 +--------------- src/libthread/threadimpl.h | 44 ---- src/libthread/x86_64-ucontext.c | 28 --- src/libthread/x86_64-ucontext.h | 42 ---- 23 files changed, 12 insertions(+), 1477 deletions(-) delete mode 100644 src/libthread/386-ucontext.c delete mode 100644 src/libthread/386-ucontext.h delete mode 100644 src/libthread/COPYING.SPARC64-CONTEXT delete mode 100644 src/libthread/Linux-arm-asm.s delete mode 100644 src/libthread/Linux-sparc64-context.S delete mode 100644 src/libthread/OpenBSD-386-asm.s delete mode 100644 src/libthread/OpenBSD-power-asm.S delete mode 100644 src/libthread/OpenBSD-x86_64-asm.S delete mode 100644 src/libthread/arm-ucontext.c delete mode 100644 src/libthread/power-ucontext.c delete mode 100644 src/libthread/power-ucontext.h delete mode 100644 src/libthread/sparc64-ucontext.c delete mode 100644 src/libthread/stkmalloc.c delete mode 100644 src/libthread/stkmmap.c delete mode 100644 src/libthread/sysofiles.sh delete mode 100644 src/libthread/x86_64-ucontext.c delete mode 100644 src/libthread/x86_64-ucontext.h diff --git a/include/libc.h b/include/libc.h index 4bb537d6..1e24f0bb 100644 --- a/include/libc.h +++ b/include/libc.h @@ -473,10 +473,8 @@ extern _Thread *(*threadnow)(void); typedef struct Lock Lock; struct Lock { -#ifdef PLAN9PORT_USING_PTHREADS int init; pthread_mutex_t mutex; -#endif int held; }; diff --git a/include/u.h b/include/u.h index f84e348a..856e10f4 100644 --- a/include/u.h +++ b/include/u.h @@ -67,7 +67,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #if defined(__linux__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # if defined(__USE_MISC) # undef _NEEDUSHORT # undef _NEEDUINT @@ -76,7 +75,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #elif defined(__sun__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # undef _NEEDUSHORT # undef _NEEDUINT # undef _NEEDULONG @@ -84,7 +82,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #elif defined(__FreeBSD__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # include # if !defined(_POSIX_SOURCE) # undef _NEEDUSHORT @@ -93,7 +90,6 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #elif defined(__APPLE__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # if __GNUC__ < 4 # undef _NEEDUSHORT # undef _NEEDUINT @@ -108,20 +104,19 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; #elif defined(__NetBSD__) # include # include +# include # undef _NEEDUSHORT # undef _NEEDUINT # undef _NEEDULONG #elif defined(__OpenBSD__) # include # include -# define PLAN9PORT_USING_PTHREADS 1 # undef _NEEDUSHORT # undef _NEEDUINT # undef _NEEDULONG #else /* No idea what system this is -- try some defaults */ # include -# define PLAN9PORT_USING_PTHREADS 1 #endif #ifndef O_DIRECT diff --git a/src/libthread/386-ucontext.c b/src/libthread/386-ucontext.c deleted file mode 100644 index 3afa9513..00000000 --- a/src/libthread/386-ucontext.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "threadimpl.h" - -void -makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) -{ - int *sp; - - sp = USPALIGN(ucp, 4); - sp -= argc; - memmove(sp, &argc+1, argc*sizeof(int)); - *--sp = 0; /* return address */ - ucp->uc_mcontext.mc_eip = (long)func; - ucp->uc_mcontext.mc_esp = (int)sp; -} - -int -swapcontext(ucontext_t *oucp, ucontext_t *ucp) -{ - if(getcontext(oucp) == 0) - setcontext(ucp); - return 0; -} diff --git a/src/libthread/386-ucontext.h b/src/libthread/386-ucontext.h deleted file mode 100644 index b1ee81b3..00000000 --- a/src/libthread/386-ucontext.h +++ /dev/null @@ -1,119 +0,0 @@ -#define setcontext(u) setmcontext(&(u)->uc_mcontext) -#define getcontext(u) getmcontext(&(u)->uc_mcontext) -typedef struct mcontext mcontext_t; -typedef struct ucontext ucontext_t; - -extern int swapcontext(ucontext_t*, ucontext_t*); -extern void makecontext(ucontext_t*, void(*)(), int, ...); -extern int getmcontext(mcontext_t*); -extern void setmcontext(mcontext_t*); - -/*- - * Copyright (c) 1999 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/sys/ucontext.h,v 1.4 1999/10/11 20:33:17 luoqi Exp $ - */ - -/* #include */ - -/*- - * Copyright (c) 1999 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD: src/sys/i386/include/ucontext.h,v 1.4 1999/10/11 20:33:09 luoqi Exp $ - */ - -struct mcontext { - /* - * The first 20 fields must match the definition of - * sigcontext. So that we can support sigcontext - * and ucontext_t at the same time. - */ - int mc_onstack; /* XXX - sigcontext compat. */ - int mc_gs; - int mc_fs; - int mc_es; - int mc_ds; - int mc_edi; - int mc_esi; - int mc_ebp; - int mc_isp; - int mc_ebx; - int mc_edx; - int mc_ecx; - int mc_eax; - int mc_trapno; - int mc_err; - int mc_eip; - int mc_cs; - int mc_eflags; - int mc_esp; /* machine state */ - int mc_ss; - - int mc_fpregs[28]; /* env87 + fpacc87 + u_long */ - int __spare__[17]; -}; - -struct ucontext { - /* - * Keep the order of the first two fields. Also, - * keep them the first two fields in the structure. - * This way we can have a union with struct - * sigcontext and ucontext_t. This allows us to - * support them both at the same time. - * note: the union is not defined, though. - */ - sigset_t uc_sigmask; - mcontext_t uc_mcontext; - - struct __ucontext *uc_link; - stack_t uc_stack; - int __spare__[8]; -}; diff --git a/src/libthread/COPYING.SPARC64-CONTEXT b/src/libthread/COPYING.SPARC64-CONTEXT deleted file mode 100644 index 3b204400..00000000 --- a/src/libthread/COPYING.SPARC64-CONTEXT +++ /dev/null @@ -1,458 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS diff --git a/src/libthread/COPYRIGHT b/src/libthread/COPYRIGHT index d0820965..212b96bc 100644 --- a/src/libthread/COPYRIGHT +++ b/src/libthread/COPYRIGHT @@ -42,12 +42,3 @@ Contains parts of an earlier library that has: * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. */ - -=== - -The above notices do *NOT* apply to Linux-sparc64-context.S -or to sparc64-ucontext.c. Those are functions from -the GNU C library and are provided for systems that use the GNU C -library but somehow are missing those functions. They are -distributed under the Lesser GPL; see COPYING.SPARC64-CONTEXT. - diff --git a/src/libthread/Linux-arm-asm.s b/src/libthread/Linux-arm-asm.s deleted file mode 100644 index 9bd54f8a..00000000 --- a/src/libthread/Linux-arm-asm.s +++ /dev/null @@ -1,41 +0,0 @@ -.globl mygetmcontext -mygetmcontext: - str r1, [r0,#4] - str r2, [r0,#8] - str r3, [r0,#12] - str r4, [r0,#16] - str r5, [r0,#20] - str r6, [r0,#24] - str r7, [r0,#28] - str r8, [r0,#32] - str r9, [r0,#36] - str r10, [r0,#40] - str r11, [r0,#44] - str r12, [r0,#48] - str r13, [r0,#52] - str r14, [r0,#56] - /* store 1 as r0-to-restore */ - mov r1, #1 - str r1, [r0] - /* return 0 */ - mov r0, #0 - mov pc, lr - -.globl mysetmcontext -mysetmcontext: - ldr r1, [r0,#4] - ldr r2, [r0,#8] - ldr r3, [r0,#12] - ldr r4, [r0,#16] - ldr r5, [r0,#20] - ldr r6, [r0,#24] - ldr r7, [r0,#28] - ldr r8, [r0,#32] - ldr r9, [r0,#36] - ldr r10, [r0,#40] - ldr r11, [r0,#44] - ldr r12, [r0,#48] - ldr r13, [r0,#52] - ldr r14, [r0,#56] - ldr r0, [r0] - mov pc, lr diff --git a/src/libthread/Linux-sparc64-context.S b/src/libthread/Linux-sparc64-context.S deleted file mode 100644 index 1cc38391..00000000 --- a/src/libthread/Linux-sparc64-context.S +++ /dev/null @@ -1,135 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Constants shared between setcontext() and getcontext(). Don't - install this header file. */ - - -#define UC_LINK 0 -#define __UC_SIGMASK 16 -#define UC_M_PC 40 -#define UC_M_NPC 48 -#define UC_SIGMASK 536 -#define SIGMASK_WORDS 16 - -/* Copyright (C) 1997, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Richard Henderson (rth@tamu.edu). - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#define ENTRY(x) x: -#define END(x) - -/*#include "ucontext_i.h" (up above) */ - -/* int getcontext(ucontext_t *); */ - -ENTRY(getcontext) - - ldx [%o0 + UC_LINK], %o1 /* Preserve uc_link field, the - trap clears it. */ - ta 0x6e -1: - ldx [%o0 + UC_M_PC], %o2 - ldx [%o0 + UC_M_NPC], %o3 - ldx [%o0 + __UC_SIGMASK], %o4 - stx %o1, [%o0 + UC_LINK] - add %o2, 2f - 1b, %o2 - stx %o2, [%o0 + UC_M_PC] - add %o3, 2f - 1b, %o3 - stx %o3, [%o0 + UC_M_NPC] -#if SIGMASK_WORDS == 16 - stx %o4, [%o0 + UC_SIGMASK] - stx %g0, [%o0 + UC_SIGMASK + 8] - stx %g0, [%o0 + UC_SIGMASK + 16] - stx %g0, [%o0 + UC_SIGMASK + 24] - stx %g0, [%o0 + UC_SIGMASK + 32] - stx %g0, [%o0 + UC_SIGMASK + 40] - stx %g0, [%o0 + UC_SIGMASK + 48] - stx %g0, [%o0 + UC_SIGMASK + 56] - stx %g0, [%o0 + UC_SIGMASK + 64] - stx %g0, [%o0 + UC_SIGMASK + 72] - stx %g0, [%o0 + UC_SIGMASK + 80] - stx %g0, [%o0 + UC_SIGMASK + 88] - stx %g0, [%o0 + UC_SIGMASK + 96] - stx %g0, [%o0 + UC_SIGMASK + 104] - stx %g0, [%o0 + UC_SIGMASK + 112] - stx %g0, [%o0 + UC_SIGMASK + 120] -#else -# error Adjust getcontext -#endif -2: - retl - clr %o0 - -END(getcontext) - -/* Copyright (C) 1997, 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Richard Henderson (rth@tamu.edu). - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* -#include -#include "ucontext_i.h" -*/ - -/* int setcontext(ucontext_t *ctx); */ -.weak setcontext -ENTRY(setcontext) - - mov 1, %o1 - -/* int __setcontext(ucontext_t *ctx, int restoremask); */ -ENTRY(__setcontext) - - ldx [%o0 + UC_SIGMASK], %o2 - stx %o2, [%o0 + __UC_SIGMASK] - ta 0x6f - -END(__setcontext) - diff --git a/src/libthread/OpenBSD-386-asm.s b/src/libthread/OpenBSD-386-asm.s deleted file mode 100644 index ed18d2f0..00000000 --- a/src/libthread/OpenBSD-386-asm.s +++ /dev/null @@ -1,45 +0,0 @@ -.globl getmcontext -getmcontext: - movl 4(%esp), %eax - - movl %fs, 8(%eax) - movl %es, 12(%eax) - movl %ds, 16(%eax) - movl %ss, 76(%eax) - movl %edi, 20(%eax) - movl %esi, 24(%eax) - movl %ebp, 28(%eax) - movl %ebx, 36(%eax) - movl %edx, 40(%eax) - movl %ecx, 44(%eax) - - movl $1, 48(%eax) /* %eax */ - movl (%esp), %ecx /* %eip */ - movl %ecx, 60(%eax) - leal 4(%esp), %ecx /* %esp */ - movl %ecx, 72(%eax) - - movl 44(%eax), %ecx /* restore %ecx */ - movl $0, %eax - ret - -.globl setmcontext -setmcontext: - movl 4(%esp), %eax - - movl 8(%eax), %fs - movl 12(%eax), %es - movl 16(%eax), %ds - movl 76(%eax), %ss - movl 20(%eax), %edi - movl 24(%eax), %esi - movl 28(%eax), %ebp - movl 36(%eax), %ebx - movl 40(%eax), %edx - movl 44(%eax), %ecx - - movl 72(%eax), %esp - pushl 60(%eax) /* new %eip */ - movl 48(%eax), %eax - ret - diff --git a/src/libthread/OpenBSD-power-asm.S b/src/libthread/OpenBSD-power-asm.S deleted file mode 100644 index 36035eb5..00000000 --- a/src/libthread/OpenBSD-power-asm.S +++ /dev/null @@ -1,73 +0,0 @@ -ENTRY(_getmcontext) /* xxx: instruction scheduling */ - mflr %r0 - mfcr %r5 - mfctr %r6 - mfxer %r7 - stw %r0, 0*4(%r3) - stw %r5, 1*4(%r3) - stw %r6, 2*4(%r3) - stw %r7, 3*4(%r3) - - stw %r1, 4*4(%r3) - stw %r2, 5*4(%r3) - li %r5, 1 /* return value for setmcontext */ - stw %r5, 6*4(%r3) - - stw %r13, (0+7)*4(%r3) /* callee-save GPRs */ - stw %r14, (1+7)*4(%r3) /* xxx: block move */ - stw %r15, (2+7)*4(%r3) - stw %r16, (3+7)*4(%r3) - stw %r17, (4+7)*4(%r3) - stw %r18, (5+7)*4(%r3) - stw %r19, (6+7)*4(%r3) - stw %r20, (7+7)*4(%r3) - stw %r21, (8+7)*4(%r3) - stw %r22, (9+7)*4(%r3) - stw %r23, (10+7)*4(%r3) - stw %r24, (11+7)*4(%r3) - stw %r25, (12+7)*4(%r3) - stw %r26, (13+7)*4(%r3) - stw %r27, (14+7)*4(%r3) - stw %r28, (15+7)*4(%r3) - stw %r29, (16+7)*4(%r3) - stw %r30, (17+7)*4(%r3) - stw %r31, (18+7)*4(%r3) - - li %r3, 0 /* return */ - blr - -ENTRY(_setmcontext) - lwz %r13, (0+7)*4(%r3) /* callee-save GPRs */ - lwz %r14, (1+7)*4(%r3) /* xxx: block move */ - lwz %r15, (2+7)*4(%r3) - lwz %r16, (3+7)*4(%r3) - lwz %r17, (4+7)*4(%r3) - lwz %r18, (5+7)*4(%r3) - lwz %r19, (6+7)*4(%r3) - lwz %r20, (7+7)*4(%r3) - lwz %r21, (8+7)*4(%r3) - lwz %r22, (9+7)*4(%r3) - lwz %r23, (10+7)*4(%r3) - lwz %r24, (11+7)*4(%r3) - lwz %r25, (12+7)*4(%r3) - lwz %r26, (13+7)*4(%r3) - lwz %r27, (14+7)*4(%r3) - lwz %r28, (15+7)*4(%r3) - lwz %r29, (16+7)*4(%r3) - lwz %r30, (17+7)*4(%r3) - lwz %r31, (18+7)*4(%r3) - - lwz %r1, 4*4(%r3) - lwz %r2, 5*4(%r3) - - lwz %r0, 0*4(%r3) - mtlr %r0 - lwz %r0, 1*4(%r3) - mtcr %r0 /* mtcrf 0xFF, %r0 */ - lwz %r0, 2*4(%r3) - mtctr %r0 - lwz %r0, 3*4(%r3) - mtxer %r0 - - lwz %r3, 6*4(%r3) - blr diff --git a/src/libthread/OpenBSD-x86_64-asm.S b/src/libthread/OpenBSD-x86_64-asm.S deleted file mode 100644 index e982cdef..00000000 --- a/src/libthread/OpenBSD-x86_64-asm.S +++ /dev/null @@ -1,44 +0,0 @@ -.text -.align 8 - -.globl libthread_getmcontext -libthread_getmcontext: - movq $1, 0*8(%rdi) // rax - movq %rbx, 1*8(%rdi) - movq %rcx, 2*8(%rdi) - movq %rdx, 3*8(%rdi) - movq %rsi, 4*8(%rdi) - movq %rdi, 5*8(%rdi) - movq %rbp, 6*8(%rdi) - movq %rsp, 7*8(%rdi) - movq %r8, 8*8(%rdi) - movq %r9, 9*8(%rdi) - movq %r10, 10*8(%rdi) - movq %r11, 11*8(%rdi) - movq %r12, 12*8(%rdi) - movq %r13, 13*8(%rdi) - movq %r14, 14*8(%rdi) - movq %r15, 15*8(%rdi) - movq $0, %rax - ret - -.globl libthread_setmcontext -libthread_setmcontext: - movq 0*8(%rdi), %rax - movq 1*8(%rdi), %rbx - movq 2*8(%rdi), %rcx - movq 3*8(%rdi), %rdx - movq 4*8(%rdi), %rsi - // %rdi later - movq 6*8(%rdi), %rbp - movq 7*8(%rdi), %rsp - movq 8*8(%rdi), %r8 - movq 9*8(%rdi), %r9 - movq 10*8(%rdi), %r10 - movq 11*8(%rdi), %r11 - movq 12*8(%rdi), %r12 - movq 13*8(%rdi), %r13 - movq 14*8(%rdi), %r14 - movq 15*8(%rdi), %r15 - movq 5*8(%rdi), %rdi - ret diff --git a/src/libthread/arm-ucontext.c b/src/libthread/arm-ucontext.c deleted file mode 100644 index 512ca973..00000000 --- a/src/libthread/arm-ucontext.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "threadimpl.h" - -void -makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...) -{ - int i, *sp; - va_list arg; - - sp = USPALIGN(uc, 4); - va_start(arg, argc); - for(i=0; i<4 && iuc_mcontext.arm_r0)[i] = va_arg(arg, uint); - va_end(arg); - uc->uc_mcontext.arm_sp = (uint)sp; - uc->uc_mcontext.arm_lr = (uint)fn; -} - -int -swapcontext(ucontext_t *oucp, const ucontext_t *ucp) -{ - if(getcontext(oucp) == 0) - setcontext(ucp); - return 0; -} diff --git a/src/libthread/mkfile b/src/libthread/mkfile index eca4f4df..40941f43 100644 --- a/src/libthread/mkfile +++ b/src/libthread/mkfile @@ -1,15 +1,14 @@ <$PLAN9/src/mkhdr -SYSOFILES=`{sh ./sysofiles.sh} LIB=libthread.a OFILES=\ - $SYSOFILES\ bg.$O\ channel.$O\ daemonize.$O\ exec.$O\ ioproc.$O\ iorw.$O\ + pthread.$O\ ref.$O\ thread.$O\ wait.$O\ diff --git a/src/libthread/power-ucontext.c b/src/libthread/power-ucontext.c deleted file mode 100644 index 32a8e931..00000000 --- a/src/libthread/power-ucontext.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "threadimpl.h" - -void -makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) -{ - ulong *sp, *tos; - va_list arg; - - if(argc != 2) - sysfatal("libthread: makecontext misused"); - sp = USPALIGN(ucp, 16); - ucp->mc.pc = (long)func; - ucp->mc.sp = (long)sp; - va_start(arg, argc); - ucp->mc.r3 = va_arg(arg, long); - ucp->mc.r4 = va_arg(arg, long); - va_end(arg); -} - -int -swapcontext(ucontext_t *oucp, ucontext_t *ucp) -{ - if(getcontext(oucp) == 0) - setcontext(ucp); - return 0; -} diff --git a/src/libthread/power-ucontext.h b/src/libthread/power-ucontext.h deleted file mode 100644 index 1985d98d..00000000 --- a/src/libthread/power-ucontext.h +++ /dev/null @@ -1,36 +0,0 @@ -#define setcontext(u) _setmcontext(&(u)->mc) -#define getcontext(u) _getmcontext(&(u)->mc) -typedef struct mcontext mcontext_t; -typedef struct ucontext ucontext_t; -struct mcontext -{ - ulong pc; /* lr */ - ulong cr; /* mfcr */ - ulong ctr; /* mfcr */ - ulong xer; /* mfcr */ - ulong sp; /* callee saved: r1 */ - ulong toc; /* callee saved: r2 */ - ulong r3; /* first arg to function, return register: r3 */ - ulong gpr[19]; /* callee saved: r13-r31 */ -/* -// XXX: currently do not save vector registers or floating-point state -// ulong pad; -// uvlong fpr[18]; / * callee saved: f14-f31 * / -// ulong vr[4*12]; / * callee saved: v20-v31, 256-bits each * / -*/ -}; - -struct ucontext -{ - struct { - void *ss_sp; - uint ss_size; - } uc_stack; - sigset_t uc_sigmask; - mcontext_t mc; -}; - -void makecontext(ucontext_t*, void(*)(void), int, ...); -int swapcontext(ucontext_t*, ucontext_t*); -int _getmcontext(mcontext_t*); -void _setmcontext(mcontext_t*); diff --git a/src/libthread/sparc64-ucontext.c b/src/libthread/sparc64-ucontext.c deleted file mode 100644 index e4800c19..00000000 --- a/src/libthread/sparc64-ucontext.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 2001 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek . - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include - -#define UC_M_PC 40 -#define UC_M_NPC 48 - -extern int __getcontext (ucontext_t *ucp); -extern int __setcontext (const ucontext_t *ucp, int restoremask); - -int -swapcontext (ucontext_t *oucp, const ucontext_t *ucp) -{ - extern void __swapcontext_ret (void); - /* Save the current machine context to oucp. */ - __getcontext (oucp); - /* Modify oucp to skip the __setcontext call on reactivation. */ - *(long*)((char*)oucp+UC_M_PC) = (long)__swapcontext_ret; - *(long*)((char*)oucp+UC_M_NPC) = (long)__swapcontext_ret + 4; - /* Restore the machine context in ucp. */ - __setcontext (ucp, 1); - return 0; -} - -asm (" \n\ - .text \n\ - .type __swapcontext_ret, #function \n\ -__swapcontext_ret: \n\ - return %i7 + 8 \n\ - clr %o0 \n\ - .size __swapcontext_ret, .-__swapcontext_ret \n\ - "); diff --git a/src/libthread/stkmalloc.c b/src/libthread/stkmalloc.c deleted file mode 100644 index 083aea1b..00000000 --- a/src/libthread/stkmalloc.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "threadimpl.h" - -void* -_threadstkalloc(int n) -{ - return malloc(n); -} - -void -_threadstkfree(void *v, int n) -{ - free(v); -} diff --git a/src/libthread/stkmmap.c b/src/libthread/stkmmap.c deleted file mode 100644 index f4a24630..00000000 --- a/src/libthread/stkmmap.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include "threadimpl.h" - -#ifndef MAP_STACK -#define MAP_STACK 0 -#endif - -void* -_threadstkalloc(int n) -{ - void *p; - - p = mmap(nil, n, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON|MAP_STACK, -1, 0); - if(p == (void*)-1) - return nil; - return p; -} - -void -_threadstkfree(void *v, int n) -{ - if(n > 0) - munmap(v, n); -} diff --git a/src/libthread/sysofiles.sh b/src/libthread/sysofiles.sh deleted file mode 100644 index cf9e0234..00000000 --- a/src/libthread/sysofiles.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -test -f $PLAN9/config && . $PLAN9/config - -echo pthread.o - -case "$SYSNAME" in -OpenBSD) - echo stkmmap.o - ;; -*) - echo stkmalloc.o -esac - -# Various libc don't supply swapcontext, makecontext, so we do. -case "$SYSNAME-$OBJTYPE" in -Linux-arm | Linux-sparc64 | NetBSD-arm | OpenBSD-386 | OpenBSD-power | OpenBSD-x86_64) - echo $OBJTYPE-ucontext.o - ;; -esac - -# A few libc don't supply setcontext, getcontext, so we do. -case "$SYSNAME-$OBJTYPE" in -Linux-arm | Linux-sparc64 | OpenBSD-386 | OpenBSD-power | OpenBSD-x86_64) - echo $SYSNAME-$OBJTYPE-asm.o - ;; -esac diff --git a/src/libthread/thread.c b/src/libthread/thread.c index 0c764000..d72bf896 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -7,7 +7,6 @@ static uint threadnsysproc; static Lock threadnproclock; static Ref threadidref; static Proc *threadmainproc; -static int pthreadperthread = 1; static void addproc(Proc*); static void delproc(Proc*); @@ -16,9 +15,7 @@ static void delthread(_Threadlist*, _Thread*); static int onlist(_Threadlist*, _Thread*); static void addthreadinproc(Proc*, _Thread*); static void delthreadinproc(Proc*, _Thread*); -static void contextswitch(Context *from, Context *to); static void procmain(Proc*); -static void procscheduler(Proc*); static int threadinfo(void*, char*); static void pthreadscheduler(Proc *p); static void pthreadsleepschedlocked(Proc *p, _Thread *t); @@ -86,114 +83,24 @@ procalloc(void) return p; } -static void -threadstart(uint y, uint x) -{ - _Thread *t; - ulong z; - -//print("threadstart\n"); - z = (ulong)x << 16; /* hide undefined 32-bit shift from 32-bit compilers */ - z <<= 16; - z |= y; - t = (_Thread*)z; - -//print("threadstart sp=%p arg=%p startfn=%p t=%p\n", &t, t, t->startfn, t->startarg); - t->startfn(t->startarg); -/*print("threadexits %p\n", v); */ - threadexits(nil); -/*print("not reacehd\n"); */ -} - -static _Thread* -threadalloc(void (*fn)(void*), void *arg, uint stack) +_Thread* +_threadcreate(Proc *p, void (*fn)(void*), void *arg, uint stack) { _Thread *t; - sigset_t zero; - uint x, y; - ulong z; - /* allocate the task and stack together */ + USED(stack); t = malloc(sizeof *t); if(t == nil) - sysfatal("threadalloc malloc: %r"); + sysfatal("threadcreate malloc: %r"); memset(t, 0, sizeof *t); t->id = incref(&threadidref); -//print("fn=%p arg=%p\n", fn, arg); t->startfn = fn; t->startarg = arg; -//print("makecontext sp=%p t=%p startfn=%p\n", (char*)t->stk+t->stksize, t, t->startfn); - - /* do a reasonable initialization */ - if(stack == 0) - return t; - t->stk = _threadstkalloc(stack); - if(t->stk == nil) - sysfatal("threadalloc malloc stack: %r"); - t->stksize = stack; - memset(&t->context.uc, 0, sizeof t->context.uc); - sigemptyset(&zero); - sigprocmask(SIG_BLOCK, &zero, &t->context.uc.uc_sigmask); -//print("makecontext sp=%p t=%p startfn=%p\n", (char*)t->stk+t->stksize, t, t->startfn); - - /* must initialize with current context */ - if(getcontext(&t->context.uc) < 0) - sysfatal("threadalloc getcontext: %r"); -//print("makecontext sp=%p t=%p startfn=%p\n", (char*)t->stk+t->stksize, t, t->startfn); - - /* - * Call makecontext to do the real work. - * To avoid various mistakes on other system software, - * debuggers, and so on, don't get too close to both - * ends of the stack. Just staying away is much easier - * than debugging everything (outside our control) - * that has off-by-one errors. - */ - t->context.uc.uc_stack.ss_sp = (void*)(t->stk+64); - t->context.uc.uc_stack.ss_size = t->stksize-2*64; -#if defined(__sun__) && !defined(__MAKECONTEXT_V2_SOURCE) /* sigh */ - /* can avoid this with __MAKECONTEXT_V2_SOURCE but only on SunOS 5.9 */ - t->context.uc.uc_stack.ss_sp = - (char*)t->context.uc.uc_stack.ss_sp - +t->context.uc.uc_stack.ss_size; -#endif - /* - * All this magic is because you have to pass makecontext a - * function that takes some number of word-sized variables, - * and on 64-bit machines pointers are bigger than words. - */ -//print("makecontext sp=%p t=%p startfn=%p\n", (char*)t->stk+t->stksize, t, t->startfn); - z = (ulong)t; - y = z; - z >>= 16; /* hide undefined 32-bit shift from 32-bit compilers */ - x = z>>16; - makecontext(&t->context.uc, (void(*)(void))threadstart, 2, y, x); - - return t; -} - -_Thread* -_threadcreate(Proc *p, void (*fn)(void*), void *arg, uint stack) -{ - _Thread *t; - - /* defend against bad C libraries */ - if(stack < (256<<10)) - stack = 256<<10; - - if(p->nthread == 0 || pthreadperthread) - stack = 0; // not using it - t = threadalloc(fn, arg, stack); t->proc = p; - if(pthreadperthread) { - if(p->nthread != 0) - _threadpthreadstart(p, t); - else - t->mainthread = 1; - } else { - if(p->nthread == 0) - p->thread0 = t; - } + if(p->nthread != 0) + _threadpthreadstart(p, t); + else + t->mainthread = 1; p->nthread++; addthreadinproc(p, t); _threadready(t); @@ -232,15 +139,8 @@ _threadswitch(void) needstack(0); p = proc(); - /*print("threadswtch %p\n", p); */ - - if(pthreadperthread) - pthreadscheduler(p); - else if(p->thread == p->thread0) - procscheduler(p); - else - contextswitch(&p->thread->context, &p->schedcontext); + pthreadscheduler(p); } void @@ -338,15 +238,6 @@ threadsysfatal(char *fmt, va_list arg) threadexitsall(buf); } -static void -contextswitch(Context *from, Context *to) -{ - if(swapcontext(&from->uc, &to->uc) < 0){ - fprint(2, "swapcontext failed: %r\n"); - assert(0); - } -} - static void procmain(Proc *p) { @@ -357,7 +248,6 @@ procmain(Proc *p) /* take out first thread to run on system stack */ t = p->runqueue.head; delthread(&p->runqueue, t); - memset(&t->context.uc, 0, sizeof t->context.uc); /* run it */ p->thread = t; @@ -378,84 +268,6 @@ _threadpthreadmain(Proc *p, _Thread *t) threadexits(nil); } -static void -procscheduler(Proc *p) -{ - _Thread *t; - - _threaddebug(nil, "scheduler enter"); -//print("s %p\n", p); - for(;;) { - /* Finish running current thread. */ - lock(&p->lock); - t = p->thread; - p->thread = nil; - if(t->exiting){ - delthreadinproc(p, t); - p->nthread--; - /*print("nthread %d\n", p->nthread); */ - _threadstkfree(t->stk, t->stksize); - /* - * Cannot free p->thread0 yet: it is used for the - * context switches back to the scheduler. - * Instead, we will free it at the end of this function. - * But all the other threads can be freed now. - */ - if(t != p->thread0) - free(t); - } - - /* Pick next thread. */ - t = procnext(p, nil); - if(t == nil) - break; - _threaddebug(nil, "run %d (%s)", t->id, t->name); - //print("run %p %p %p %p\n", t, *(uintptr*)(t->context.uc.mc.sp), t->context.uc.mc.di, t->context.uc.mc.si); - unlock(&p->lock); - - /* Switch to next thread. */ - if(t == p->thread0) - return; - contextswitch(&p->schedcontext, &t->context); - - _threaddebug(nil, "back in scheduler"); - /*print("back in scheduler\n"); */ - } - - /* No more threads in proc. Clean up. */ - _threaddebug(nil, "scheduler exit"); - if(p->mainproc){ - /* - * Stupid bug - on Linux 2.6 and maybe elsewhere, - * if the main thread exits then the others keep running - * but the process shows up as a zombie in ps and is not - * attachable with ptrace. We'll just sit around pretending - * to be a system proc instead of exiting. - */ - _threaddaemonize(); - lock(&threadnproclock); - if(++threadnsysproc == threadnproc) - threadexitsall(p->msg); - p->sysproc = 1; - unlock(&threadnproclock); - for(;;) - sleep(1000); - } - - delproc(p); - lock(&threadnproclock); - if(p->sysproc) - --threadnsysproc; - if(--threadnproc == threadnsysproc) - threadexitsall(p->msg); - unlock(&threadnproclock); - unlock(&p->lock); - _threadsetproc(nil); - free(p->thread0); - free(p); - _threadpexit(); -} - static void pthreadsleepschedlocked(Proc *p, _Thread *t) { @@ -913,15 +725,6 @@ main(int argc, char **argv) if(opts == nil) opts = ""; - pthreadperthread = (strstr(opts, "pthreadperthread") != nil); -#ifdef PLAN9PORT_ASAN - // ASAN can't deal with the coroutine stack switches. - // In theory it has support for informing it about stack switches, - // but even with those calls added it can't deal with things - // like fork or exit from a coroutine stack. - // Easier to just run in pthread-per-thread mode. - pthreadperthread = 1; -#endif if(threadmaybackground() && strstr(opts, "nodaemon") == nil && getenv("NOLIBTHREADDAEMONIZE") == nil) _threadsetupdaemonize(); @@ -956,7 +759,7 @@ main(int argc, char **argv) t = _threadcreate(p, threadmainstart, nil, mainstacksize); t->mainthread = 1; procmain(p); - sysfatal("procscheduler returned in threadmain!"); + sysfatal("procmain returned in libthread"); /* does not return */ return 0; } diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h index 14646031..9eddba21 100644 --- a/src/libthread/threadimpl.h +++ b/src/libthread/threadimpl.h @@ -9,36 +9,11 @@ # if defined(__APPLE__) # define _XOPEN_SOURCE /* for Snow Leopard */ # endif -# include #endif #include #include "libc.h" #include "thread.h" -#if defined(__OpenBSD__) -# define mcontext libthread_mcontext -# define mcontext_t libthread_mcontext_t -# define ucontext libthread_ucontext -# define ucontext_t libthread_ucontext_t -# if defined __i386__ -# include "386-ucontext.h" -# elif defined __amd64__ -# include "x86_64-ucontext.h" -# else -# include "power-ucontext.h" -# endif -extern pid_t rfork_thread(int, void*, int(*)(void*), void*); -#endif - -#if defined(__arm__) -int mygetmcontext(ulong*); -void mysetmcontext(const ulong*); -#define setcontext(u) mysetmcontext(&(u)->uc_mcontext.arm_r0) -#define getcontext(u) mygetmcontext(&(u)->uc_mcontext.arm_r0) -#endif - - -typedef struct Context Context; typedef struct Execjob Execjob; typedef struct Proc Proc; typedef struct _Procrendez _Procrendez; @@ -54,11 +29,6 @@ enum STACK = 8192 }; -struct Context -{ - ucontext_t uc; -}; - struct Execjob { int *fd; @@ -72,11 +42,7 @@ struct _Procrendez { Lock *l; int asleep; -#ifdef PLAN9PORT_USING_PTHREADS pthread_cond_t cond; -#else - int pid; -#endif }; struct _Thread @@ -85,15 +51,10 @@ struct _Thread _Thread *prev; _Thread *allnext; _Thread *allprev; - Context context; void (*startfn)(void*); void *startarg; uint id; -#ifdef PLAN9PORT_USING_PTHREADS pthread_t osprocid; -#else - int osprocid; -#endif uchar *stk; uint stksize; int exiting; @@ -115,11 +76,7 @@ struct Proc Proc *next; Proc *prev; char msg[128]; -#ifdef PLAN9PORT_USING_PTHREADS pthread_t osprocid; -#else - int osprocid; -#endif Lock lock; int nswitch; _Thread *thread0; @@ -133,7 +90,6 @@ struct Proc _Procrendez runrend; Lock schedlock; _Thread *schedthread; - Context schedcontext; void *udata; Jmp sigjmp; int mainproc; diff --git a/src/libthread/x86_64-ucontext.c b/src/libthread/x86_64-ucontext.c deleted file mode 100644 index 5d1aaefc..00000000 --- a/src/libthread/x86_64-ucontext.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "threadimpl.h" - -void -makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...) -{ - uintptr *sp; - va_list arg; - - if(argc != 2) - sysfatal("libthread: makecontext misused"); - va_start(arg, argc); - uc->mc.di = va_arg(arg, uint); - uc->mc.si = va_arg(arg, uint); - va_end(arg); - - sp = USPALIGN(uc, 16); - *--sp = 0; // fn's return address - *--sp = (uintptr)fn; // return address of setcontext - uc->mc.sp = (uintptr)sp; -} - -int -swapcontext(ucontext_t *oucp, ucontext_t *ucp) -{ - if(getcontext(oucp) == 0) - setcontext(ucp); - return 0; -} diff --git a/src/libthread/x86_64-ucontext.h b/src/libthread/x86_64-ucontext.h deleted file mode 100644 index e0640761..00000000 --- a/src/libthread/x86_64-ucontext.h +++ /dev/null @@ -1,42 +0,0 @@ -#define setcontext(u) libthread_setmcontext(&(u)->mc) -#define getcontext(u) libthread_getmcontext(&(u)->mc) -typedef struct mcontext mcontext_t; -typedef struct ucontext ucontext_t; - -struct mcontext -{ - uintptr ax; - uintptr bx; - uintptr cx; - uintptr dx; - uintptr si; - uintptr di; - uintptr bp; - uintptr sp; - uintptr r8; - uintptr r9; - uintptr r10; - uintptr r11; - uintptr r12; - uintptr r13; - uintptr r14; - uintptr r15; -/* -// XXX: currently do not save vector registers or floating-point state -*/ -}; - -struct ucontext -{ - struct { - void *ss_sp; - uint ss_size; - } uc_stack; - sigset_t uc_sigmask; - mcontext_t mc; -}; - -void makecontext(ucontext_t*, void(*)(void), int, ...); -int swapcontext(ucontext_t*, ucontext_t*); -int libthread_getmcontext(mcontext_t*); -void libthread_setmcontext(mcontext_t*); -- cgit v1.2.3 From 8b9aaf2e3f7f6e2733e52db4dd1dcb46a91e4972 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 07:18:30 -0500 Subject: devdraw: add /usr/X11R7 for NetBSD Fixes #362. --- src/cmd/devdraw/mkwsysrules.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cmd/devdraw/mkwsysrules.sh b/src/cmd/devdraw/mkwsysrules.sh index 122e9123..56dff55a 100644 --- a/src/cmd/devdraw/mkwsysrules.sh +++ b/src/cmd/devdraw/mkwsysrules.sh @@ -7,6 +7,8 @@ if [ "x$X11" = "x" ]; then X11=/usr/X11R6 elif [ -d /usr/local/X11R6 ]; then X11=/usr/local/X11R6 + elif [ -d /usr/X11R7 ]; then + X11=/usr/X11R7 elif [ -d /usr/X ]; then X11=/usr/X elif [ -d /usr/openwin ]; then # for Sun -- cgit v1.2.3 From 0a7fe606818a7906cdc57ea14cb57b416be6c1de Mon Sep 17 00:00:00 2001 From: Nicola Girardi Date: Fri, 20 Mar 2020 18:52:41 +0000 Subject: 9term: use openpty on NetBSD Fixes #376. --- src/cmd/9term/NetBSD.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/cmd/9term/NetBSD.c b/src/cmd/9term/NetBSD.c index eec79c28..18294803 100644 --- a/src/cmd/9term/NetBSD.c +++ b/src/cmd/9term/NetBSD.c @@ -1 +1,17 @@ +#define getpts not_using_this_getpts #include "bsdpty.c" +#undef getpts + +#include + +int +getpts(int fd[], char *slave) +{ + if(openpty(&fd[1], &fd[0], NULL, NULL, NULL) >= 0){ + fchmod(fd[1], 0620); + strcpy(slave, ttyname(fd[0])); + return 0; + } + sysfatal("no ptys: %r"); + return 0; +} -- cgit v1.2.3 From 0bd14783426d137428ffae7cd89cfc06b88d1b11 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 07:21:44 -0500 Subject: wintext: use rc not bash --- bin/wintext | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/bin/wintext b/bin/wintext index 80a89957..1f36a05c 100755 --- a/bin/wintext +++ b/bin/wintext @@ -1,22 +1,17 @@ -#!/bin/bash +#!/usr/local/plan9/bin/rc -case "$winid" in -[0-9]*) +if(~ $winid [0-9]*) { 9p read acme/$winid/body exit 0 -esac - -case "$text9term" in -unix!*) - dial -e $text9term &1 +echo 'no running window found' >[2=1] exit 1 -- cgit v1.2.3 From 99dee78c2d44641ba56e5bb640d732f993b3dfa1 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 07:39:16 -0500 Subject: all: remove $OBJTYPE from build Now that we assume pthreads, the only assembly left is in libmp and libsec. We only ever added assembly for 386. The portable C code is fine for plan9port. --- INSTALL | 30 +--- bin/9a | 21 --- bin/9c | 14 +- bin/9l | 12 +- dist/buildmk | 2 +- src/libmp/386/mkfile | 15 -- src/libmp/386/mpdigdiv-Darwin.s | 33 ----- src/libmp/386/mpdigdiv.s | 33 ----- src/libmp/386/mpvecadd-Darwin.s | 70 ---------- src/libmp/386/mpvecadd.s | 70 ---------- src/libmp/386/mpvecdigmuladd-Darwin.s | 68 ---------- src/libmp/386/mpvecdigmuladd.s | 69 ---------- src/libmp/386/mpvecdigmulsub-Darwin.s | 69 ---------- src/libmp/386/mpvecdigmulsub.s | 70 ---------- src/libmp/386/mpvecsub-Darwin.s | 60 -------- src/libmp/386/mpvecsub.s | 60 -------- src/libmp/PowerMacintosh/mkfile | 4 - src/libmp/arm/mkfile | 4 - src/libmp/arm64/mkfile | 4 - src/libmp/mips/mkfile | 4 - src/libmp/mkfile | 2 +- src/libmp/port/mkfile | 5 +- src/libmp/power/mkfile | 4 - src/libmp/sparc64/mkfile | 4 - src/libmp/sun4u/mkfile | 4 - src/libmp/x86_64/mkfile | 4 - src/libsec/386/md5block.spp | 248 ---------------------------------- src/libsec/386/mkfile | 26 ---- src/libsec/386/sha1block.spp | 221 ------------------------------ src/libsec/PowerMacintosh/mkfile | 4 - src/libsec/arm/mkfile | 4 - src/libsec/arm64/mkfile | 4 - src/libsec/mips/mkfile | 4 - src/libsec/mkfile | 2 +- src/libsec/port/mkfile | 3 +- src/libsec/power/mkfile | 4 - src/libsec/sparc64/mkfile | 4 - src/libsec/sun4u/mkfile | 4 - src/libsec/x86_64/mkfile | 4 - src/mkenv | 36 ++--- src/mkfile | 2 - unix/make/Make.Darwin | 7 + unix/make/Make.Darwin-386 | 7 - unix/make/Make.Darwin-PowerMacintosh | 7 - unix/make/Make.FreeBSD | 6 + unix/make/Make.FreeBSD-386 | 6 - unix/make/Make.HP-UX | 6 + unix/make/Make.HP-UX-9000 | 6 - unix/make/Make.Linux | 6 + unix/make/Make.Linux-386 | 6 - unix/make/Make.Linux-power | 6 - unix/make/Make.Linux-x86_64 | 6 - unix/make/Make.NetBSD | 6 + unix/make/Make.NetBSD-386 | 6 - unix/make/Make.OSF1 | 6 + unix/make/Make.OSF1-alpha | 6 - unix/make/Make.OpenBSD | 6 + unix/make/Make.OpenBSD-386 | 6 - unix/make/Make.SunOS | 2 + unix/make/Make.SunOS-cc | 6 + unix/make/Make.SunOS-gcc | 6 + unix/make/Make.SunOS-sun4u | 2 - unix/make/Make.SunOS-sun4u-cc | 6 - unix/make/Make.SunOS-sun4u-gcc | 6 - unix/make/Makefile.TOP | 4 +- 65 files changed, 96 insertions(+), 1346 deletions(-) delete mode 100755 bin/9a delete mode 100644 src/libmp/386/mkfile delete mode 100644 src/libmp/386/mpdigdiv-Darwin.s delete mode 100644 src/libmp/386/mpdigdiv.s delete mode 100644 src/libmp/386/mpvecadd-Darwin.s delete mode 100644 src/libmp/386/mpvecadd.s delete mode 100644 src/libmp/386/mpvecdigmuladd-Darwin.s delete mode 100644 src/libmp/386/mpvecdigmuladd.s delete mode 100644 src/libmp/386/mpvecdigmulsub-Darwin.s delete mode 100644 src/libmp/386/mpvecdigmulsub.s delete mode 100644 src/libmp/386/mpvecsub-Darwin.s delete mode 100644 src/libmp/386/mpvecsub.s delete mode 100644 src/libmp/PowerMacintosh/mkfile delete mode 100644 src/libmp/arm/mkfile delete mode 100644 src/libmp/arm64/mkfile delete mode 100644 src/libmp/mips/mkfile delete mode 100644 src/libmp/power/mkfile delete mode 100644 src/libmp/sparc64/mkfile delete mode 100644 src/libmp/sun4u/mkfile delete mode 100644 src/libmp/x86_64/mkfile delete mode 100644 src/libsec/386/md5block.spp delete mode 100644 src/libsec/386/mkfile delete mode 100644 src/libsec/386/sha1block.spp delete mode 100644 src/libsec/PowerMacintosh/mkfile delete mode 100644 src/libsec/arm/mkfile delete mode 100644 src/libsec/arm64/mkfile delete mode 100644 src/libsec/mips/mkfile delete mode 100644 src/libsec/power/mkfile delete mode 100644 src/libsec/sparc64/mkfile delete mode 100644 src/libsec/sun4u/mkfile delete mode 100644 src/libsec/x86_64/mkfile create mode 100644 unix/make/Make.Darwin delete mode 100644 unix/make/Make.Darwin-386 delete mode 100644 unix/make/Make.Darwin-PowerMacintosh create mode 100644 unix/make/Make.FreeBSD delete mode 100644 unix/make/Make.FreeBSD-386 create mode 100644 unix/make/Make.HP-UX delete mode 100644 unix/make/Make.HP-UX-9000 create mode 100644 unix/make/Make.Linux delete mode 100644 unix/make/Make.Linux-386 delete mode 100644 unix/make/Make.Linux-power delete mode 100644 unix/make/Make.Linux-x86_64 create mode 100644 unix/make/Make.NetBSD delete mode 100644 unix/make/Make.NetBSD-386 create mode 100644 unix/make/Make.OSF1 delete mode 100644 unix/make/Make.OSF1-alpha create mode 100644 unix/make/Make.OpenBSD delete mode 100644 unix/make/Make.OpenBSD-386 create mode 100644 unix/make/Make.SunOS create mode 100644 unix/make/Make.SunOS-cc create mode 100644 unix/make/Make.SunOS-gcc delete mode 100644 unix/make/Make.SunOS-sun4u delete mode 100644 unix/make/Make.SunOS-sun4u-cc delete mode 100644 unix/make/Make.SunOS-sun4u-gcc diff --git a/INSTALL b/INSTALL index 49a4d9a4..79c0745f 100755 --- a/INSTALL +++ b/INSTALL @@ -71,18 +71,15 @@ if [ `uname` = SunOS ]; then echo "* Running on Solaris: checking architecture..." case "$(isainfo -n)" in *amd64*) - echo " x86-64 found." - echo "OBJTYPE=x86_64" >>$PLAN9/config + echo " x86-64 found; using gcc." echo "CC9=gcc" >>$PLAN9/config # defaults to gcc on Solaris/amd64 ;; *i386*) - echo " i386 found." - echo "OBJTYPE=386" >>$PLAN9/config + echo " i386 found; using gcc." echo "CC9=gcc" >>$PLAN9/config # defaults to gcc on Solaris/i386 ;; *sparc*) echo " Sparc found." - echo "OBJTYPE=sparc" >>$PLAN9/config ;; esac fi @@ -90,28 +87,15 @@ fi if [ `uname` = Darwin ]; then export NPROC=$(sysctl hw.ncpu | sed 's/hw.ncpu: //') # On Darwin, uname -m -p cannot be trusted. - echo "* Running on Darwin: checking architecture..." + echo "* Running on Darwin..." rm -f ./a.out - if ! gcc lib/darwin-main.c >/dev/null 2>&1; then - echo "Cannot find gcc. You may need to install the command-line tools using Xcode." >&2 + if ! xcrun --sdk macosx clang lib/darwin-main.c >/dev/null 2>&1; then + echo "Cannot find 'xcrun --sdk macosx clang'." >&2 + echo "You may need to install the command-line tools using Xcode." >&2 echo "See http://swtch.com/go/xcodegcc for details." >&2 exit 1 fi - case "$(file ./a.out 2>/dev/null)" in - *x86_64*) - echo " x86-64 found." - echo "OBJTYPE=x86_64" >>$PLAN9/config - echo "CC9='xcrun --sdk macosx clang'" >>$PLAN9/config - ;; - *i386*) - echo " i386 found." - echo "OBJTYPE=386" >>$PLAN9/config - ;; - *ppc*) - echo " power found." - echo "OBJTYPE=power" >>$PLAN9/config - ;; - esac + echo "CC9='xcrun --sdk macosx clang'" >>$PLAN9/config rm -f ./a.out fi diff --git a/bin/9a b/bin/9a deleted file mode 100755 index 753797c8..00000000 --- a/bin/9a +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -if [ $# != 1 ]; then - echo 'usage: 9a file.s' 1>&2 - exit 1 -fi - -test -f $PLAN9/config && . $PLAN9/config - -aflags="" -case "`uname`-${OBJTYPE:-`uname -m`}" in -Darwin-*386*) - aflags="-arch i386" - ;; -Darwin-*x86_64*) - aflags="-arch x86_64" - ;; -esac - -out=`echo $1 | sed 's/\.s$//;s/$/.o/'` -exec as $aflags -o $out $1 diff --git a/bin/9c b/bin/9c index 9dfc082e..4d488179 100755 --- a/bin/9c +++ b/bin/9c @@ -112,24 +112,14 @@ usexlc() cflags="$cflags $CC9FLAGS" } -tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}-${CC9:-cc}" +tag="${SYSNAME:-`uname`}-${CC9:-cc}" case "$tag" in *DragonFly*gcc*|*BSD*gcc*) usegcc ;; *DragonFly*clang|*BSD*clang*) useclang ;; -*Darwin-x86_64*) +*Darwin*) useclang cflags="$cflags -g3 -m64" ;; -*Darwin-arm64*) - useclang - cflags="$cflags -g3 -m64" - ;; -*Darwin*clang*) - useclang - cflags="$cflags -g3 -m32" - ;; -*Darwin*) usegcc - cflags="$cflags -g3 -no-cpp-precomp -m32" ;; *HP-UX*) cc=${CC9:-cc}; cflags="-g -O -c -Ae" ;; *Linux*) usegcc case "${CC9:-gcc}" in diff --git a/bin/9l b/bin/9l index f6eb0ba1..abca55fc 100755 --- a/bin/9l +++ b/bin/9l @@ -9,7 +9,7 @@ verbose=false nmflags="" extralibs="-lm" -tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}" +tag="${SYSNAME:-`uname`}" case "$tag" in *DragonFly*|*BSD*) ld="${CC9:-gcc} $CC9FLAGS" @@ -27,14 +27,8 @@ case "$tag" in userpath=true extralibs="$extralibs -lutil -lresolv -lpthread" ;; -*Darwin*x86_64*) - ld="${CC9:-gcc} -m64 $CC9FLAGS" - ;; -*Darwin-arm64*) - ld="${CC9:-gcc} -m64 $CC9FLAGS" - ;; *Darwin*) - ld="${CC9:-gcc} -m32 $CC9FLAGS" + ld="${CC9:-gcc} -m64 $CC9FLAGS" ;; *SunOS*) ld="${CC9:-cc} -g $CC9FLAGS" @@ -255,7 +249,7 @@ then fi # Don't say -L with a non-existent directory: Xcode complains. # x86_64 seems to put its 64-bit libraries in lib64. - if [ "${OBJTYPE:-`uname -m`}" = "x86_64" -a -d "$X11/lib64" ] + if [ "`uname -m`" = "x86_64" -a -d "$X11/lib64" ] then libsl="$libsl -L$X11/lib64" fi diff --git a/dist/buildmk b/dist/buildmk index cd11417c..ba21ae02 100755 --- a/dist/buildmk +++ b/dist/buildmk @@ -2,5 +2,5 @@ # run this in the src directory . ../src/mkenv -export SYSNAME OBJTYPE INSTALL +export SYSNAME INSTALL sh -x mkmk.sh diff --git a/src/libmp/386/mkfile b/src/libmp/386/mkfile deleted file mode 100644 index c63daf42..00000000 --- a/src/libmp/386/mkfile +++ /dev/null @@ -1,15 +0,0 @@ -<$PLAN9/src/mkhdr - -LIB=libmp.a -UNAME=`uname` -A=`[ $UNAME = Darwin ] && echo -Darwin` -OFILES=\ - mpdigdiv$A.$O\ - mpvecadd$A.$O\ - mpvecdigmuladd$A.$O\ - mpvecdigmulsub$A.$O\ - mpvecsub$A.$O\ - -HFILES=$PLAN9/include/mp.h ../port/dat.h - -<$PLAN9/src/mksyslib diff --git a/src/libmp/386/mpdigdiv-Darwin.s b/src/libmp/386/mpdigdiv-Darwin.s deleted file mode 100644 index 038214bf..00000000 --- a/src/libmp/386/mpdigdiv-Darwin.s +++ /dev/null @@ -1,33 +0,0 @@ -.text - -.globl _mpdigdiv -_mpdigdiv: - /* Prelude */ - pushl %ebp /* save on stack */ - pushl %ebx - - leal 12(%esp), %ebp /* %ebp = FP for now */ - movl 0(%ebp), %ebx /* dividend */ - movl 0(%ebx), %eax - movl 4(%ebx), %edx - movl 4(%ebp), %ebx /* divisor */ - movl 8(%ebp), %ebp /* quotient */ - - xorl %ecx, %ecx - cmpl %ebx, %edx /* dividend >= 2^32 * divisor */ - jae 2f - cmpl %ecx, %ebx /* divisor == 1 */ - je 2f - divl %ebx /* AX = DX:AX/BX */ - movl %eax, (%ebp) -1: - /* Postlude */ - popl %ebx - popl %ebp - ret - - /* return all 1's */ -2: - notl %ecx - movl %ecx, (%ebp) - jmp 1b diff --git a/src/libmp/386/mpdigdiv.s b/src/libmp/386/mpdigdiv.s deleted file mode 100644 index 48d37c0d..00000000 --- a/src/libmp/386/mpdigdiv.s +++ /dev/null @@ -1,33 +0,0 @@ -.text -.p2align 2,0x90 -.globl mpdigdiv -mpdigdiv: - /* Prelude */ - pushl %ebp /* save on stack */ - pushl %ebx - - leal 12(%esp), %ebp /* %ebp = FP for now */ - movl 0(%ebp), %ebx /* dividend */ - movl 0(%ebx), %eax - movl 4(%ebx), %edx - movl 4(%ebp), %ebx /* divisor */ - movl 8(%ebp), %ebp /* quotient */ - - xorl %ecx, %ecx - cmpl %ebx, %edx /* dividend >= 2^32 * divisor */ - jae divovfl - cmpl %ecx, %ebx /* divisor == 1 */ - je divovfl - divl %ebx /* AX = DX:AX/BX */ - movl %eax, (%ebp) -done: - /* Postlude */ - popl %ebx - popl %ebp - ret - - /* return all 1's */ -divovfl: - notl %ecx - movl %ecx, (%ebp) - jmp done diff --git a/src/libmp/386/mpvecadd-Darwin.s b/src/libmp/386/mpvecadd-Darwin.s deleted file mode 100644 index 2f68dbda..00000000 --- a/src/libmp/386/mpvecadd-Darwin.s +++ /dev/null @@ -1,70 +0,0 @@ -/* mpvecadd(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *sum) */ -/* sum[0:alen] = a[0:alen-1] + b[0:blen-1] */ -/* prereq: alen >= blen, sum has room for alen+1 digits */ -/* (very old gnu assembler doesn't allow multiline comments) */ - -.text - -.p2align 2,0x90 -.globl _mpvecadd -_mpvecadd: - /* Prelude */ - pushl %ebp /* save on stack */ - pushl %ebx - pushl %esi - pushl %edi - - leal 20(%esp), %ebp /* %ebp = FP for now */ - - movl 4(%ebp), %edx /* alen */ - movl 12(%ebp), %ecx /* blen */ - movl 0(%ebp), %esi /* a */ - movl 8(%ebp), %ebx /* b */ - subl %ecx, %edx - movl 16(%ebp), %edi /* sum */ - xorl %ebp, %ebp /* this also sets carry to 0 */ - - /* skip addition if b is zero */ - testl %ecx,%ecx - je 2f - - /* sum[0:blen-1],carry = a[0:blen-1] + b[0:blen-1] */ -1: - movl (%esi, %ebp, 4), %eax - adcl (%ebx, %ebp, 4), %eax - movl %eax, (%edi, %ebp, 4) - incl %ebp - loop 1b - -2: - /* jump if alen > blen */ - incl %edx - movl %edx, %ecx - loop 5f - - /* sum[alen] = carry */ -3: - jb 4f - movl $0, (%edi, %ebp, 4) - jmp 6f - -4: - movl $1, (%edi, %ebp, 4) - jmp 6f - - /* sum[blen:alen-1],carry = a[blen:alen-1] + 0 */ -5: - movl (%esi, %ebp, 4),%eax - adcl $0, %eax - movl %eax, (%edi, %ebp, 4) - incl %ebp - loop 5b - jmp 3b - -6: - /* Postlude */ - popl %edi - popl %esi - popl %ebx - popl %ebp - ret diff --git a/src/libmp/386/mpvecadd.s b/src/libmp/386/mpvecadd.s deleted file mode 100644 index 41d83c3f..00000000 --- a/src/libmp/386/mpvecadd.s +++ /dev/null @@ -1,70 +0,0 @@ -/* mpvecadd(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *sum) */ -/* sum[0:alen] = a[0:alen-1] + b[0:blen-1] */ -/* prereq: alen >= blen, sum has room for alen+1 digits */ -/* (very old gnu assembler doesn't allow multiline comments) */ - -.text - -.p2align 2,0x90 -.globl mpvecadd -mpvecadd: - /* Prelude */ - pushl %ebp /* save on stack */ - pushl %ebx - pushl %esi - pushl %edi - - leal 20(%esp), %ebp /* %ebp = FP for now */ - - movl 4(%ebp), %edx /* alen */ - movl 12(%ebp), %ecx /* blen */ - movl 0(%ebp), %esi /* a */ - movl 8(%ebp), %ebx /* b */ - subl %ecx, %edx - movl 16(%ebp), %edi /* sum */ - xorl %ebp, %ebp /* this also sets carry to 0 */ - - /* skip addition if b is zero */ - testl %ecx,%ecx - je _add1 - - /* sum[0:blen-1],carry = a[0:blen-1] + b[0:blen-1] */ -_addloop1: - movl (%esi, %ebp, 4), %eax - adcl (%ebx, %ebp, 4), %eax - movl %eax, (%edi, %ebp, 4) - incl %ebp - loop _addloop1 - -_add1: - /* jump if alen > blen */ - incl %edx - movl %edx, %ecx - loop _addloop2 - - /* sum[alen] = carry */ -_addend: - jb _addcarry - movl $0, (%edi, %ebp, 4) - jmp done - -_addcarry: - movl $1, (%edi, %ebp, 4) - jmp done - - /* sum[blen:alen-1],carry = a[blen:alen-1] + 0 */ -_addloop2: - movl (%esi, %ebp, 4),%eax - adcl $0, %eax - movl %eax, (%edi, %ebp, 4) - incl %ebp - loop _addloop2 - jmp _addend - -done: - /* Postlude */ - popl %edi - popl %esi - popl %ebx - popl %ebp - ret diff --git a/src/libmp/386/mpvecdigmuladd-Darwin.s b/src/libmp/386/mpvecdigmuladd-Darwin.s deleted file mode 100644 index f6d28ac3..00000000 --- a/src/libmp/386/mpvecdigmuladd-Darwin.s +++ /dev/null @@ -1,68 +0,0 @@ -/* - * mpvecdigmul(mpdigit *b, int n, mpdigit m, mpdigit *p) - * - * p += b*m - * - * each step look like: - * hi,lo = m*b[i] - * lo += oldhi + carry - * hi += carry - * p[i] += lo - * oldhi = hi - * - * the registers are: - * hi = DX - constrained by hardware - * lo = AX - constrained by hardware - * b+n = SI - can't be BP - * p+n = DI - can't be BP - * i-n = BP - * m = BX - * oldhi = CX - * - */ -.text - -.globl _mpvecdigmuladd -_mpvecdigmuladd: - /* Prelude */ - pushl %ebp /* save on stack */ - pushl %ebx - pushl %esi - pushl %edi - - leal 20(%esp), %ebp /* %ebp = FP for now */ - movl 0(%ebp), %esi /* b */ - movl 4(%ebp), %ecx /* n */ - movl 8(%ebp), %ebx /* m */ - movl 12(%ebp), %edi /* p */ - movl %ecx, %ebp - negl %ebp /* BP = -n */ - shll $2, %ecx - addl %ecx, %esi /* SI = b + n */ - addl %ecx, %edi /* DI = p + n */ - xorl %ecx, %ecx -1: - movl (%esi, %ebp, 4), %eax /* lo = b[i] */ - mull %ebx /* hi, lo = b[i] * m */ - addl %ecx,%eax /* lo += oldhi */ - jae 2f - incl %edx /* hi += carry */ -2: - addl %eax, (%edi, %ebp, 4) /* p[i] += lo */ - jae 3f - incl %edx /* hi += carry */ -3: - movl %edx, %ecx /* oldhi = hi */ - incl %ebp /* i++ */ - jnz 1b - xorl %eax, %eax - addl %ecx, (%edi, %ebp, 4) /* p[n] + oldhi */ - adcl %eax, %eax /* return carry out of p[n] */ - - /* Postlude */ - popl %edi - popl %esi - popl %ebx - popl %ebp - ret - diff --git a/src/libmp/386/mpvecdigmuladd.s b/src/libmp/386/mpvecdigmuladd.s deleted file mode 100644 index 8c92f61f..00000000 --- a/src/libmp/386/mpvecdigmuladd.s +++ /dev/null @@ -1,69 +0,0 @@ -# -# mpvecdigmul(mpdigit *b, int n, mpdigit m, mpdigit *p) -# -# p += b*m -# -# each step look like: -# hi,lo = m*b[i] -# lo += oldhi + carry -# hi += carry -# p[i] += lo -# oldhi = hi -# -# the registers are: -# hi = DX - constrained by hardware -# lo = AX - constrained by hardware -# b+n = SI - can't be BP -# p+n = DI - can't be BP -# i-n = BP -# m = BX -# oldhi = CX -# - -.text - -.p2align 2,0x90 -.globl mpvecdigmuladd -mpvecdigmuladd: - # Prelude - pushl %ebp # save on stack - pushl %ebx - pushl %esi - pushl %edi - - leal 20(%esp), %ebp # %ebp = FP for now - movl 0(%ebp), %esi # b - movl 4(%ebp), %ecx # n - movl 8(%ebp), %ebx # m - movl 12(%ebp), %edi # p - movl %ecx, %ebp - negl %ebp # BP = -n - shll $2, %ecx - addl %ecx, %esi # SI = b + n - addl %ecx, %edi # DI = p + n - xorl %ecx, %ecx -_muladdloop: - movl (%esi, %ebp, 4), %eax # lo = b[i] - mull %ebx # hi, lo = b[i] * m - addl %ecx,%eax # lo += oldhi - jae _muladdnocarry1 - incl %edx # hi += carry -_muladdnocarry1: - addl %eax, (%edi, %ebp, 4) # p[i] += lo - jae _muladdnocarry2 - incl %edx # hi += carry -_muladdnocarry2: - movl %edx, %ecx # oldhi = hi - incl %ebp # i++ - jnz _muladdloop - xorl %eax, %eax - addl %ecx, (%edi, %ebp, 4) # p[n] + oldhi - adcl %eax, %eax # return carry out of p[n] - - # Postlude - popl %edi - popl %esi - popl %ebx - popl %ebp - ret - diff --git a/src/libmp/386/mpvecdigmulsub-Darwin.s b/src/libmp/386/mpvecdigmulsub-Darwin.s deleted file mode 100644 index 8f7f4d68..00000000 --- a/src/libmp/386/mpvecdigmulsub-Darwin.s +++ /dev/null @@ -1,69 +0,0 @@ -/* - * mpvecdigmulsub(mpdigit *b, int n, mpdigit m, mpdigit *p) - * - * p -= b*m - * - * each step look like: - * hi,lo = m*b[i] - * lo += oldhi + carry - * hi += carry - * p[i] += lo - * oldhi = hi - * - * the registers are: - * hi = DX - constrained by hardware - * lo = AX - constrained by hardware - * b = SI - can't be BP - * p = DI - can't be BP - * i = BP - * n = CX - constrained by LOOP instr - * m = BX - * oldhi = EX - * - */ -.text - -.globl _mpvecdigmulsub -_mpvecdigmulsub: - /* Prelude */ - pushl %ebp /* save on stack */ - pushl %ebx - pushl %esi - pushl %edi - - leal 20(%esp), %ebp /* %ebp = FP for now */ - movl 0(%ebp), %esi /* b */ - movl 4(%ebp), %ecx /* n */ - movl 8(%ebp), %ebx /* m */ - movl 12(%ebp), %edi /* p */ - xorl %ebp, %ebp - pushl %ebp -1: - movl (%esi, %ebp, 4),%eax /* lo = b[i] */ - mull %ebx /* hi, lo = b[i] * m */ - addl 0(%esp), %eax /* lo += oldhi */ - jae 2f - incl %edx /* hi += carry */ -2: - subl %eax, (%edi, %ebp, 4) - jae 3f - incl %edx /* hi += carry */ -3: - movl %edx, 0(%esp) - incl %ebp - loop 1b - popl %eax - subl %eax, (%edi, %ebp, 4) - jae 4f - movl $-1, %eax - jmp 5f -4: - movl $1, %eax -5: - /* Postlude */ - popl %edi - popl %esi - popl %ebx - popl %ebp - ret - diff --git a/src/libmp/386/mpvecdigmulsub.s b/src/libmp/386/mpvecdigmulsub.s deleted file mode 100644 index 017e86c9..00000000 --- a/src/libmp/386/mpvecdigmulsub.s +++ /dev/null @@ -1,70 +0,0 @@ -# -# mpvecdigmulsub(mpdigit *b, int n, mpdigit m, mpdigit *p) -# -# p -= b*m -# -# each step look like: -# hi,lo = m*b[i] -# lo += oldhi + carry -# hi += carry -# p[i] += lo -# oldhi = hi -# -# the registers are: -# hi = DX - constrained by hardware -# lo = AX - constrained by hardware -# b = SI - can't be BP -# p = DI - can't be BP -# i = BP -# n = CX - constrained by LOOP instr -# m = BX -# oldhi = EX -# - -.text - -.p2align 2,0x90 -.globl mpvecdigmulsub -mpvecdigmulsub: - # Prelude - pushl %ebp # save on stack - pushl %ebx - pushl %esi - pushl %edi - - leal 20(%esp), %ebp # %ebp = FP for now - movl 0(%ebp), %esi # b - movl 4(%ebp), %ecx # n - movl 8(%ebp), %ebx # m - movl 12(%ebp), %edi # p - xorl %ebp, %ebp - pushl %ebp -_mulsubloop: - movl (%esi, %ebp, 4),%eax # lo = b[i] - mull %ebx # hi, lo = b[i] * m - addl 0(%esp), %eax # lo += oldhi - jae _mulsubnocarry1 - incl %edx # hi += carry -_mulsubnocarry1: - subl %eax, (%edi, %ebp, 4) - jae _mulsubnocarry2 - incl %edx # hi += carry -_mulsubnocarry2: - movl %edx, 0(%esp) - incl %ebp - loop _mulsubloop - popl %eax - subl %eax, (%edi, %ebp, 4) - jae _mulsubnocarry3 - movl $-1, %eax - jmp done -_mulsubnocarry3: - movl $1, %eax -done: - # Postlude - popl %edi - popl %esi - popl %ebx - popl %ebp - ret - diff --git a/src/libmp/386/mpvecsub-Darwin.s b/src/libmp/386/mpvecsub-Darwin.s deleted file mode 100644 index 0155e3ec..00000000 --- a/src/libmp/386/mpvecsub-Darwin.s +++ /dev/null @@ -1,60 +0,0 @@ -/* mpvecsub(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *diff) */ -/* diff[0:alen-1] = a[0:alen-1] - b[0:blen-1] */ -/* prereq: alen >= blen, diff has room for alen digits */ -/* (very old gnu assembler doesn't allow multiline comments) */ - -.text - -.p2align 2,0x90 -.globl _mpvecsub -_mpvecsub: - /* Prelude */ - pushl %ebp /* save on stack */ - pushl %ebx - pushl %esi - pushl %edi - - leal 20(%esp), %ebp /* %ebp = FP for now */ - movl 0(%ebp), %esi /* a */ - movl 8(%ebp), %ebx /* b */ - movl 4(%ebp), %edx /* alen */ - movl 12(%ebp), %ecx /* blen */ - movl 16(%ebp), %edi /* diff */ - - subl %ecx,%edx - xorl %ebp,%ebp /* this also sets carry to 0 */ - - /* skip subraction if b is zero */ - testl %ecx,%ecx - jz 2f - - /* diff[0:blen-1],borrow = a[0:blen-1] - b[0:blen-1] */ -1: - movl (%esi, %ebp, 4), %eax - sbbl (%ebx, %ebp, 4), %eax - movl %eax, (%edi, %ebp, 4) - incl %ebp - loop 1b - -2: - incl %edx - movl %edx,%ecx - loop 3f - jmp 4f - - /* diff[blen:alen-1] = a[blen:alen-1] - 0 */ -3: - movl (%esi, %ebp, 4), %eax - sbbl $0, %eax - movl %eax, (%edi, %ebp, 4) - incl %ebp - loop 3b - -4: - /* Postlude */ - popl %edi - popl %esi - popl %ebx - popl %ebp - ret - diff --git a/src/libmp/386/mpvecsub.s b/src/libmp/386/mpvecsub.s deleted file mode 100644 index d68424cf..00000000 --- a/src/libmp/386/mpvecsub.s +++ /dev/null @@ -1,60 +0,0 @@ -/* mpvecsub(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *diff) */ -/* diff[0:alen-1] = a[0:alen-1] - b[0:blen-1] */ -/* prereq: alen >= blen, diff has room for alen digits */ -/* (very old gnu assembler doesn't allow multiline comments) */ - -.text - -.p2align 2,0x90 -.globl mpvecsub -mpvecsub: - /* Prelude */ - pushl %ebp /* save on stack */ - pushl %ebx - pushl %esi - pushl %edi - - leal 20(%esp), %ebp /* %ebp = FP for now */ - movl 0(%ebp), %esi /* a */ - movl 8(%ebp), %ebx /* b */ - movl 4(%ebp), %edx /* alen */ - movl 12(%ebp), %ecx /* blen */ - movl 16(%ebp), %edi /* diff */ - - subl %ecx,%edx - xorl %ebp,%ebp /* this also sets carry to 0 */ - - /* skip subraction if b is zero */ - testl %ecx,%ecx - jz _sub1 - - /* diff[0:blen-1],borrow = a[0:blen-1] - b[0:blen-1] */ -_subloop1: - movl (%esi, %ebp, 4), %eax - sbbl (%ebx, %ebp, 4), %eax - movl %eax, (%edi, %ebp, 4) - incl %ebp - loop _subloop1 - -_sub1: - incl %edx - movl %edx,%ecx - loop _subloop2 - jmp done - - /* diff[blen:alen-1] = a[blen:alen-1] - 0 */ -_subloop2: - movl (%esi, %ebp, 4), %eax - sbbl $0, %eax - movl %eax, (%edi, %ebp, 4) - incl %ebp - loop _subloop2 - -done: - /* Postlude */ - popl %edi - popl %esi - popl %ebx - popl %ebp - ret - diff --git a/src/libmp/PowerMacintosh/mkfile b/src/libmp/PowerMacintosh/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libmp/PowerMacintosh/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libmp/arm/mkfile b/src/libmp/arm/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libmp/arm/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libmp/arm64/mkfile b/src/libmp/arm64/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libmp/arm64/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libmp/mips/mkfile b/src/libmp/mips/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libmp/mips/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libmp/mkfile b/src/libmp/mkfile index e3f1aa69..81f237c4 100644 --- a/src/libmp/mkfile +++ b/src/libmp/mkfile @@ -2,6 +2,6 @@ DIRS=\ port\ - $OBJTYPE\ +# $OBJTYPE\ <$PLAN9/src/mkdirs diff --git a/src/libmp/port/mkfile b/src/libmp/port/mkfile index b0cf77cd..15612aa7 100644 --- a/src/libmp/port/mkfile +++ b/src/libmp/port/mkfile @@ -34,8 +34,9 @@ FILES=\ mptouv\ ALLOFILES=${FILES:%=%.$O} -# cull things in the per-machine directories from this list -OFILES= `{sh ./reduce $O $OBJTYPE $ALLOFILES} +# # cull things in the per-machine directories from this list +# OFILES= `{sh ./reduce $O $ALLOFILES} +OFILES=$ALLOFILES HFILES=\ $PLAN9/include/lib9.h\ diff --git a/src/libmp/power/mkfile b/src/libmp/power/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libmp/power/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libmp/sparc64/mkfile b/src/libmp/sparc64/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libmp/sparc64/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libmp/sun4u/mkfile b/src/libmp/sun4u/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libmp/sun4u/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libmp/x86_64/mkfile b/src/libmp/x86_64/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libmp/x86_64/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libsec/386/md5block.spp b/src/libsec/386/md5block.spp deleted file mode 100644 index feebf615..00000000 --- a/src/libsec/386/md5block.spp +++ /dev/null @@ -1,248 +0,0 @@ -/* - * rfc1321 requires that I include this. The code is new. The constants - * all come from the rfc (hence the copyright). We trade a table for the - * macros in rfc. The total size is a lot less. -- presotto - * - * Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All - * rights reserved. - * - * License to copy and use this software is granted provided that it - * is identified as the "RSA Data Security, Inc. MD5 Message-Digest - * Algorithm" in all material mentioning or referencing this software - * or this function. - * - * License is also granted to make and use derivative works provided - * that such works are identified as "derived from the RSA Data - * Security, Inc. MD5 Message-Digest Algorithm" in all material - * mentioning or referencing the derived work. - * - * RSA Data Security, Inc. makes no representations concerning either - * the merchantability of this software or the suitability of this - * software forany particular purpose. It is provided "as is" - * without express or implied warranty of any kind. - * These notices must be retained in any copies of any part of this - * documentation and/or software. - */ -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 - -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 - -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 - -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - -#define PAYME(x) $##x - -/* - * SI is data - * a += FN(B,C,D); - * a += x[sh] + t[sh]; - * a = (a << S11) | (a >> (32 - S11)); - * a += b; - */ - -#define BODY1(off,V,FN,SH,A,B,C,D)\ - FN(B,C,D)\ - leal V(A, %edi, 1), A;\ - addl off(%ebp), A;\ - roll PAYME(SH), A;\ - addl B, A;\ - -#define BODY(off,V,FN,SH,A,B,C,D)\ - FN(B,C,D)\ - leal V(A, %edi, 1), A;\ - addl (off)(%ebp), A;\ - roll PAYME(SH), A;\ - addl B,A;\ - -/* - * fn1 = ((c ^ d) & b) ^ d - */ -#define FN1(B,C,D)\ - movl C, %edi;\ - xorl D, %edi;\ - andl B, %edi;\ - xorl D, %edi;\ - -/* - * fn2 = ((b ^ c) & d) ^ c; - */ -#define FN2(B,C,D)\ - movl B, %edi;\ - xorl C, %edi;\ - andl D, %edi;\ - xorl C, %edi;\ - -/* - * fn3 = b ^ c ^ d; - */ -#define FN3(B,C,D)\ - movl B, %edi;\ - xorl C, %edi;\ - xorl D, %edi;\ - -/* - * fn4 = c ^ (b | ~d); - */ -#define FN4(B,C,D)\ - movl D, %edi;\ - xorl $-1, %edi;\ - orl B, %edi;\ - xorl C, %edi;\ - -#define STACKSIZE 20 - -#define DATA (STACKSIZE+8) -#define LEN (STACKSIZE+12) -#define STATE (STACKSIZE+16) - -#define EDATA (STACKSIZE-4) -#define OLDEBX (STACKSIZE-8) -#define OLDESI (STACKSIZE-12) -#define OLDEDI (STACKSIZE-16) - - .text - - .p2align 2,0x90 -#ifdef __Darwin__ - .globl __md5block - __md5block: -#else - .globl _md5block - _md5block: -#endif - - /* Prelude */ - pushl %ebp - subl $(STACKSIZE), %esp - movl %ebx, OLDEBX(%esp) - movl %esi, OLDESI(%esp) - movl %edi, OLDEDI(%esp) - - movl DATA(%esp), %eax - addl LEN(%esp), %eax - movl %eax, EDATA(%esp) - - movl DATA(%esp), %ebp - -0: - movl STATE(%esp), %esi - movl (%esi), %eax - movl 4(%esi), %ebx - movl 8(%esi), %ecx - movl 12(%esi), %edx - - BODY1( 0*4,0xd76aa478,FN1,S11,%eax,%ebx,%ecx,%edx) - BODY1( 1*4,0xe8c7b756,FN1,S12,%edx,%eax,%ebx,%ecx) - BODY1( 2*4,0x242070db,FN1,S13,%ecx,%edx,%eax,%ebx) - BODY1( 3*4,0xc1bdceee,FN1,S14,%ebx,%ecx,%edx,%eax) - - BODY1( 4*4,0xf57c0faf,FN1,S11,%eax,%ebx,%ecx,%edx) - BODY1( 5*4,0x4787c62a,FN1,S12,%edx,%eax,%ebx,%ecx) - BODY1( 6*4,0xa8304613,FN1,S13,%ecx,%edx,%eax,%ebx) - BODY1( 7*4,0xfd469501,FN1,S14,%ebx,%ecx,%edx,%eax) - - BODY1( 8*4,0x698098d8,FN1,S11,%eax,%ebx,%ecx,%edx) - BODY1( 9*4,0x8b44f7af,FN1,S12,%edx,%eax,%ebx,%ecx) - BODY1(10*4,0xffff5bb1,FN1,S13,%ecx,%edx,%eax,%ebx) - BODY1(11*4,0x895cd7be,FN1,S14,%ebx,%ecx,%edx,%eax) - - BODY1(12*4,0x6b901122,FN1,S11,%eax,%ebx,%ecx,%edx) - BODY1(13*4,0xfd987193,FN1,S12,%edx,%eax,%ebx,%ecx) - BODY1(14*4,0xa679438e,FN1,S13,%ecx,%edx,%eax,%ebx) - BODY1(15*4,0x49b40821,FN1,S14,%ebx,%ecx,%edx,%eax) - - - BODY( 1*4,0xf61e2562,FN2,S21,%eax,%ebx,%ecx,%edx) - BODY( 6*4,0xc040b340,FN2,S22,%edx,%eax,%ebx,%ecx) - BODY(11*4,0x265e5a51,FN2,S23,%ecx,%edx,%eax,%ebx) - BODY( 0*4,0xe9b6c7aa,FN2,S24,%ebx,%ecx,%edx,%eax) - - BODY( 5*4,0xd62f105d,FN2,S21,%eax,%ebx,%ecx,%edx) - BODY(10*4,0x02441453,FN2,S22,%edx,%eax,%ebx,%ecx) - BODY(15*4,0xd8a1e681,FN2,S23,%ecx,%edx,%eax,%ebx) - BODY( 4*4,0xe7d3fbc8,FN2,S24,%ebx,%ecx,%edx,%eax) - - BODY( 9*4,0x21e1cde6,FN2,S21,%eax,%ebx,%ecx,%edx) - BODY(14*4,0xc33707d6,FN2,S22,%edx,%eax,%ebx,%ecx) - BODY( 3*4,0xf4d50d87,FN2,S23,%ecx,%edx,%eax,%ebx) - BODY( 8*4,0x455a14ed,FN2,S24,%ebx,%ecx,%edx,%eax) - - BODY(13*4,0xa9e3e905,FN2,S21,%eax,%ebx,%ecx,%edx) - BODY( 2*4,0xfcefa3f8,FN2,S22,%edx,%eax,%ebx,%ecx) - BODY( 7*4,0x676f02d9,FN2,S23,%ecx,%edx,%eax,%ebx) - BODY(12*4,0x8d2a4c8a,FN2,S24,%ebx,%ecx,%edx,%eax) - - - BODY( 5*4,0xfffa3942,FN3,S31,%eax,%ebx,%ecx,%edx) - BODY( 8*4,0x8771f681,FN3,S32,%edx,%eax,%ebx,%ecx) - BODY(11*4,0x6d9d6122,FN3,S33,%ecx,%edx,%eax,%ebx) - BODY(14*4,0xfde5380c,FN3,S34,%ebx,%ecx,%edx,%eax) - - BODY( 1*4,0xa4beea44,FN3,S31,%eax,%ebx,%ecx,%edx) - BODY( 4*4,0x4bdecfa9,FN3,S32,%edx,%eax,%ebx,%ecx) - BODY( 7*4,0xf6bb4b60,FN3,S33,%ecx,%edx,%eax,%ebx) - BODY(10*4,0xbebfbc70,FN3,S34,%ebx,%ecx,%edx,%eax) - - BODY(13*4,0x289b7ec6,FN3,S31,%eax,%ebx,%ecx,%edx) - BODY( 0*4,0xeaa127fa,FN3,S32,%edx,%eax,%ebx,%ecx) - BODY( 3*4,0xd4ef3085,FN3,S33,%ecx,%edx,%eax,%ebx) - BODY( 6*4,0x04881d05,FN3,S34,%ebx,%ecx,%edx,%eax) - - BODY( 9*4,0xd9d4d039,FN3,S31,%eax,%ebx,%ecx,%edx) - BODY(12*4,0xe6db99e5,FN3,S32,%edx,%eax,%ebx,%ecx) - BODY(15*4,0x1fa27cf8,FN3,S33,%ecx,%edx,%eax,%ebx) - BODY( 2*4,0xc4ac5665,FN3,S34,%ebx,%ecx,%edx,%eax) - - - BODY( 0*4,0xf4292244,FN4,S41,%eax,%ebx,%ecx,%edx) - BODY( 7*4,0x432aff97,FN4,S42,%edx,%eax,%ebx,%ecx) - BODY(14*4,0xab9423a7,FN4,S43,%ecx,%edx,%eax,%ebx) - BODY( 5*4,0xfc93a039,FN4,S44,%ebx,%ecx,%edx,%eax) - - BODY(12*4,0x655b59c3,FN4,S41,%eax,%ebx,%ecx,%edx) - BODY( 3*4,0x8f0ccc92,FN4,S42,%edx,%eax,%ebx,%ecx) - BODY(10*4,0xffeff47d,FN4,S43,%ecx,%edx,%eax,%ebx) - BODY( 1*4,0x85845dd1,FN4,S44,%ebx,%ecx,%edx,%eax) - - BODY( 8*4,0x6fa87e4f,FN4,S41,%eax,%ebx,%ecx,%edx) - BODY(15*4,0xfe2ce6e0,FN4,S42,%edx,%eax,%ebx,%ecx) - BODY( 6*4,0xa3014314,FN4,S43,%ecx,%edx,%eax,%ebx) - BODY(13*4,0x4e0811a1,FN4,S44,%ebx,%ecx,%edx,%eax) - - BODY( 4*4,0xf7537e82,FN4,S41,%eax,%ebx,%ecx,%edx) - BODY(11*4,0xbd3af235,FN4,S42,%edx,%eax,%ebx,%ecx) - BODY( 2*4,0x2ad7d2bb,FN4,S43,%ecx,%edx,%eax,%ebx) - BODY( 9*4,0xeb86d391,FN4,S44,%ebx,%ecx,%edx,%eax) - - addl $(16*4), %ebp - movl STATE(%esp), %edi - addl %eax,0(%edi) - addl %ebx,4(%edi) - addl %ecx,8(%edi) - addl %edx,12(%edi) - - movl EDATA(%esp), %edi - cmpl %edi, %ebp - jb 0b - - /* Postlude */ - movl OLDEBX(%esp), %ebx - movl OLDESI(%esp), %esi - movl OLDEDI(%esp), %edi - addl $(STACKSIZE), %esp - popl %ebp - ret - diff --git a/src/libsec/386/mkfile b/src/libsec/386/mkfile deleted file mode 100644 index 6f970600..00000000 --- a/src/libsec/386/mkfile +++ /dev/null @@ -1,26 +0,0 @@ -<$PLAN9/src/mkhdr - -LIB=libsec.a -SFILES=\ - md5block.s\ - sha1block.s\ - -HFILES=$PLAN9/include/libsec.h - -OFILES=${SFILES:%.s=%.$O} - -UPDATE=mkfile\ - $HFILES\ - $SFILES\ - -<$PLAN9/src/mksyslib - -%.s: %.spp - if [ `uname` = OpenBSD ] || [ `uname` = Darwin ] - then - gcc -xc -D__`uname`__ -E $stem.spp >$stem.s - else - cpp $stem.spp >$stem.s - fi - -CLEANFILES=md5block.s sha1block.s diff --git a/src/libsec/386/sha1block.spp b/src/libsec/386/sha1block.spp deleted file mode 100644 index 386b2e6c..00000000 --- a/src/libsec/386/sha1block.spp +++ /dev/null @@ -1,221 +0,0 @@ -.text - -.p2align 2,0x90 -#ifdef __Darwin__ -.globl __sha1block -__sha1block: -#else -.globl _sha1block -_sha1block: -#endif - -/* x = (wp[off-f] ^ wp[off-8] ^ wp[off-14] ^ wp[off-16]) <<< 1; - * wp[off] = x; - * x += A <<< 5; - * E += 0xca62c1d6 + x; - * x = FN(B,C,D); - * E += x; - * B >>> 2 - */ -#define BSWAPDI BYTE $0x0f; BYTE $0xcf; - -#define BODY(off,FN,V,A,B,C,D,E)\ - movl (off-64)(%ebp), %edi;\ - xorl (off-56)(%ebp), %edi;\ - xorl (off-32)(%ebp), %edi;\ - xorl (off-12)(%ebp), %edi;\ - roll $1, %edi;\ - movl %edi, off(%ebp);\ - leal V(%edi, E, 1), E;\ - movl A, %edi;\ - roll $5, %edi;\ - addl %edi, E;\ - FN(B,C,D)\ - addl %edi, E;\ - rorl $2, B;\ - -#define BODY0(off,FN,V,A,B,C,D,E)\ - movl off(%ebx), %edi;\ - bswap %edi;\ - movl %edi, off(%ebp);\ - leal V(%edi,E,1), E;\ - movl A, %edi;\ - roll $5,%edi;\ - addl %edi,E;\ - FN(B,C,D)\ - addl %edi,E;\ - rorl $2,B;\ - -/* - * fn1 = (((C^D)&B)^D); - */ -#define FN1(B,C,D)\ - movl C, %edi;\ - xorl D, %edi;\ - andl B, %edi;\ - xorl D, %edi;\ - -/* - * fn24 = B ^ C ^ D - */ -#define FN24(B,C,D)\ - movl B, %edi;\ - xorl C, %edi;\ - xorl D, %edi;\ - -/* - * fn3 = ((B ^ C) & (D ^= B)) ^ B - * D ^= B to restore D - */ -#define FN3(B,C,D)\ - movl B, %edi;\ - xorl C, %edi;\ - xorl B, D;\ - andl D, %edi;\ - xorl B, %edi;\ - xorl B, D;\ - -/* - * stack offsets - * void sha1block(uchar *DATA, int LEN, ulong *STATE) - */ -#define STACKSIZE (48+80*4) -#define DATA (STACKSIZE+8) -#define LEN (STACKSIZE+12) -#define STATE (STACKSIZE+16) - -/* - * stack offsets for locals - * ulong w[80]; - * uchar *edata; - * ulong *w15, *w40, *w60, *w80; - * register local - * ulong *wp = %ebp - * ulong a = eax, b = ebx, c = ecx, d = edx, e = esi - * ulong tmp = edi - */ -#define WARRAY (STACKSIZE-4-(80*4)) -#define TMP1 (STACKSIZE-8-(80*4)) -#define TMP2 (STACKSIZE-12-(80*4)) -#define W15 (STACKSIZE-16-(80*4)) -#define W40 (STACKSIZE-20-(80*4)) -#define W60 (STACKSIZE-24-(80*4)) -#define W80 (STACKSIZE-28-(80*4)) -#define EDATA (STACKSIZE-32-(80*4)) -#define OLDEBX (STACKSIZE-36-(80*4)) -#define OLDESI (STACKSIZE-40-(80*4)) -#define OLDEDI (STACKSIZE-44-(80*4)) - - /* Prelude */ - pushl %ebp - subl $(STACKSIZE), %esp - - mov %ebx, OLDEBX(%esp) - mov %esi, OLDESI(%esp) - mov %edi, OLDEDI(%esp) - - movl DATA(%esp), %eax - addl LEN(%esp), %eax - movl %eax, EDATA(%esp) - - leal (WARRAY+15*4)(%esp), %edi /* aw15 */ - movl %edi, W15(%esp) - leal (WARRAY+40*4)(%esp), %edx /* aw40 */ - movl %edx, W40(%esp) - leal (WARRAY+60*4)(%esp), %ecx /* aw60 */ - movl %ecx, W60(%esp) - leal (WARRAY+80*4)(%esp), %edi /* aw80 */ - movl %edi, W80(%esp) - -0: - leal WARRAY(%esp), %ebp /* warray */ - - movl STATE(%esp), %edi /* state */ - movl (%edi),%eax - movl 4(%edi),%ebx - movl %ebx, TMP1(%esp) /* tmp1 */ - movl 8(%edi), %ecx - movl 12(%edi), %edx - movl 16(%edi), %esi - - movl DATA(%esp), %ebx /* data */ - -1: - BODY0(0,FN1,0x5a827999,%eax,TMP1(%esp),%ecx,%edx,%esi) - movl %esi,TMP2(%esp) - BODY0(4,FN1,0x5a827999,%esi,%eax,TMP1(%esp),%ecx,%edx) - movl TMP1(%esp),%esi - BODY0(8,FN1,0x5a827999,%edx,TMP2(%esp),%eax,%esi,%ecx) - BODY0(12,FN1,0x5a827999,%ecx,%edx,TMP2(%esp),%eax,%esi) - movl %esi,TMP1(%esp) - BODY0(16,FN1,0x5a827999,%esi,%ecx,%edx,TMP2(%esp),%eax) - movl TMP2(%esp),%esi - - addl $20, %ebx - addl $20, %ebp - cmpl W15(%esp), %ebp /* w15 */ - jb 1b - - BODY0(0,FN1,0x5a827999,%eax,TMP1(%esp),%ecx,%edx,%esi) - addl $4, %ebx - movl %ebx, DATA(%esp) /* data */ - movl TMP1(%esp),%ebx - - BODY(4,FN1,0x5a827999,%esi,%eax,%ebx,%ecx,%edx) - BODY(8,FN1,0x5a827999,%edx,%esi,%eax,%ebx,%ecx) - BODY(12,FN1,0x5a827999,%ecx,%edx,%esi,%eax,%ebx) - BODY(16,FN1,0x5a827999,%ebx,%ecx,%edx,%esi,%eax) - - addl $20, %ebp - -2: - BODY(0,FN24,0x6ed9eba1,%eax,%ebx,%ecx,%edx,%esi) - BODY(4,FN24,0x6ed9eba1,%esi,%eax,%ebx,%ecx,%edx) - BODY(8,FN24,0x6ed9eba1,%edx,%esi,%eax,%ebx,%ecx) - BODY(12,FN24,0x6ed9eba1,%ecx,%edx,%esi,%eax,%ebx) - BODY(16,FN24,0x6ed9eba1,%ebx,%ecx,%edx,%esi,%eax) - - addl $20,%ebp - cmpl W40(%esp), %ebp - jb 2b - -3: - BODY(0,FN3,0x8f1bbcdc,%eax,%ebx,%ecx,%edx,%esi) - BODY(4,FN3,0x8f1bbcdc,%esi,%eax,%ebx,%ecx,%edx) - BODY(8,FN3,0x8f1bbcdc,%edx,%esi,%eax,%ebx,%ecx) - BODY(12,FN3,0x8f1bbcdc,%ecx,%edx,%esi,%eax,%ebx) - BODY(16,FN3,0x8f1bbcdc,%ebx,%ecx,%edx,%esi,%eax) - - addl $20, %ebp - cmpl W60(%esp), %ebp /* w60 */ - jb 3b - -4: - BODY(0,FN24,0xca62c1d6,%eax,%ebx,%ecx,%edx,%esi) - BODY(4,FN24,0xca62c1d6,%esi,%eax,%ebx,%ecx,%edx) - BODY(8,FN24,0xca62c1d6,%edx,%esi,%eax,%ebx,%ecx) - BODY(12,FN24,0xca62c1d6,%ecx,%edx,%esi,%eax,%ebx) - BODY(16,FN24,0xca62c1d6,%ebx,%ecx,%edx,%esi,%eax) - - addl $20, %ebp - cmpl W80(%esp), %ebp /* w80 */ - jb 4b - - movl STATE(%esp), %edi /* state */ - addl %eax, 0(%edi) - addl %ebx, 4(%edi) - addl %ecx, 8(%edi) - addl %edx, 12(%edi) - addl %esi, 16(%edi) - - movl EDATA(%esp), %edi /* edata */ - cmpl %edi, DATA(%esp) /* data */ - jb 0b - - /* Postlude */ - mov OLDEBX(%esp), %ebx - mov OLDESI(%esp), %esi - mov OLDEDI(%esp), %edi - addl $(STACKSIZE), %esp - popl %ebp - ret diff --git a/src/libsec/PowerMacintosh/mkfile b/src/libsec/PowerMacintosh/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libsec/PowerMacintosh/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libsec/arm/mkfile b/src/libsec/arm/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libsec/arm/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libsec/arm64/mkfile b/src/libsec/arm64/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libsec/arm64/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libsec/mips/mkfile b/src/libsec/mips/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libsec/mips/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libsec/mkfile b/src/libsec/mkfile index e3f1aa69..81f237c4 100644 --- a/src/libsec/mkfile +++ b/src/libsec/mkfile @@ -2,6 +2,6 @@ DIRS=\ port\ - $OBJTYPE\ +# $OBJTYPE\ <$PLAN9/src/mkdirs diff --git a/src/libsec/port/mkfile b/src/libsec/port/mkfile index 60baf2a3..7db34a97 100644 --- a/src/libsec/port/mkfile +++ b/src/libsec/port/mkfile @@ -54,7 +54,8 @@ ALLOFILES=\ tlshand.$O\ x509.$O\ -OFILES=`{sh ./reduce $O $OBJTYPE $ALLOFILES} +# OFILES=`{sh ./reduce $O $OBJTYPE $ALLOFILES} +OFILES=$ALLOFILES HFILES=$PLAN9/include/libsec.h <$PLAN9/src/mksyslib diff --git a/src/libsec/power/mkfile b/src/libsec/power/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libsec/power/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libsec/sparc64/mkfile b/src/libsec/sparc64/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libsec/sparc64/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libsec/sun4u/mkfile b/src/libsec/sun4u/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libsec/sun4u/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/libsec/x86_64/mkfile b/src/libsec/x86_64/mkfile deleted file mode 100644 index 43a4662b..00000000 --- a/src/libsec/x86_64/mkfile +++ /dev/null @@ -1,4 +0,0 @@ -all: - -%:V: - # nothing to see here diff --git a/src/mkenv b/src/mkenv index 6c89f141..5feca483 100644 --- a/src/mkenv +++ b/src/mkenv @@ -2,22 +2,22 @@ # and also valid shell input for ../dist/buildmk SYSNAME=`uname` -OBJTYPE=`(uname -m -p 2>/dev/null || uname -m) | sed ' - s;.*i[3-6]86.*;386;; - s;.*i86pc.*;386;; - s;.*amd64.*;x86_64;; - s;.*x86_64.*;x86_64;; - s;.*armv.*;arm;g; - s;.*powerpc.*;power;g; - s;.*PowerMacintosh.*;power;g; - s;.*Power.Macintosh.*;power;g; - s;.*macppc.*;power;g; - s;.*mips.*;mips;g; - s;.*ppc64.*;power;g; - s;.*ppc.*;power;g; - s;.*alpha.*;alpha;g; - s;.*sun4u.*;sun4u;g; - s;.*aarch64.*;arm64; - s;.*arm64.*;arm64; -'` +# OBJTYPE=`(uname -m -p 2>/dev/null || uname -m) | sed ' +# s;.*i[3-6]86.*;386;; +# s;.*i86pc.*;386;; +# s;.*amd64.*;x86_64;; +# s;.*x86_64.*;x86_64;; +# s;.*armv.*;arm;g; +# s;.*powerpc.*;power;g; +# s;.*PowerMacintosh.*;power;g; +# s;.*Power.Macintosh.*;power;g; +# s;.*macppc.*;power;g; +# s;.*mips.*;mips;g; +# s;.*ppc64.*;power;g; +# s;.*ppc.*;power;g; +# s;.*alpha.*;alpha;g; +# s;.*sun4u.*;sun4u;g; +# s;.*aarch64.*;arm64; +# s;.*arm64.*;arm64; +# '` INSTALL=`[ $(uname) = AIX ] && echo installbsd || echo install` diff --git a/src/mkfile b/src/mkfile index 4740780d..d17ca6b6 100644 --- a/src/mkfile +++ b/src/mkfile @@ -37,9 +37,7 @@ mkmk.sh:VD: ) | sed ' s/'$INSTALL'/$INSTALL/g s/'$SYSNAME'/$SYSNAME/g - s/'$OBJTYPE'/$OBJTYPE/g s;'$PLAN9';$PLAN9;g - s/^9[ac] *tas-.*/9a tas-$OBJTYPE.s || 9c tas-$OBJTYPE.c/ ' >$target testmkmk:V: diff --git a/unix/make/Make.Darwin b/unix/make/Make.Darwin new file mode 100644 index 00000000..21ede6f2 --- /dev/null +++ b/unix/make/Make.Darwin @@ -0,0 +1,7 @@ +CC=gcc +CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I${PREFIX}/include +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O +RANLIB=ranlib diff --git a/unix/make/Make.Darwin-386 b/unix/make/Make.Darwin-386 deleted file mode 100644 index 21ede6f2..00000000 --- a/unix/make/Make.Darwin-386 +++ /dev/null @@ -1,7 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I${PREFIX}/include -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O -RANLIB=ranlib diff --git a/unix/make/Make.Darwin-PowerMacintosh b/unix/make/Make.Darwin-PowerMacintosh deleted file mode 100644 index 21ede6f2..00000000 --- a/unix/make/Make.Darwin-PowerMacintosh +++ /dev/null @@ -1,7 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I${PREFIX}/include -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O -RANLIB=ranlib diff --git a/unix/make/Make.FreeBSD b/unix/make/Make.FreeBSD new file mode 100644 index 00000000..87aa579f --- /dev/null +++ b/unix/make/Make.FreeBSD @@ -0,0 +1,6 @@ +CC=gcc +CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I$(PREFIX)/include +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O diff --git a/unix/make/Make.FreeBSD-386 b/unix/make/Make.FreeBSD-386 deleted file mode 100644 index 87aa579f..00000000 --- a/unix/make/Make.FreeBSD-386 +++ /dev/null @@ -1,6 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I$(PREFIX)/include -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.HP-UX b/unix/make/Make.HP-UX new file mode 100644 index 00000000..edbdc111 --- /dev/null +++ b/unix/make/Make.HP-UX @@ -0,0 +1,6 @@ +CC=cc +CFLAGS=-O -c -Ae -I. +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O diff --git a/unix/make/Make.HP-UX-9000 b/unix/make/Make.HP-UX-9000 deleted file mode 100644 index edbdc111..00000000 --- a/unix/make/Make.HP-UX-9000 +++ /dev/null @@ -1,6 +0,0 @@ -CC=cc -CFLAGS=-O -c -Ae -I. -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.Linux b/unix/make/Make.Linux new file mode 100644 index 00000000..1fadb5f8 --- /dev/null +++ b/unix/make/Make.Linux @@ -0,0 +1,6 @@ +CC=gcc +CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -fPIC -O2 -g -c -I. +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O diff --git a/unix/make/Make.Linux-386 b/unix/make/Make.Linux-386 deleted file mode 100644 index c1dc4109..00000000 --- a/unix/make/Make.Linux-386 +++ /dev/null @@ -1,6 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.Linux-power b/unix/make/Make.Linux-power deleted file mode 100644 index c1dc4109..00000000 --- a/unix/make/Make.Linux-power +++ /dev/null @@ -1,6 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.Linux-x86_64 b/unix/make/Make.Linux-x86_64 deleted file mode 100644 index 1fadb5f8..00000000 --- a/unix/make/Make.Linux-x86_64 +++ /dev/null @@ -1,6 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -fPIC -O2 -g -c -I. -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.NetBSD b/unix/make/Make.NetBSD new file mode 100644 index 00000000..87aa579f --- /dev/null +++ b/unix/make/Make.NetBSD @@ -0,0 +1,6 @@ +CC=gcc +CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I$(PREFIX)/include +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O diff --git a/unix/make/Make.NetBSD-386 b/unix/make/Make.NetBSD-386 deleted file mode 100644 index 87aa579f..00000000 --- a/unix/make/Make.NetBSD-386 +++ /dev/null @@ -1,6 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I$(PREFIX)/include -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.OSF1 b/unix/make/Make.OSF1 new file mode 100644 index 00000000..3d45279b --- /dev/null +++ b/unix/make/Make.OSF1 @@ -0,0 +1,6 @@ +CC=cc +CFLAGS+=-g -c -I. +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O diff --git a/unix/make/Make.OSF1-alpha b/unix/make/Make.OSF1-alpha deleted file mode 100644 index 3d45279b..00000000 --- a/unix/make/Make.OSF1-alpha +++ /dev/null @@ -1,6 +0,0 @@ -CC=cc -CFLAGS+=-g -c -I. -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.OpenBSD b/unix/make/Make.OpenBSD new file mode 100644 index 00000000..87aa579f --- /dev/null +++ b/unix/make/Make.OpenBSD @@ -0,0 +1,6 @@ +CC=gcc +CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I$(PREFIX)/include +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O diff --git a/unix/make/Make.OpenBSD-386 b/unix/make/Make.OpenBSD-386 deleted file mode 100644 index 87aa579f..00000000 --- a/unix/make/Make.OpenBSD-386 +++ /dev/null @@ -1,6 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -I. -I$(PREFIX)/include -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.SunOS b/unix/make/Make.SunOS new file mode 100644 index 00000000..a306597b --- /dev/null +++ b/unix/make/Make.SunOS @@ -0,0 +1,2 @@ +include Make.SunOS-$(CC) +NAN=nan64.$O diff --git a/unix/make/Make.SunOS-cc b/unix/make/Make.SunOS-cc new file mode 100644 index 00000000..829301de --- /dev/null +++ b/unix/make/Make.SunOS-cc @@ -0,0 +1,6 @@ +CC=cc +CFLAGS+=-g -c -I. -O +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O diff --git a/unix/make/Make.SunOS-gcc b/unix/make/Make.SunOS-gcc new file mode 100644 index 00000000..5c415948 --- /dev/null +++ b/unix/make/Make.SunOS-gcc @@ -0,0 +1,6 @@ +CC=gcc +CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c +O=o +AR=ar +ARFLAGS=rvc +NAN=nan64.$O diff --git a/unix/make/Make.SunOS-sun4u b/unix/make/Make.SunOS-sun4u deleted file mode 100644 index c5fe67b8..00000000 --- a/unix/make/Make.SunOS-sun4u +++ /dev/null @@ -1,2 +0,0 @@ -include Make.SunOS-sun4u-$(CC) -NAN=nan64.$O diff --git a/unix/make/Make.SunOS-sun4u-cc b/unix/make/Make.SunOS-sun4u-cc deleted file mode 100644 index 829301de..00000000 --- a/unix/make/Make.SunOS-sun4u-cc +++ /dev/null @@ -1,6 +0,0 @@ -CC=cc -CFLAGS+=-g -c -I. -O -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Make.SunOS-sun4u-gcc b/unix/make/Make.SunOS-sun4u-gcc deleted file mode 100644 index 5c415948..00000000 --- a/unix/make/Make.SunOS-sun4u-gcc +++ /dev/null @@ -1,6 +0,0 @@ -CC=gcc -CFLAGS+=-Wall -Wno-missing-braces -Wno-parentheses -Wno-switch -O2 -g -c -O=o -AR=ar -ARFLAGS=rvc -NAN=nan64.$O diff --git a/unix/make/Makefile.TOP b/unix/make/Makefile.TOP index 516937e0..5feb1d47 100644 --- a/unix/make/Makefile.TOP +++ b/unix/make/Makefile.TOP @@ -1,18 +1,16 @@ # this works in gnu make SYSNAME:=${shell uname} -OBJTYPE:=${shell uname -m | sed 's;i.86;386;; s;/.*;;; s; ;;g'} # this works in bsd make SYSNAME!=uname -OBJTYPE!=uname -m | sed 's;i.86;386;; s;amd64;x864_64;; s;/.*;;; s; ;;g' # the gnu rules will mess up bsd but not vice versa, # hence the gnu rules come first. RANLIB=true -include Make.$(SYSNAME)-$(OBJTYPE) +include Make.$(SYSNAME) PREFIX=/usr/local -- cgit v1.2.3 From ebbeff0ac69f8fa25fed3f85d2e7b2261e4fa2aa Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 07:59:26 -0500 Subject: .gitignore: enumerate ignored parts of bin/ --- .gitignore | 235 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 218 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index f590cf28..61deffc6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,226 @@ -plan9.log -plan9-reverse.log -state -state.old -state.journal -*.o *.a -man/man?/*.html -src/**/o.* -y.tab.[ch] -src/cmd/rc/x.tab.h -unix/*.tgz -bin/ -log/ -dict/ -postscript/font/ -sky/here -sky/*.scat +*.o *.orig +bin/9660srv +bin/9import +bin/9p +bin/9pfuse +bin/9pserve +bin/9term +bin/Mail +bin/Netfiles +bin/acid +bin/acidtypes +bin/acme +bin/acmeevent +bin/aescbc +bin/ascii +bin/asn12dsa +bin/asn12rsa +bin/astro +bin/auxclog +bin/auxstats +bin/awk +bin/basename +bin/bc +bin/bmp +bin/bunzip2 +bin/bzip2 +bin/cal +bin/calendar +bin/cat +bin/cb +bin/cleanname +bin/clock +bin/cmapcube +bin/cmp +bin/col +bin/colors +bin/comm +bin/compress +bin/core +bin/crop +bin/date +bin/db +bin/dc +bin/dd +bin/delatex +bin/deroff +bin/devdraw +bin/dial +bin/dict +bin/diff +bin/disknfs +bin/dns +bin/dnsdebug +bin/dnsquery +bin/dnstcp +bin/dsa2pub +bin/dsa2ssh +bin/dsagen +bin/dsasign +bin/du +bin/dump9660 +bin/echo +bin/ed +bin/eqn +bin/factor +bin/factotum +bin/file +bin/fmt +bin/fontsrv +bin/fortune +bin/freq +bin/fsize +bin/getflags +bin/gif +bin/grap +bin/graph +bin/grep +bin/gunzip +bin/gview +bin/gzip +bin/hget +bin/hist +bin/hoc +bin/htmlfmt +bin/htmlroff +bin/ico +bin/iconv +bin/idiff +bin/img +bin/import +bin/join +bin/jpg +bin/lex +bin/listen1 +bin/look +bin/ls +bin/macargv +bin/mapd +bin/mc +bin/md5sum +bin/mk +bin/mkdir +bin/mklatinkbd +bin/mtime +bin/namespace +bin/ndbipquery +bin/ndbmkdb +bin/ndbmkhash +bin/ndbmkhosts +bin/ndbquery +bin/netkey +bin/news +bin/p +bin/page +bin/paint +bin/passwd +bin/pbd +bin/pemdecode +bin/pemencode +bin/pic +bin/plot +bin/plumb +bin/plumber +bin/png +bin/ppm +bin/pr +bin/primes +bin/proof +bin/psdownload +bin/ramfs +bin/rc +bin/read +bin/readcons +bin/resample +bin/rm +bin/rsa2csr +bin/rsa2pub +bin/rsa2ssh +bin/rsa2x509 +bin/rsafill +bin/rsagen +bin/sam +bin/samterm +bin/scat +bin/secstore +bin/secstored +bin/secuser +bin/sed +bin/seq +bin/sftpcache +bin/sha1sum +bin/sleep +bin/sort +bin/split +bin/sprog +bin/srv +bin/ssh-agent +bin/stats +bin/statusbar +bin/strings +bin/sum +bin/svgpic +bin/tail +bin/tar +bin/tbl +bin/tcolors +bin/tcs +bin/tee +bin/test +bin/time +bin/togif +bin/toico +bin/topng +bin/toppm +bin/touch +bin/tpic +bin/tr +bin/tr2post +bin/troff +bin/troff2html +bin/tweak +bin/uncompress +bin/unicode +bin/uniq +bin/units +bin/unutf +bin/unvac +bin/unzip +bin/usage +bin/vac +bin/vacfs +bin/vbackup +bin/vcat +bin/vmount0 +bin/vnfs +bin/wc +bin/win +bin/xd +bin/yacc +bin/yuv +bin/zcat +bin/zerotrunc +bin/zip config +dict/ install.log install.sum last-change +log/ +man/man?/*.html +plan9-reverse.log +plan9.log +postscript/font/ +sky/*.scat +sky/here +src/**/o.* src/cmd/awk/y.output src/cmd/devdraw/latin1.h +src/cmd/rc/x.tab.h +state +state.journal +state.old +unix/*.tgz +y.tab.[ch] -- cgit v1.2.3 From 0ed5e9f828757a17995e0550f285a11c1ff27026 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 08:07:24 -0500 Subject: 9a: remove a few mentions --- man/man1/9c.1 | 16 +--------------- src/mkhdr | 2 +- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/man/man1/9c.1 b/man/man1/9c.1 index dd15926d..943df6fb 100644 --- a/man/man1/9c.1 +++ b/man/man1/9c.1 @@ -1,6 +1,6 @@ .TH 9C 1 .SH NAME -9c, 9a, 9l, 9ar \- C compiler, assembler, linker, archiver +9c, 9l, 9ar \- C compiler, assembler, linker, archiver .SH SYNOPSIS .B 9c [ @@ -14,10 +14,6 @@ .I file \&... .PP -.B 9a -.I file -\&... -.PP .B 9l [ .I -o @@ -81,12 +77,6 @@ also defines .B __sun__ on SunOS systems. .PP -.I 9a -assembles the named files into object files for the current system. -Unlike some system assemblers, it does -.I not -promise to run the C preprocessor on the source files. -.PP .I 9l links the named object files and libraries to create the target executable. Each @@ -203,10 +193,6 @@ rebuilt whenever the archive is modified. Compile three C source files. .TP .L -9a file4.s -Assemble one assembler source file. -.TP -.L 9ar rvc lib.a file[12].o Archive the first two object files into a library. .TP diff --git a/src/mkhdr b/src/mkhdr index 35a2ccc5..77cf8559 100644 --- a/src/mkhdr +++ b/src/mkhdr @@ -9,7 +9,7 @@ OS=$O CC=9c #CC=9r LD=9l -AS=9a +AS=no-9a AR=9ar CFLAGS= LDFLAGS= -- cgit v1.2.3 From 74577741c856c145811061a438d5a52ea7055f39 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 08:12:04 -0500 Subject: tcolors: add threadmaybackground --- src/cmd/draw/tcolors.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmd/draw/tcolors.c b/src/cmd/draw/tcolors.c index 9aa4de79..05674947 100644 --- a/src/cmd/draw/tcolors.c +++ b/src/cmd/draw/tcolors.c @@ -44,6 +44,12 @@ dither[16] = { extern int chattydrawclient; +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { -- cgit v1.2.3 From 4692dd4786f8847494d3f020bc3c05ba210adc0d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 08:38:55 -0500 Subject: 9c: drop PLAN9PORT_ASAN It is no longer special. --- bin/9c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/bin/9c b/bin/9c index 4d488179..63840b19 100755 --- a/bin/9c +++ b/bin/9c @@ -26,10 +26,6 @@ usegcc() # that option only works with gcc3+ it seems cflags="$cflags -ggdb" cflags="$cflags $CC9FLAGS" - case "$cflags" in - *sanitize=address*) - cflags="$cflags -DPLAN9PORT_ASAN" - esac } quiet() @@ -87,11 +83,6 @@ useclang() " cflags="$cflags -g" cflags="$cflags $CC9FLAGS" - - case "$cflags" in - *sanitize=address*) - cflags="$cflags -DPLAN9PORT_ASAN" - esac } usexlc() -- cgit v1.2.3 From 91ececc99741b3111c69d455bc928e871b15d766 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 08:41:01 -0500 Subject: libthread: drop schedlock Having two locks in the proc was causing deadlocks. --- src/libthread/thread.c | 2 +- src/libthread/threadimpl.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libthread/thread.c b/src/libthread/thread.c index d72bf896..79e0ec71 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -281,7 +281,7 @@ static void pthreadwakeupschedlocked(Proc *p, _Thread *self, _Thread *t) { _threaddebug(self, "pthreadwakeupschedlocked %p %d", p, t->id);; - t->schedrend.l = &p->schedlock; + t->schedrend.l = &p->lock; p->schedthread = t; _procwakeup(&t->schedrend); } diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h index 9eddba21..fd40f252 100644 --- a/src/libthread/threadimpl.h +++ b/src/libthread/threadimpl.h @@ -88,7 +88,6 @@ struct Proc uint nthread; uint sysproc; _Procrendez runrend; - Lock schedlock; _Thread *schedthread; void *udata; Jmp sigjmp; -- cgit v1.2.3 From ee9b2a22996e29d55b97f7717163989173c71747 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 08:44:15 -0500 Subject: .gitignore: more binaries --- .gitignore | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/.gitignore b/.gitignore index 61deffc6..bb7c160d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ *.a *.o *.orig +bin/" +bin/"" bin/9660srv bin/9import bin/9p @@ -50,6 +52,8 @@ bin/devdraw bin/dial bin/dict bin/diff +bin/disk/mkext +bin/disk/mkfs bin/disknfs bin/dns bin/dnsdebug @@ -70,7 +74,21 @@ bin/file bin/fmt bin/fontsrv bin/fortune +bin/fossil/conf +bin/fossil/flchk +bin/fossil/flfmt +bin/fossil/fossil +bin/fossil/last +bin/fossil/view bin/freq +bin/fs/32vfs +bin/fs/cpiofs +bin/fs/tapfs +bin/fs/tarfs +bin/fs/tpfs +bin/fs/v10fs +bin/fs/v6fs +bin/fs/zipfs bin/fsize bin/getflags bin/gif @@ -101,6 +119,7 @@ bin/mapd bin/mc bin/md5sum bin/mk +bin/mk9660 bin/mkdir bin/mklatinkbd bin/mtime @@ -110,6 +129,10 @@ bin/ndbmkdb bin/ndbmkhash bin/ndbmkhosts bin/ndbquery +bin/netfileget +bin/netfilelib.rc +bin/netfileput +bin/netfilestat bin/netkey bin/news bin/p @@ -193,6 +216,31 @@ bin/vac bin/vacfs bin/vbackup bin/vcat +bin/venti/buildindex +bin/venti/checkarenas +bin/venti/checkindex +bin/venti/clumpstats +bin/venti/conf +bin/venti/copy +bin/venti/dump +bin/venti/findscore +bin/venti/fixarenas +bin/venti/fmtarenas +bin/venti/fmtbloom +bin/venti/fmtindex +bin/venti/fmtisect +bin/venti/mirrorarenas +bin/venti/printarena +bin/venti/printarenapart +bin/venti/rdarena +bin/venti/read +bin/venti/ro +bin/venti/sync +bin/venti/syncindex +bin/venti/venti +bin/venti/verifyarena +bin/venti/wrarena +bin/venti/write bin/vmount0 bin/vnfs bin/wc -- cgit v1.2.3 From f23783cbb197f71f867bd9d44abfa8787a65448b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 08:46:47 -0500 Subject: .gitignore: add LOCAL.config and lib/fortunes.index --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index bb7c160d..ad8a20de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.a *.o *.orig +LOCAL.config bin/" bin/"" bin/9660srv @@ -256,6 +257,7 @@ dict/ install.log install.sum last-change +lib/fortunes.index log/ man/man?/*.html plan9-reverse.log -- cgit v1.2.3 From dbc153f51e2af8fabe43b0c408d27f2dd6b09925 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 10:40:25 -0500 Subject: 9term: add threadmaybackground --- src/cmd/9term/9term.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmd/9term/9term.c b/src/cmd/9term/9term.c index b28f44fa..d7391cf5 100644 --- a/src/cmd/9term/9term.c +++ b/src/cmd/9term/9term.c @@ -47,6 +47,12 @@ usage(void) threadexitsall("usage"); } +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { -- cgit v1.2.3 From 6c8e44dd2e3b346ad5e313830ef22ee7b0a9df04 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 30 Dec 2020 20:36:09 +0100 Subject: wintext: add to moveplan9.files (#470) --- lib/moveplan9.files | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/moveplan9.files b/lib/moveplan9.files index 16535103..fe47d4ab 100644 --- a/lib/moveplan9.files +++ b/lib/moveplan9.files @@ -34,6 +34,7 @@ bin/upas/unspambox bin/venti/conf bin/vmount bin/vwhois +bin/wintext bin/yesterday dist/debian/mkpkg dist/debian/mkrep -- cgit v1.2.3 From ac487c754e009b0f3c01c2a8ad5bda2143da4a6b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 30 Dec 2020 14:42:47 -0500 Subject: acme: allow @ in file names For upspin and other tools that put email addresses in names. --- src/cmd/acme/look.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/acme/look.c b/src/cmd/acme/look.c index 35667c6c..a7172b50 100644 --- a/src/cmd/acme/look.c +++ b/src/cmd/acme/look.c @@ -378,7 +378,7 @@ search(Text *ct, Rune *r, uint n) int isfilec(Rune r) { - static Rune Lx[] = { '.', '-', '+', '/', ':', 0 }; + static Rune Lx[] = { '.', '-', '+', '/', ':', '@', 0 }; if(isalnum(r)) return TRUE; if(runestrchr(Lx, r)) -- cgit v1.2.3 From 7f6458b045e04b97dd06b3171ac67e9ecde32429 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 5 Jan 2021 23:35:33 -0500 Subject: stats: add threadmaybackground --- src/cmd/devdraw/mac-screen.m | 5 +++- src/cmd/draw/stats.c | 6 ++++ src/cmd/sam/cmd.c | 70 ++++++++++++++++++++++---------------------- src/cmd/sam/parse.h | 6 ++-- src/cmd/sam/sam.h | 2 -- 5 files changed, 49 insertions(+), 40 deletions(-) diff --git a/src/cmd/devdraw/mac-screen.m b/src/cmd/devdraw/mac-screen.m index ad9c029e..9e51eec6 100644 --- a/src/cmd/devdraw/mac-screen.m +++ b/src/cmd/devdraw/mac-screen.m @@ -238,11 +238,14 @@ rpc_attach(Client *c, char *label, char *winsize) char *s; NSArray *allDevices; - const NSWindowStyleMask Winstyle = NSWindowStyleMaskTitled + NSWindowStyleMask Winstyle = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable; + if(label == nil || *label == '\0') + Winstyle &= ~NSWindowStyleMaskTitled; + s = winsize; sr = [[NSScreen mainScreen] frame]; r = [[NSScreen mainScreen] visibleFrame]; diff --git a/src/cmd/draw/stats.c b/src/cmd/draw/stats.c index 3b6471b7..d74b95e3 100644 --- a/src/cmd/draw/stats.c +++ b/src/cmd/draw/stats.c @@ -675,6 +675,12 @@ keyboardthread(void *v) void machproc(void*); void updateproc(void*); +int +threadmaybackground(void) +{ + return 1; +} + void threadmain(int argc, char *argv[]) { diff --git a/src/cmd/sam/cmd.c b/src/cmd/sam/cmd.c index 386fe8d4..7176a827 100644 --- a/src/cmd/sam/cmd.c +++ b/src/cmd/sam/cmd.c @@ -3,41 +3,41 @@ static char linex[]="\n"; static char wordx[]=" \t\n"; -struct cmdtab cmdtab[]={ +struct Cmdtab cmdtab[]={ /* cmdc text regexp addr defcmd defaddr count token fn */ - '\n', 0, 0, 0, 0, aDot, 0, 0, nl_cmd, - 'a', 1, 0, 0, 0, aDot, 0, 0, a_cmd, - 'b', 0, 0, 0, 0, aNo, 0, linex, b_cmd, - 'B', 0, 0, 0, 0, aNo, 0, linex, b_cmd, - 'c', 1, 0, 0, 0, aDot, 0, 0, c_cmd, - 'd', 0, 0, 0, 0, aDot, 0, 0, d_cmd, - 'D', 0, 0, 0, 0, aNo, 0, linex, D_cmd, - 'e', 0, 0, 0, 0, aNo, 0, wordx, e_cmd, - 'f', 0, 0, 0, 0, aNo, 0, wordx, f_cmd, - 'g', 0, 1, 0, 'p', aDot, 0, 0, g_cmd, - 'i', 1, 0, 0, 0, aDot, 0, 0, i_cmd, - 'k', 0, 0, 0, 0, aDot, 0, 0, k_cmd, - 'm', 0, 0, 1, 0, aDot, 0, 0, m_cmd, - 'n', 0, 0, 0, 0, aNo, 0, 0, n_cmd, - 'p', 0, 0, 0, 0, aDot, 0, 0, p_cmd, - 'q', 0, 0, 0, 0, aNo, 0, 0, q_cmd, - 'r', 0, 0, 0, 0, aDot, 0, wordx, e_cmd, - 's', 0, 1, 0, 0, aDot, 1, 0, s_cmd, - 't', 0, 0, 1, 0, aDot, 0, 0, m_cmd, - 'u', 0, 0, 0, 0, aNo, 2, 0, u_cmd, - 'v', 0, 1, 0, 'p', aDot, 0, 0, g_cmd, - 'w', 0, 0, 0, 0, aAll, 0, wordx, w_cmd, - 'x', 0, 1, 0, 'p', aDot, 0, 0, x_cmd, - 'y', 0, 1, 0, 'p', aDot, 0, 0, x_cmd, - 'X', 0, 1, 0, 'f', aNo, 0, 0, X_cmd, - 'Y', 0, 1, 0, 'f', aNo, 0, 0, X_cmd, - '!', 0, 0, 0, 0, aNo, 0, linex, plan9_cmd, - '>', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, - '<', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, - '|', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd, - '=', 0, 0, 0, 0, aDot, 0, linex, eq_cmd, - 'c'|0x100,0, 0, 0, 0, aNo, 0, wordx, cd_cmd, - 0, 0, 0, 0, 0, 0, 0, 0 + {'\n', 0, 0, 0, 0, aDot, 0, 0, nl_cmd}, + {'a', 1, 0, 0, 0, aDot, 0, 0, a_cmd}, + {'b', 0, 0, 0, 0, aNo, 0, linex, b_cmd}, + {'B', 0, 0, 0, 0, aNo, 0, linex, b_cmd}, + {'c', 1, 0, 0, 0, aDot, 0, 0, c_cmd}, + {'d', 0, 0, 0, 0, aDot, 0, 0, d_cmd}, + {'D', 0, 0, 0, 0, aNo, 0, linex, D_cmd}, + {'e', 0, 0, 0, 0, aNo, 0, wordx, e_cmd}, + {'f', 0, 0, 0, 0, aNo, 0, wordx, f_cmd}, + {'g', 0, 1, 0, 'p', aDot, 0, 0, g_cmd}, + {'i', 1, 0, 0, 0, aDot, 0, 0, i_cmd}, + {'k', 0, 0, 0, 0, aDot, 0, 0, k_cmd}, + {'m', 0, 0, 1, 0, aDot, 0, 0, m_cmd}, + {'n', 0, 0, 0, 0, aNo, 0, 0, n_cmd}, + {'p', 0, 0, 0, 0, aDot, 0, 0, p_cmd}, + {'q', 0, 0, 0, 0, aNo, 0, 0, q_cmd}, + {'r', 0, 0, 0, 0, aDot, 0, wordx, e_cmd}, + {'s', 0, 1, 0, 0, aDot, 1, 0, s_cmd}, + {'t', 0, 0, 1, 0, aDot, 0, 0, m_cmd}, + {'u', 0, 0, 0, 0, aNo, 2, 0, u_cmd}, + {'v', 0, 1, 0, 'p', aDot, 0, 0, g_cmd}, + {'w', 0, 0, 0, 0, aAll, 0, wordx, w_cmd}, + {'x', 0, 1, 0, 'p', aDot, 0, 0, x_cmd}, + {'y', 0, 1, 0, 'p', aDot, 0, 0, x_cmd}, + {'X', 0, 1, 0, 'f', aNo, 0, 0, X_cmd}, + {'Y', 0, 1, 0, 'f', aNo, 0, 0, X_cmd}, + {'!', 0, 0, 0, 0, aNo, 0, linex, plan9_cmd}, + {'>', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd}, + {'<', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd}, + {'|', 0, 0, 0, 0, aDot, 0, linex, plan9_cmd}, + {'=', 0, 0, 0, 0, aDot, 0, linex, eq_cmd}, + {'c'|0x100,0, 0, 0, 0, aNo, 0, wordx, cd_cmd}, + {0, 0, 0, 0, 0, 0, 0, 0}, }; Cmd *parsecmd(int); Addr *compoundaddr(void); @@ -402,7 +402,7 @@ Cmd * parsecmd(int nest) { int i, c; - struct cmdtab *ct; + Cmdtab *ct; Cmd *cp, *ncp; Cmd cmd; diff --git a/src/cmd/sam/parse.h b/src/cmd/sam/parse.h index d5fabf14..dd837a48 100644 --- a/src/cmd/sam/parse.h +++ b/src/cmd/sam/parse.h @@ -33,7 +33,8 @@ struct Cmd #define ctext g.text #define caddr g.addr -extern struct cmdtab{ +typedef struct Cmdtab Cmdtab; +struct Cmdtab { ushort cmdc; /* command character */ uchar text; /* takes a textual argument? */ uchar regexp; /* takes a regular expression? */ @@ -43,7 +44,8 @@ extern struct cmdtab{ uchar count; /* takes a count e.g. s2/// */ char *token; /* takes text terminated by one of these */ int (*fn)(File*, Cmd*); /* function to call with parse tree */ -}cmdtab[]; +}; +extern Cmdtab cmdtab[]; enum Defaddr{ /* default addresses */ aNo, diff --git a/src/cmd/sam/sam.h b/src/cmd/sam/sam.h index aae39b4a..6e018156 100644 --- a/src/cmd/sam/sam.h +++ b/src/cmd/sam/sam.h @@ -37,7 +37,6 @@ typedef struct Address Address; typedef struct Block Block; typedef struct Buffer Buffer; typedef struct Disk Disk; -typedef struct Discdesc Discdesc; typedef struct File File; typedef struct List List; typedef struct Range Range; @@ -342,7 +341,6 @@ void warn_S(Warn, String*); int whichmenu(File*); void writef(File*); Posn writeio(File*); -Discdesc *Dstart(void); extern Rune samname[]; /* compiler dependent */ extern Rune *left[]; -- cgit v1.2.3 From 0a513e65607223d11ba94003256b13ef5779e7e8 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sun, 3 Jan 2021 00:54:20 -0500 Subject: sam: rm dregs --- src/cmd/sam/README | 29 -------- src/cmd/sam/_libc.h | 40 ------------ src/cmd/sam/err | 39 ----------- src/cmd/sam/plan9.c | 185 ---------------------------------------------------- 4 files changed, 293 deletions(-) delete mode 100644 src/cmd/sam/README delete mode 100644 src/cmd/sam/_libc.h delete mode 100644 src/cmd/sam/err delete mode 100644 src/cmd/sam/plan9.c diff --git a/src/cmd/sam/README b/src/cmd/sam/README deleted file mode 100644 index b78a89da..00000000 --- a/src/cmd/sam/README +++ /dev/null @@ -1,29 +0,0 @@ -This is sam (not including samterm) from the 4th edition of Plan 9, -with changes so that it can be compiled under unix. -(Tested on Solaris 7 and Debian 3.0r1.) - -Some extra libraries are needed. First, fetch libutf-2.0 and libfmt-2.0 -from - http://pdos.lcs.mit.edu/~rsc/software/ - -(Beware that in libfmt/fmt.c there is a line that says: - 'u', __ifmt, /* in Plan 9, __flagfmt */ -Thus, sam will have to fmtinstall the other thing. Other ported programs -may have to do the same. The fmt library should probably print messages -about bad format characters to stderr, since no one seems to check the -return codes.) - -Compile and install those two libraries. -Set PREFIX in the Makefile to match, then compile sam. - -Your C compiler will emit many complaints of the form: - sam.c:496: warning: passing arg 1 of `bufread' from incompatible pointer type - -This is because the Plan 9 compiler has a slightly different (better, -ala Oberon) type system than ISO C. Popular compilers generate the right -code, so in an act of civil disobediance I changed just enough to get -it to compile, but left the type errors in. Now the next C standard can -adopt this extension, because at least one important C program uses it! - --- Scott Schwartz, 4 July 2003 - diff --git a/src/cmd/sam/_libc.h b/src/cmd/sam/_libc.h deleted file mode 100644 index 65618918..00000000 --- a/src/cmd/sam/_libc.h +++ /dev/null @@ -1,40 +0,0 @@ -#define __USE_UNIX98 // for pread/pwrite, supposedly -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "utf.h" -#include "fmt.h" - -#define nil 0 -#define dup dup2 -#define exec execv -#define seek lseek -#define getwd getcwd -#define USED(a) -#define SET(a) - -enum { - OREAD = 0, - OWRITE = 1, - ORDWR = 2, - OCEXEC = 4, - ORCLOSE = 8 -}; - -enum { - ERRMAX = 255 -}; - -void exits(const char *); -void _exits(const char *); -int notify (void(*f)(void *, char *)); -int create(char *, int, int); -int errstr(char *, int); diff --git a/src/cmd/sam/err b/src/cmd/sam/err deleted file mode 100644 index 2a36c23b..00000000 --- a/src/cmd/sam/err +++ /dev/null @@ -1,39 +0,0 @@ -address.c: In function `filematch': -address.c:159: warning: passing arg 1 of `bufreset' from incompatible pointer type -address.c:160: warning: passing arg 1 of `bufinsert' from incompatible pointer type -file.c: In function `mergeextend': -file.c:117: warning: passing arg 1 of `bufread' from incompatible pointer type -file.c: In function `fileinsert': -file.c:275: warning: passing arg 1 of `bufinsert' from incompatible pointer type -file.c: In function `filedelete': -file.c:301: warning: passing arg 1 of `bufdelete' from incompatible pointer type -file.c: In function `fileundelete': -file.c:324: warning: passing arg 1 of `bufread' from incompatible pointer type -file.c: In function `filereadc': -file.c:339: warning: passing arg 1 of `bufread' from incompatible pointer type -file.c: In function `fileload': -file.c:405: warning: passing arg 1 of `bufload' from incompatible pointer type -file.c: In function `fileundo': -file.c:528: warning: passing arg 1 of `bufdelete' from incompatible pointer type -file.c:546: warning: passing arg 1 of `bufinsert' from incompatible pointer type -file.c: In function `fileclose': -file.c:604: warning: passing arg 1 of `bufclose' from incompatible pointer type -io.c: In function `readio': -io.c:90: warning: passing arg 1 of `bufload' from incompatible pointer type -io.c: In function `writeio': -io.c:152: warning: passing arg 1 of `bufread' from incompatible pointer type -mesg.c: In function `inmesg': -mesg.c:248: warning: passing arg 1 of `bufread' from incompatible pointer type -mesg.c: In function `snarf': -mesg.c:568: warning: passing arg 1 of `bufread' from incompatible pointer type -mesg.c: In function `setgenstr': -mesg.c:612: warning: passing arg 1 of `bufread' from incompatible pointer type -sam.c: In function `readcmd': -sam.c:496: warning: passing arg 1 of `bufread' from incompatible pointer type -sam.c: In function `copy': -sam.c:676: warning: passing arg 1 of `bufread' from incompatible pointer type -xec.c: In function `s_cmd': -xec.c:234: warning: passing arg 1 of `bufread' from incompatible pointer type -xec.c:243: warning: passing arg 1 of `bufread' from incompatible pointer type -xec.c: In function `display': -xec.c:401: warning: passing arg 1 of `bufread' from incompatible pointer type diff --git a/src/cmd/sam/plan9.c b/src/cmd/sam/plan9.c deleted file mode 100644 index 0a3fe070..00000000 --- a/src/cmd/sam/plan9.c +++ /dev/null @@ -1,185 +0,0 @@ -#include "sam.h" - -Rune samname[] = L"~~sam~~"; - -Rune *left[]= { - L"{[(<«", - L"\n", - L"'\"`", - 0 -}; -Rune *right[]= { - L"}])>»", - L"\n", - L"'\"`", - 0 -}; - -char RSAM[] = "sam"; -char SAMTERM[] = "/bin/aux/samterm"; -char HOME[] = "HOME"; -char TMPDIR[] = "/tmp"; -char SH[] = "rc"; -char SHPATH[] = "/bin/rc"; -char RX[] = "rx"; -char RXPATH[] = "/bin/rx"; -char SAMSAVECMD[] = "/bin/rc\n/sys/lib/samsave"; - -void -dprint(char *z, ...) -{ - char buf[BLOCKSIZE]; - va_list arg; - - va_start(arg, z); - vseprint(buf, &buf[BLOCKSIZE], z, arg); - va_end(arg); - termwrite(buf); -} - -void -print_ss(char *s, String *a, String *b) -{ - dprint("?warning: %s: `%.*S' and `%.*S'\n", s, a->n, a->s, b->n, b->s); -} - -void -print_s(char *s, String *a) -{ - dprint("?warning: %s `%.*S'\n", s, a->n, a->s); -} - -char* -getuser(void) -{ - static char user[64]; - int fd; - - if(user[0] == 0){ - fd = open("/dev/user", 0); - if(fd<0 || read(fd, user, sizeof user-1)<=0) - strcpy(user, "none"); - close(fd); - } - return user; -} - -int -statfile(char *name, ulong *dev, uvlong *id, long *time, long *length, long *appendonly) -{ - Dir *dirb; - - dirb = dirstat(name); - if(dirb == nil) - return -1; - if(dev) - *dev = dirb->type|(dirb->dev<<16); - if(id) - *id = dirb->qid.path; - if(time) - *time = dirb->mtime; - if(length) - *length = dirb->length; - if(appendonly) - *appendonly = dirb->mode & DMAPPEND; - free(dirb); - return 1; -} - -int -statfd(int fd, ulong *dev, uvlong *id, long *time, long *length, long *appendonly) -{ - Dir *dirb; - - dirb = dirfstat(fd); - if(dirb == nil) - return -1; - if(dev) - *dev = dirb->type|(dirb->dev<<16); - if(id) - *id = dirb->qid.path; - if(time) - *time = dirb->mtime; - if(length) - *length = dirb->length; - if(appendonly) - *appendonly = dirb->mode & DMAPPEND; - free(dirb); - return 1; -} - -void -notifyf(void *a, char *s) -{ - USED(a); - if(bpipeok && strcmp(s, "sys: write on closed pipe") == 0) - noted(NCONT); - if(strcmp(s, "interrupt") == 0) - noted(NCONT); - panicking = 1; - rescue(); - noted(NDFLT); -} - -int -newtmp(int num) -{ - int i, fd; - static char tempnam[30]; - - i = getpid(); - do - snprint(tempnam, sizeof tempnam, "%s/%d%.4s%dsam", TMPDIR, num, getuser(), i++); - while(access(tempnam, 0) == 0); - fd = create(tempnam, ORDWR|OCEXEC|ORCLOSE, 0000); - if(fd < 0){ - remove(tempnam); - fd = create(tempnam, ORDWR|OCEXEC|ORCLOSE, 0000); - } - return fd; -} - -int -waitfor(int pid) -{ - int msg; - Waitmsg *w; - - while((w = wait()) != nil){ - if(w->pid != pid){ - free(w); - continue; - } - msg = (w->msg[0] != '\0'); - free(w); - return msg; - } - return -1; -} - -void -samerr(char *buf) -{ - sprint(buf, "%s/sam.err", TMPDIR); -} - -void* -emalloc(ulong n) -{ - void *p; - - p = malloc(n); - if(p == 0) - panic("malloc fails"); - memset(p, 0, n); - return p; -} - -void* -erealloc(void *p, ulong n) -{ - p = realloc(p, n); - if(p == 0) - panic("realloc fails"); - return p; -} -- cgit v1.2.3 From 1c845e0bd5ff897dc5e90f2c24db4ecd81a8f60c Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 5 Jan 2021 23:38:09 -0500 Subject: acme, sam, samterm: remove weird switch usage For whatever reason all three of these programs contain switches like: switch(x) { case 1: if(cond) case 2: f(); } Like Duff's device, this is legal C but more obscure than it really needs to be. This commit assumes those are intended as written and simply writes them more clearly. I did consider that maybe they are mistakes, but in the case of sam/regexp.c, my rewrite in this commit matches the acme/regx.c that has been in plan9port since I added acme in 2003. (I didn't bother to dig up the old Plan 9 releases.) Assuming acme/regx.c has been correct for the past two decades, this commit should be correct too. --- src/cmd/acme/edit.c | 6 ++++-- src/cmd/sam/cmd.c | 6 ++++-- src/cmd/sam/regexp.c | 2 +- src/cmd/samterm/flayer.c | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cmd/acme/edit.c b/src/cmd/acme/edit.c index 81f80300..82a19b0d 100644 --- a/src/cmd/acme/edit.c +++ b/src/cmd/acme/edit.c @@ -635,9 +635,11 @@ simpleaddr(void) case '.': case '$': case '\'': - if(addr.type!='"') + if(addr.type=='"') + break; + /* fall through */ case '"': - editerror("bad address syntax"); + editerror("bad address syntax"); break; case 'l': case '#': diff --git a/src/cmd/sam/cmd.c b/src/cmd/sam/cmd.c index 7176a827..13bd17e0 100644 --- a/src/cmd/sam/cmd.c +++ b/src/cmd/sam/cmd.c @@ -559,9 +559,11 @@ simpleaddr(void) case '.': case '$': case '\'': - if(addr.type!='"') + if(addr.type=='"') + break; + /* fall through */ case '"': - error(Eaddress); + error(Eaddress); break; case 'l': case '#': diff --git a/src/cmd/sam/regexp.c b/src/cmd/sam/regexp.c index 2e369fe1..57c639d9 100644 --- a/src/cmd/sam/regexp.c +++ b/src/cmd/sam/regexp.c @@ -700,11 +700,11 @@ bexecute(File *f, Posn startp) break; case 1: /* expired; wrap to end */ if(sel.p[0].p1>=0) - case 3: goto Return; list[0][0].inst = list[1][0].inst = 0; p = f->b.nc; goto doloop; + case 3: default: goto Return; } diff --git a/src/cmd/samterm/flayer.c b/src/cmd/samterm/flayer.c index e9fde31c..a8e70d0c 100644 --- a/src/cmd/samterm/flayer.c +++ b/src/cmd/samterm/flayer.c @@ -169,8 +169,8 @@ newvisibilities(int redraw) break; case V(Some, Some): - if(l->f.b==0 && redraw) case V(None, Some): + if(ov == None || (l->f.b==0 && redraw)) flprepare(l); if(l->f.b && redraw){ flrefresh(l, l->entire, 0); -- cgit v1.2.3 From fdcf3d70c24886dddb5fd7052dfada67d33d5c75 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 09:58:44 -0500 Subject: auxstats: do not postnote 0 --- src/cmd/auxstats/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/auxstats/main.c b/src/cmd/auxstats/main.c index 3fd77ac4..a37c9723 100644 --- a/src/cmd/auxstats/main.c +++ b/src/cmd/auxstats/main.c @@ -21,7 +21,8 @@ notifyf(void *v, char *msg) if(strstr(msg, "child")) noted(NCONT); - postnote(PNPROC, pid, msg); + if(pid) + postnote(PNPROC, pid, msg); exits(nil); } -- cgit v1.2.3 From 0cc1faf015a253ef64b97a8453b6fc959c0ee512 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 09:59:03 -0500 Subject: lib9: reject postnote with special pids --- src/lib9/postnote.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib9/postnote.c b/src/lib9/postnote.c index 68e6d2f6..d750c69d 100644 --- a/src/lib9/postnote.c +++ b/src/lib9/postnote.c @@ -18,6 +18,11 @@ postnote(int who, int pid, char *msg) return -1; } + if(pid <= 0){ + werrstr("bad pid in postnote"); + return -1; + } + switch(who){ default: werrstr("bad who in postnote"); -- cgit v1.2.3 From c3ae85a004c8714fc653629a983327d9a15b36da Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 09:59:54 -0500 Subject: rc: do not exit on EINTR from read This happens if lldb attaches to rc. --- src/cmd/rc/io.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cmd/rc/io.c b/src/cmd/rc/io.c index c2e9d7b4..907ba86f 100644 --- a/src/cmd/rc/io.c +++ b/src/cmd/rc/io.c @@ -1,4 +1,5 @@ #include +#include #include "rc.h" #include "exec.h" #include "io.h" @@ -257,7 +258,15 @@ int emptybuf(io *f) { int n; - if(f->fd==-1 || (n = Read(f->fd, f->buf, NBUF))<=0) return EOF; + if(f->fd==-1) + return EOF; +Loop: + errno = 0; + n = Read(f->fd, f->buf, NBUF); + if(n < 0 && errno == EINTR) + goto Loop; + if(n <= 0) + return EOF; f->bufp = f->buf; f->ebuf = f->buf+n; return *f->bufp++&0xff; -- cgit v1.2.3 From 6a80119eb509bd948d87ad1b84b0a82855a3c691 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 10:01:25 -0500 Subject: sam: remove backward ?: The exit code here is ignored anyway. --- src/cmd/sam/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/sam/shell.c b/src/cmd/sam/shell.c index c6efdd57..92bd5277 100644 --- a/src/cmd/sam/shell.c +++ b/src/cmd/sam/shell.c @@ -90,7 +90,7 @@ plan9(File *f, int type, String *s, int nest) free(c); } } - exits(retcode? "error" : 0); + exits(0); } if(pid==-1){ fprint(2, "Can't fork?!\n"); -- cgit v1.2.3 From 3ccd61629b641613bcccbc51125330efab9c89a7 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 10:05:50 -0500 Subject: sam: avoid out-of-bounds read in rterm Usually r->nused < r->nalloc and the read is in bounds. But it could in theory be right on the line and reading past the end of the allocation. Make it safe but preserve as much of the old semantics as possible. This use of rterm appears to be only for optimization purposes so the result does not matter for correctness. --- src/cmd/sam/rasp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/sam/rasp.c b/src/cmd/sam/rasp.c index c96101df..55d16cfb 100644 --- a/src/cmd/sam/rasp.c +++ b/src/cmd/sam/rasp.c @@ -283,8 +283,8 @@ rterm(List *r, Posn p1) for(p = 0,i = 0; inused && p+L(i)<=p1; p+=L(i++)) ; - if(i==r->nused && (i==0 || !T(i-1))) - return 0; + if(i==r->nused) + return i > 0 && T(i-1); return T(i); } -- cgit v1.2.3 From 52b599a63c488d3a80bb9f5dd97bad0b10103c54 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 14 Jan 2021 10:30:24 -0500 Subject: libthread: call setpgrp in programs that will background This fixes the 'run stats from rc; exit rc; stats dies' problem. It's unclear whether this is the right fix or whether rc should be starting all its interactive commands in their own process groups. But at least it does fix stats dying. --- src/libthread/daemonize.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libthread/daemonize.c b/src/libthread/daemonize.c index f994ffe1..29929068 100644 --- a/src/libthread/daemonize.c +++ b/src/libthread/daemonize.c @@ -101,6 +101,13 @@ _threadsetupdaemonize(void) sigpid = 1; + /* + * We've been told this program is likely to background itself. + * Put it in its own process group so that we don't get a SIGHUP + * when the parent exits. + */ + setpgrp(); + if(pipe(p) < 0) sysfatal("passer pipe: %r"); -- cgit v1.2.3 From 4056d6be4d0fca6fc5e6ccfd24ff4785db9fec15 Mon Sep 17 00:00:00 2001 From: Xiao-Yong Jin Date: Fri, 29 Jan 2021 05:12:42 +0000 Subject: libhtml: fix array bounds in lex --- src/libhtml/lex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libhtml/lex.c b/src/libhtml/lex.c index 49c5f502..82324ba5 100644 --- a/src/libhtml/lex.c +++ b/src/libhtml/lex.c @@ -586,7 +586,7 @@ getplaindata(TokenSource* ts, Token* a, int* pai) } if(c != 0){ buf[j++] = c; - if(j == sizeof(buf)-1){ + if(j == BIGBUFSIZE-1){ s = buftostr(s, buf, j); j = 0; } -- cgit v1.2.3 From 20c14efad6487b0a09ecd661680321afa240bc0b Mon Sep 17 00:00:00 2001 From: Xiao-Yong Jin Date: Fri, 29 Jan 2021 05:30:08 +0000 Subject: xd: fix swizz8 loop counting --- src/cmd/xd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/xd.c b/src/cmd/xd.c index 9f83e1cf..2cfbcfd1 100644 --- a/src/cmd/xd.c +++ b/src/cmd/xd.c @@ -327,7 +327,7 @@ swizz8(void) *q++ = *p++; p = data; q = swdata; - for(i=0; i<8; i++){ + for(i=0; i<2; i++){ p[0] = q[7]; p[1] = q[6]; p[2] = q[5]; -- cgit v1.2.3 From 4e6bb208eb96baae65fd6b1bf99aaa1115b9a9ba Mon Sep 17 00:00:00 2001 From: Xiao-Yong Jin Date: Fri, 29 Jan 2021 05:35:40 +0000 Subject: eqn: enlarge errbuf to account for large tokens --- src/cmd/eqn/e.h | 2 +- src/cmd/eqn/input.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/eqn/e.h b/src/cmd/eqn/e.h index 07dc4df6..f2a71849 100644 --- a/src/cmd/eqn/e.h +++ b/src/cmd/eqn/e.h @@ -20,7 +20,7 @@ extern int class[LAST][LAST]; #undef sprintf /* Snow Leopard */ -extern char errbuf[200]; +extern char errbuf[2000]; extern char *cmdname; #define ERROR sprintf(errbuf, #define FATAL ), error(1, errbuf) diff --git a/src/cmd/eqn/input.c b/src/cmd/eqn/input.c index a0c0c34e..b146171b 100644 --- a/src/cmd/eqn/input.c +++ b/src/cmd/eqn/input.c @@ -255,7 +255,7 @@ void yyerror(char *s) error(0, s); /* temporary */ } -char errbuf[200]; +char errbuf[2000]; void eprint(void) /* try to print context around error */ { -- cgit v1.2.3 From 0144f87dc6c7f2f6becbd55519e433a9b36a466f Mon Sep 17 00:00:00 2001 From: Xiao-Yong Jin Date: Fri, 29 Jan 2021 05:38:41 +0000 Subject: htmlroff: fix array bounds --- src/cmd/htmlroff/roff.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/htmlroff/roff.c b/src/cmd/htmlroff/roff.c index 34b794be..f52e0734 100644 --- a/src/cmd/htmlroff/roff.c +++ b/src/cmd/htmlroff/roff.c @@ -257,7 +257,7 @@ copyarg(void) int c; Rune *r; - if(_readx(buf, sizeof buf, ArgMode, 0) < 0) + if(_readx(buf, MaxLine, ArgMode, 0) < 0) return nil; r = runestrstr(buf, L("\\\"")); if(r){ @@ -280,7 +280,7 @@ readline(int m) static Rune buf[MaxLine]; Rune *r; - if(_readx(buf, sizeof buf, m, 1) < 0) + if(_readx(buf, MaxLine, m, 1) < 0) return nil; r = erunestrdup(buf); return r; -- cgit v1.2.3 From 36cd4c58c1346375b98f517fb8568be5bb47618d Mon Sep 17 00:00:00 2001 From: Fazlul Shahriar Date: Fri, 29 Jan 2021 18:55:29 -0500 Subject: man9: rename IM to MR Commit d32deab17bfffa5bffc5fab3e6577558e40888c5 renamed IM to MR but these man pages were missed. --- man/man9/0intro.9p | 18 +++++++++--------- man/man9/attach.9p | 4 ++-- man/man9/clunk.9p | 2 +- man/man9/flush.9p | 4 ++-- man/man9/open.9p | 4 ++-- man/man9/openfd.9p | 8 ++++---- man/man9/read.9p | 2 +- man/man9/remove.9p | 2 +- man/man9/stat.9p | 4 ++-- man/man9/version.9p | 2 +- man/man9/walk.9p | 4 ++-- 11 files changed, 27 insertions(+), 27 deletions(-) diff --git a/man/man9/0intro.9p b/man/man9/0intro.9p index f432cf51..30e153a1 100644 --- a/man/man9/0intro.9p +++ b/man/man9/0intro.9p @@ -21,7 +21,7 @@ such a machine is called, somewhat confusingly, a Another possibility for a server is to synthesize files on demand, perhaps based on information on data structures maintained in memory; the -.IM plumber (4) +.MR plumber (4) server is an example of such a server. .PP A @@ -63,7 +63,7 @@ bytes of data. Text strings are represented this way, with the text itself stored as a UTF-8 encoded sequence of Unicode characters (see -.IM utf (7) ). +.MR utf (7) ). Text strings in 9P messages are not .SM NUL\c -terminated: @@ -114,7 +114,7 @@ Plan 9 names may contain any printable character (that is, any character outside hexadecimal 00-1F and 80-9F) except slash.) Messages are transported in byte form to allow for machine independence; -.IM fcall (3) +.MR fcall (3) describes routines that convert to and from this form into a machine-dependent C structure. .SH MESSAGES @@ -348,7 +348,7 @@ a ``current file'' on the server. Fids are somewhat like file descriptors in a user process, but they are not restricted to files open for I/O: directories being examined, files being accessed by -.IM stat (3) +.MR stat (3) calls, and so on \(em all files being manipulated by the operating system \(em are identified by fids. Fids are chosen by the client. @@ -461,7 +461,7 @@ to have their input or output attached to fids on 9P servers. See .IR openfd (9p) and -.IM 9pclient (3) +.MR 9pclient (3) for details. .PP The @@ -475,7 +475,7 @@ access permissions (read, write and execute for owner, group and public), access and modification times, and owner and group identifications (see -.IM stat (3) ). +.MR stat (3) ). The owner and group identifications are textual names. The .B wstat @@ -523,12 +523,12 @@ into 9P messages. .SS Unix On Unix, 9P services are posted as Unix domain sockets in a well-known directory (see -.IM getns (3) +.MR getns (3) and -.IM 9pserve (4) ). +.MR 9pserve (4) ). Clients connect to these servers using a 9P client library (see -.IM 9pclient (3) ). +.MR 9pclient (3) ). .SH DIRECTORIES Directories are created by .B create diff --git a/man/man9/attach.9p b/man/man9/attach.9p index 3a5104d5..4160f30d 100644 --- a/man/man9/attach.9p +++ b/man/man9/attach.9p @@ -122,7 +122,7 @@ and and .I fsauth (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) generate .B attach and @@ -163,6 +163,6 @@ transactions. .\" .B mount .\" system call on an uninitialized connection. .SH SEE ALSO -.IM 9pclient (3) , +.MR 9pclient (3) , .IR version (9P), Plan 9's \fIauthsrv\fR(6) diff --git a/man/man9/clunk.9p b/man/man9/clunk.9p index 3277c4b0..f014ac42 100644 --- a/man/man9/clunk.9p +++ b/man/man9/clunk.9p @@ -41,7 +41,7 @@ generated by and .I fsunmount (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) and indirectly by other actions such as failed .I fsopen calls. diff --git a/man/man9/flush.9p b/man/man9/flush.9p index d0987cac..862ab9a4 100644 --- a/man/man9/flush.9p +++ b/man/man9/flush.9p @@ -99,11 +99,11 @@ flushing a and flushing an invalid tag. .SH ENTRY POINTS The -.IM 9pclient (3) +.MR 9pclient (3) library does not generate .B flush transactions.. -.IM 9pserve (4) +.MR 9pserve (4) generates .B flush transactions to cancel transactions pending when a client hangs up. diff --git a/man/man9/open.9p b/man/man9/open.9p index 1f74eb07..8a54f72c 100644 --- a/man/man9/open.9p +++ b/man/man9/open.9p @@ -160,7 +160,7 @@ in this case, the .I fscreate call (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) uses .B open with truncation. @@ -209,7 +209,7 @@ again. and .I fscreate (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) both generate .B open messages; only diff --git a/man/man9/openfd.9p b/man/man9/openfd.9p index 56fb392a..620b1991 100644 --- a/man/man9/openfd.9p +++ b/man/man9/openfd.9p @@ -43,18 +43,18 @@ it cannot be .PP .I Openfd is implemented by -.IM 9pserve (4) . +.MR 9pserve (4) . 9P servers that post their services using -.IM 9pserve (4) +.MR 9pserve (4) (or indirectly via -.IM post9pservice (3) ) +.MR post9pservice (3) ) will never see a .B Topenfd message. .SH ENTRY POINTS .I Fsopenfd (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) generates an .B openfd message. diff --git a/man/man9/read.9p b/man/man9/read.9p index 515f85c3..675bb773 100644 --- a/man/man9/read.9p +++ b/man/man9/read.9p @@ -114,7 +114,7 @@ to be transferred atomically. and .I fswrite (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) generate the corresponding messages. Because they take an offset parameter, the .I fspread diff --git a/man/man9/remove.9p b/man/man9/remove.9p index 79a646a1..232c88f6 100644 --- a/man/man9/remove.9p +++ b/man/man9/remove.9p @@ -45,7 +45,7 @@ so other fids typically remain usable. .SH ENTRY POINTS .I Fsremove (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) generates .B remove messages. diff --git a/man/man9/stat.9p b/man/man9/stat.9p index b92f2d69..7706d3eb 100644 --- a/man/man9/stat.9p +++ b/man/man9/stat.9p @@ -88,7 +88,7 @@ The and .I convD2M routines (see -.IM fcall (3) ) +.MR fcall (3) ) convert between directory entries and a C structure called a .BR Dir . .PP @@ -263,7 +263,7 @@ messages are generated by and .IR fsdirstat (see -.IM 9pclient (3) ). +.MR 9pclient (3) ). .PP .B Wstat messages are generated by diff --git a/man/man9/version.9p b/man/man9/version.9p index 99f30239..c71ee556 100644 --- a/man/man9/version.9p +++ b/man/man9/version.9p @@ -91,7 +91,7 @@ requests is called a .SH ENTRY POINTS .I Fsversion (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) generates .B version messages; diff --git a/man/man9/walk.9p b/man/man9/walk.9p index b48b947b..735b7dcb 100644 --- a/man/man9/walk.9p +++ b/man/man9/walk.9p @@ -149,13 +149,13 @@ may be packed in a single message. This constant is called .B MAXWELEM in -.IM fcall (3) . +.MR fcall (3) . Despite this restriction, the system imposes no limit on the number of elements in a file name, only the number that may be transmitted in a single message. .SH ENTRY POINTS .I Fswalk (see -.IM 9pclient (3) ) +.MR 9pclient (3) ) generates walk messages. One or more walk messages may be generated by any call that evaluates file names: -- cgit v1.2.3 From a72478870ae66b7ac1e73b1d22b578cd31852f33 Mon Sep 17 00:00:00 2001 From: David Arroyo Date: Sun, 31 Jan 2021 00:51:32 -0500 Subject: 9p: parse lines in rdwr command Use bio(3) to read at most one line of input per iteration, even if there is more than one line available in the input buffer. This makes it easier to interact with line-oriented ctl files like that of factotum(4) from shell scripts, without the need to control when and how much data is flushed to a pipe. --- src/cmd/9p.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cmd/9p.c b/src/cmd/9p.c index 75511a19..a5b97f85 100644 --- a/src/cmd/9p.c +++ b/src/cmd/9p.c @@ -302,8 +302,10 @@ void xrdwr(int argc, char **argv) { char buf[4096]; + char *p; int n; CFid *fid; + Biobuf *b; ARGBEGIN{ default: @@ -313,6 +315,8 @@ xrdwr(int argc, char **argv) if(argc != 1) usage(); + if((b = Bfdopen(0, OREAD)) == nil) + sysfatal("out of memory"); fid = xopen(argv[0], ORDWR); for(;;){ fsseek(fid, 0, 0); @@ -322,15 +326,15 @@ xrdwr(int argc, char **argv) if(write(1, buf, n) < 0 || write(1, "\n", 1) < 0) sysfatal("write error: %r"); } - n = read(0, buf, sizeof buf); - if(n <= 0) + if((p = Brdstr(b, '\n', 1)) == nil) break; - if(buf[n-1] == '\n') - n--; - if(fswrite(fid, buf, n) != n) + n = strlen(p); + if(fswrite(fid, p, n) != n) fprint(2, "write: %r\n"); + free(p); } fsclose(fid); + Bterm(b); threadexitsall(0); } -- cgit v1.2.3 From f62d4c4143c9a21e488fca658590e1546700586f Mon Sep 17 00:00:00 2001 From: Connor Taffe Date: Tue, 26 Jan 2021 15:14:18 -0600 Subject: 9pfuse: support MacFUSE >=4 MacFUSE 4 removes support for passing device fd to the mount command. Adds support for the receiving the fd over a socket instead, and updates command paths and filesystem name. --- src/cmd/9pfuse/fuse.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/cmd/9pfuse/fuse.c b/src/cmd/9pfuse/fuse.c index 4c9aac9b..ea8e3bbf 100644 --- a/src/cmd/9pfuse/fuse.c +++ b/src/cmd/9pfuse/fuse.c @@ -798,16 +798,19 @@ mountfuse(char *mtpt) } return fd; #elif defined(__APPLE__) - int i, pid, fd, r; + int i, pid, fd, r, p[2]; char buf[20]; struct vfsconf vfs; char *f, *v; if(getvfsbyname(v="osxfusefs", &vfs) < 0 && + getvfsbyname(v="macfuse", &vfs) < 0 && getvfsbyname(v="osxfuse", &vfs) < 0 && getvfsbyname(v="fusefs", &vfs) < 0){ if(access((v="osxfusefs", f="/Library/Filesystems/osxfusefs.fs" "/Support/load_osxfusefs"), 0) < 0 && + access((v="macfuse", f="/Library/Filesystems/macfuse.fs" + "/Contents/Resources/load_macfuse"), 0) < 0 && access((v="osxfuse", f="/Library/Filesystems/osxfuse.fs" "/Contents/Resources/load_osxfuse"), 0) < 0 && access((v="osxfuse", f="/opt/local/Library/Filesystems/osxfuse.fs" @@ -837,6 +840,32 @@ mountfuse(char *mtpt) } } + /* MacFUSE >=4 dropped support for passing fd */ + if (strcmp(v, "macfuse") == 0) { + if(socketpair(AF_UNIX, SOCK_STREAM, 0, p) < 0) + return -1; + pid = fork(); + if(pid < 0) + return -1; + if(pid == 0){ + close(p[1]); + snprint(buf, sizeof buf, "%d", p[0]); + putenv("_FUSE_COMMFD", buf); + putenv("_FUSE_COMMVERS", "2"); + putenv("_FUSE_CALL_BY_LIB", "1"); + putenv("_FUSE_DAEMON_PATH", + "/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfus"); + execl("/Library/Filesystems/macfuse.fs/Contents/Resources/mount_macfuse", + "mount_macfuse", mtpt, nil); + fprint(2, "exec mount_macfuse: %r\n"); + _exit(1); + } + close(p[0]); + fd = recvfd(p[1]); + close(p[1]); + return fd; + } + /* Look for available FUSE device. */ /* * We need to truncate `fs` from the end of the vfs name if -- cgit v1.2.3 From 90971376a5e8620fc62579aa1b3be26245ec8c06 Mon Sep 17 00:00:00 2001 From: Connor Taffe Date: Sun, 31 Jan 2021 19:33:14 -0600 Subject: mount: find kext with MacFUSE >=4 and macOS >=11 --- bin/mount | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/mount b/bin/mount index 0fbb1bfd..e29cc201 100755 --- a/bin/mount +++ b/bin/mount @@ -20,11 +20,14 @@ case FreeBSD echo 'don''t know how to mount (no fuse)' >[1=2] case Darwin version=`{sw_vers -productVersion|cut -d. -f1,2} + major_version = `{echo $version|cut -d. -f1} if(sysctl fuse.version >[2]/dev/null |9 grep -si 'fuse.version' || sysctl macfuse.version.number >[2]/dev/null |9 grep -si 'fuse.version' || sysctl osxfuse.version.number >[2]/dev/null |9 grep -si 'fuse.version' || test -d /System/Library/Extensions/fusefs.kext || test -d /Library/Filesystems/osxfuse.fs/Contents/Extensions/$version/osxfuse.kext || + test -d /Library/Filesystems/macfuse.fs/Contents/Extensions/$version/macfuse.kext || + test -d /Library/Filesystems/macfuse.fs/Contents/Extensions/$major_version/macfuse.kext || test -d /Library/Filesystems/osxfusefs.fs/Support/osxfusefs.kext || test -d /opt/local/Library/Filesystems/osxfuse.fs || test -d /Library/Filesystems/fusefs.fs/Support/fusefs.kext) -- cgit v1.2.3