diff options
Diffstat (limited to 'src')
105 files changed, 412 insertions, 3537 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); } 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 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/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[]) { 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 <util.h> + +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; +} 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/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)) 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/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); } 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/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 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/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[]) { 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 */ { 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/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; 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/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 <limits.h> +#include <errno.h> #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; 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 <unistd.h> -#include <stdlib.h> -#include <stdarg.h> -#include <setjmp.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <stdio.h> - -#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/cmd.c b/src/cmd/sam/cmd.c index 386fe8d4..13bd17e0 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; @@ -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/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/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/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; -} 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; i<r->nused && 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); } 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/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[]; 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"); 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); 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/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]; 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"); 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/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; } 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/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 <machine/ucontext.h> */ - -/*- - * 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 <jakub@redhat.com>. - - 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 <sysdep.h> -#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/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; i<npid; i++) - kill(pid[i], SIGUSR2); - unlock(&_threadprocslock); - exits(msg); -} - -/* - * per-process data, indexed by pid - * - * could use modify_ldt and a segment register - * to avoid the many calls to getpid(), but i don't - * care -- this is compatibility code. linux 2.6 with - * nptl is a good enough pthreads to avoid this whole file. - */ -typedef struct Perproc Perproc; -struct Perproc -{ - int pid; - Proc *proc; -}; - -static Lock perlock; -static Perproc perproc[1024]; -#define P ((Proc*)-1) - -static Perproc* -myperproc(void) -{ - int i, pid, h; - Perproc *p; - - pid = getpid(); - h = pid%nelem(perproc); - for(i=0; i<nelem(perproc); i++){ - p = &perproc[(i+h)%nelem(perproc)]; - if(p->pid == 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; i<nelem(perproc); i++){ - p = &perproc[(i+h)%nelem(perproc)]; - if(p->pid == 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/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 && i<argc; i++) - (&uc->uc_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/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..29929068 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 @@ -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"); @@ -163,9 +170,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..40941f43 100644 --- a/src/libthread/mkfile +++ b/src/libthread/mkfile @@ -1,14 +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 <jakub@redhat.com>. - - 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 <ucontext.h> - -#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 <u.h> -#include <sys/mman.h> -#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 833afbe0..00000000 --- a/src/libthread/sysofiles.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -test -f $PLAN9/config && . $PLAN9/config - -case "$SYSNAME" in -NetBSD) - echo ${SYSNAME}-${OBJTYPE}-asm.o $SYSNAME.o stkmalloc.o - ;; -OpenBSD) - echo pthread.o stkmmap.o - ;; -*) - echo pthread.o 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 65e65194..79e0ec71 100644 --- a/src/libthread/thread.c +++ b/src/libthread/thread.c @@ -1,13 +1,12 @@ #include "threadimpl.h" -int _threaddebuglevel; +int _threaddebuglevel = 0; static uint threadnproc; static uint threadnsysproc; static Lock threadnproclock; static Ref threadidref; static Proc *threadmainproc; -static int pthreadperthread; static void addproc(Proc*); static void delproc(Proc*); @@ -16,17 +15,18 @@ 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); +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 +52,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 @@ -82,109 +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(p->nthread == 0) - p->thread0 = t; - else if(pthreadperthread) + if(p->nthread != 0) _threadpthreadstart(p, t); + else + t->mainthread = 1; p->nthread++; addthreadinproc(p, t); _threadready(t); @@ -197,6 +113,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 +127,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) { @@ -252,15 +139,8 @@ _threadswitch(void) needstack(0); p = proc(); - /*print("threadswtch %p\n", p); */ - - if(p->thread == p->thread0) - procscheduler(p); - else if(pthreadperthread) - procswitch(p, p->thread, p->thread0); - else - contextswitch(&p->thread->context, &p->schedcontext); + pthreadscheduler(p); } void @@ -359,15 +239,6 @@ threadsysfatal(char *fmt, va_list arg) } 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) { _Thread *t; @@ -377,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; @@ -390,118 +260,133 @@ 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); } static void -procscheduler(Proc *p) +pthreadsleepschedlocked(Proc *p, _Thread *t) { - _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->lock; + p->schedthread = t; + _procwakeup(&t->schedrend); +} + +static void +pthreadscheduler(Proc *p) +{ + _Thread *self, *t; - _threaddebug("scheduler enter"); -//print("s %p\n", p); -Top: + _threaddebug(nil, "scheduler"); lock(&p->lock); - t = p->thread; + self = p->thread; p->thread = nil; - if(t->exiting){ - delthreadinproc(p, t); + _threaddebug(self, "pausing"); + + if(self->exiting) { + _threaddebug(self, "exiting"); + delthreadinproc(p, self); 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"); - } - 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); - 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); - if(t == p->thread0) + 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(pthreadperthread) - procswitch(p, p->thread0, t); - else - contextswitch(&p->schedcontext, &t->context); - _threaddebug("back in scheduler"); -/*print("back in scheduler\n"); */ - goto Top; + } } -Out: - _threaddebug("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(); + if(t == nil) { + /* Tear down proc bookkeeping. Wait to free p. */ + delproc(p); lock(&threadnproclock); - if(++threadnsysproc == threadnproc) + if(p->sysproc) + --threadnsysproc; + if(--threadnproc == threadnsysproc) 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); + /* 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(p->thread0); - free(p); + 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 +669,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 +716,7 @@ int main(int argc, char **argv) { Proc *p; + _Thread *t; char *opts; argv0 = argv[0]; @@ -835,16 +725,7 @@ 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(strstr(opts, "nodaemon") == nil && getenv("NOLIBTHREADDAEMONIZE") == nil) + if(threadmaybackground() && strstr(opts, "nodaemon") == nil && getenv("NOLIBTHREADDAEMONIZE") == nil) _threadsetupdaemonize(); threadargc = argc; @@ -875,9 +756,10 @@ 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!"); + sysfatal("procmain returned in libthread"); /* does not return */ return 0; } diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h index 8d22a161..fd40f252 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 <ucontext.h> #endif #include <sys/utsname.h> #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,18 +51,14 @@ 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; + int mainthread; Proc *proc; char name[256]; char state[256]; @@ -114,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; @@ -130,9 +88,7 @@ struct Proc uint nthread; uint sysproc; _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*); @@ -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` @@ -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: @@ -9,7 +9,7 @@ OS=$O CC=9c #CC=9r LD=9l -AS=9a +AS=no-9a AR=9ar CFLAGS= LDFLAGS= |