tMore tweaks on Linux and Solaris. - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 64bcfff3a12695f4e3f54b0590e896611da71c3b
parent f7012583e9a7594cbb5ebe8e974bb69061189262
Author: rsc 
Date:   Tue, 25 Nov 2003 02:11:11 +0000

More tweaks on Linux and Solaris.

Diffstat:
  M bin/9c                              |       3 +--
  M bin/9l                              |       2 +-
  M include/lib9.h                      |      26 ++++++--------------------
  M src/cmd/samterm/plan9.c             |       2 +-
  M src/lib9/_p9dir.c                   |      12 +++++++++---
  M src/lib9/date.c                     |      36 +++++++++++++++++++------------
  M src/lib9/dirfwstat.c                |      17 +++++++++++++----
  M src/lib9/dirread.c                  |      26 +++++++++++++++++++++++---
  M src/lib9/dirwstat.c                 |       1 -
  M src/libhttpd/fail.c                 |      36 ++++++++++++++++----------------
  M src/libsec/port/aes.c               |       2 +-
  M src/libthread/sched.c               |       2 +-
  M src/libthread/sun4u.c               |      20 ++++++++++++++++++--
  M src/mkfile                          |       2 +-

14 files changed, 115 insertions(+), 72 deletions(-)
---
diff --git a/bin/9c b/bin/9c
t@@ -5,7 +5,6 @@ usegcc()
         cc=gcc
         cflags=" \
                 -O2 \
-                -I$PLAN9/include \
                 -c \
                 -ggdb \
                 -Wall \
t@@ -29,4 +28,4 @@ case "$tag" in
         exit 1
 esac
 
-exec $cc $cflags "$@"
+exec $cc -I$PLAN9/include $cflags "$@"
diff --git a/bin/9l b/bin/9l
t@@ -7,7 +7,7 @@ case "$tag" in
 *BSD*)                ld=gcc ;;
 *Linux*)        ld=gcc ;;
 *Darwin*)        ld=gcc ;;
-*SunOS*)        ld=${CC9:-cc}
+*SunOS*)        ld="${CC9:-cc} -g"
                 extralibs="$extralibs -lrt -lpthread -lsocket -lnsl"
                 ;;
 *)
diff --git a/include/lib9.h b/include/lib9.h
t@@ -15,6 +15,7 @@ extern "C" {
 #define _XOPEN_SOURCE_EXTENDED 1
 #define _LARGEFILE64_SOURCE 1
 #define _FILE_OFFSET_BITS 64
+#define __EXTENSIONS__ 1 /* SunOS */
 
 #include 
 #include 
t@@ -36,14 +37,6 @@ extern "C" {
 #define _NEEDUINT 1
 #define _NEEDULONG 1
 
-/* better to assume we have these and then be proved wrong */
-#define _HAVESTGEN 1
-#define _HAVETIMEGM 1
-#define _HAVETMZONE 1
-#define _HAVETMTZOFF 1
-#define _HAVEFUTIMESAT 1
-#define _HAVEFUTIMES 1
-
 typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
 
 #if defined(__linux__)
t@@ -53,22 +46,12 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
 #                undef _NEEDUINT
 #                undef _NEEDULONG
 #        endif
-#        undef _HAVESTGEN
-#        undef _HAVETMZONE
-#        undef _HAVETMTZOFF
-#        undef _HAVEFUTIMESAT
 #endif
 #if defined(__sun__)
 #        include 
 #        undef _NEEDUSHORT
 #        undef _NEEDUINT
 #        undef _NEEDULONG
-#        undef _HAVESTGEN
-#        undef _HAVETIMEGM
-#        undef _HAVETMZONE
-#        undef _HAVETMTZOFF
-#        undef _HAVEFUTIMES
-#        undef _HAVEUTIMES
 #endif
 #if defined(__FreeBSD__)
 #        include 
t@@ -76,14 +59,12 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
 #                undef _NEEDUSHORT
 #                undef _NEEDUINT
 #        endif
-#        define _HAVEDISKLABEL 1
 #endif
 #if defined(__APPLE__)
 #        include 
 #        undef _NEEDUSHORT
 #        undef _NEEDUINT
 #        define _NEEDLL 1
-#        define _GETDIRENTRIES_TAKES_LONG 1
 #endif
 
 typedef signed char schar;
t@@ -106,6 +87,11 @@ typedef uvlong u64int;
 typedef uchar u8int;
 typedef ushort u16int;
 
+#undef _NEEDUCHAR
+#undef _NEEDUSHORT
+#undef _NEEDUINT
+#undef _NEEDULONG
+
 /*
  * Begin usual libc.h 
  */
diff --git a/src/cmd/samterm/plan9.c b/src/cmd/samterm/plan9.c
t@@ -15,7 +15,7 @@
 
 static char *exname;
 
-#define STACK 8192
+#define STACK 16384
 
 void
 getscreen(int argc, char **argv)
diff --git a/src/lib9/_p9dir.c b/src/lib9/_p9dir.c
t@@ -4,13 +4,19 @@
 
 #include 
 #include 
-#ifdef _HAVEDISKLABEL
-#include 
-#endif
 #include 
 #include 
 #include 
 
+#if defined(__FreeBSD__)
+#include 
+#define _HAVEDISKLABEL
+#endif
+
+#if !defined(__linux__) && !defined(__sun__)
+#define _HAVESTGEN
+#endif
+
 int
 _p9dir(struct stat *st, char *name, Dir *d, char **str, char *estr)
 {
diff --git a/src/lib9/date.c b/src/lib9/date.c
t@@ -1,18 +1,24 @@
 #include  /* setenv etc. */
 
 #include 
+#define NOPLAN9DEFINES
 #include 
+#include 
 
-#undef gmtime
-#undef localtime
-#undef asctime
-#undef ctime
-#undef cputime
-#undef times
-#undef tm2sec
-#undef nsec
+#define _HAVETIMEGM 1
+#define _HAVETMZONE 1
+#define _HAVETMTZOFF 1
 
-#include 
+#if defined(__linux__)
+#        undef _HAVETMZONE
+#        undef _HAVETMTZOFF
+
+#elif defined(__sun__)
+#        undef _HAVETIMEGM
+#        undef _HAVETMZONE
+#        undef _HAVETMTZOFF
+
+#endif
 
 static Tm bigtm;
 
t@@ -80,15 +86,17 @@ timegm(struct tm *tm)
 {
         time_t ret;
         char *tz;
+        char *s;
 
         tz = getenv("TZ");
-        setenv("TZ", "", 1);
+        putenv("TZ=");
         tzset();
         ret = mktime(tm);
-        if(tz)
-                setenv("TZ", tz, 1);
-        else
-                unsetenv("TZ");
+        if(tz){
+                s = smprint("TZ=%s", tz);
+                if(s)
+                        putenv(s);
+        }
         return ret;
 }
 #endif
diff --git a/src/lib9/dirfwstat.c b/src/lib9/dirfwstat.c
t@@ -1,22 +1,30 @@
 #include 
-#define NOPLAN9DEFINES
 #include 
-
 #include 
 
-#if !defined(_HAVEFUTIMES) && defined(_HAVEFUTIMESAT)
+#if defined(__FreeBSD__) || defined(__APPLE__)
+/* do nothing -- futimes exists and is fine */
+
+#elif defined(__sun__)
+/* use futimesat */
 static int
 futimes(int fd, struct timeval *tv)
 {
         return futimesat(fd, 0, tv);
 }
-#elif !defined(_HAVEFUTIMES)
+
+#else
+/* provide dummy */
+/* rename just in case -- linux provides an unusable one */
+#undef futimes
+#define futimes myfutimes
 static int
 futimes(int fd, struct timeval *tv)
 {
         werrstr("futimes not available");
         return -1;
 }
+
 #endif
 
 int
t@@ -25,6 +33,7 @@ dirfwstat(int fd, Dir *dir)
         int ret;
         struct timeval tv[2];
 
+        ret = 0;
         if(~dir->mode != 0){
                 if(fchmod(fd, dir->mode) < 0)
                         ret = -1;
diff --git a/src/lib9/dirread.c b/src/lib9/dirread.c
t@@ -6,19 +6,39 @@
 
 extern int _p9dir(struct stat*, char*, Dir*, char**, char*);
 
-/* almost everyone has getdirentries, just use that */
+#if defined(__linux__)
 static int
-mygetdents(int fd, char *buf, int n)
+mygetdents(int fd, struct dirent *buf, int n)
+{
+        ssize_t nn;
+        off_t off;
+
+        off = p9seek(fd, 0, 1);
+        nn = getdirentries(fd, (void*)buf, n, &off);
+        if(nn > 0)
+                p9seek(fd, off, 0);
+        return nn;
+}
+#elif defined(__APPLE__) || defined(__FreeBSD__)
+static int
+mygetdents(int fd, struct dirent *buf, int n)
 {
         ssize_t nn;
         long off;
 
         off = p9seek(fd, 0, 1);
-        nn = getdirentries(fd, buf, n, &off);
+        nn = getdirentries(fd, (void*)buf, n, &off);
         if(nn > 0)
                 p9seek(fd, off, 0);
         return nn;
 }
+#elif defined(__sun__)
+static int
+mygetdents(int fd, struct dirent *buf, int n)
+{
+        return getdents(fd, (void*)buf, n);
+}
+#endif        
 
 static int
 countde(char *p, int n)
diff --git a/src/lib9/dirwstat.c b/src/lib9/dirwstat.c
t@@ -1,7 +1,6 @@
 #include 
 #define NOPLAN9DEFINES
 #include 
-
 #include 
 #include 
 
diff --git a/src/libhttpd/fail.c b/src/libhttpd/fail.c
t@@ -14,33 +14,33 @@ struct Error
 
 Error errormsg[] =
 {
-        [HInternal]        {"500 Internal Error", "Internal Error",
+        /* HInternal */        {"500 Internal Error", "Internal Error",
                 "This server could not process your request due to an internal error."},
-        [HTempFail]        {"500 Internal Error", "Temporary Failure",
+        /* HTempFail */        {"500 Internal Error", "Temporary Failure",
                 "The object %s is currently inaccessible.

Please try again later."}, - [HUnimp] {"501 Not implemented", "Command not implemented", + /* HUnimp */ {"501 Not implemented", "Command not implemented", "This server does not implement the %s command."}, - [HUnkVers] {"501 Not Implemented", "Unknown http version", - "This server does not know how to respond to http version %s."}, - [HBadCont] {"501 Not Implemented", "Impossible format", - "This server cannot produce %s in any of the formats your client accepts."}, - [HBadReq] {"400 Bad Request", "Strange Request", + /* HBadReq */ {"400 Bad Request", "Strange Request", "Your client sent a query that this server could not understand."}, - [HSyntax] {"400 Bad Request", "Garbled Syntax", - "Your client sent a query with incoherent syntax."}, - [HBadSearch] {"400 Bad Request", "Inapplicable Search", + /* HBadSearch */ {"400 Bad Request", "Inapplicable Search", "Your client sent a search that cannot be applied to %s."}, - [HNotFound] {"404 Not Found", "Object not found", + /* HNotFound */ {"404 Not Found", "Object not found", "The object %s does not exist on this server."}, - [HNoSearch] {"403 Forbidden", "Search not supported", + /* HUnauth */ {"403 Forbidden", "Forbidden", + "You are not allowed to see the object %s."}, + /* HSyntax */ {"400 Bad Request", "Garbled Syntax", + "Your client sent a query with incoherent syntax."}, + /* HNoSearch */ {"403 Forbidden", "Search not supported", "The object %s does not support the search command."}, - [HNoData] {"403 Forbidden", "No data supplied", + /* HNoData */ {"403 Forbidden", "No data supplied", "Search or forms data must be supplied to %s."}, - [HExpectFail] {"403 Expectation Failed", "Expectation Failed", + /* HExpectFail */ {"403 Expectation Failed", "Expectation Failed", "This server does not support some of your request's expectations."}, - [HUnauth] {"403 Forbidden", "Forbidden", - "You are not allowed to see the object %s."}, - [HOK] {"200 OK", "everything is fine"}, + /* HUnkVers */ {"501 Not Implemented", "Unknown http version", + "This server does not know how to respond to http version %s."}, + /* HBadCont */ {"501 Not Implemented", "Impossible format", + "This server cannot produce %s in any of the formats your client accepts."}, + /* HOK */ {"200 OK", "everything is fine"}, }; /*

diff --git a/src/libsec/port/aes.c b/src/libsec/port/aes.c
t@@ -43,7 +43,7 @@ static const u32 Td3[256];
 static const u8  Te4[256];
 
 static int rijndaelKeySetupEnc(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits);
-static int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits);
+// static int rijndaelKeySetupDec(u32 rk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits);
 static int rijndaelKeySetup(u32 erk[/*4*(Nr + 1)*/], u32 drk[/*4*(Nr + 1)*/], const u8 cipherKey[], int keyBits);
 static void        rijndaelEncrypt(const u32int rk[], int Nr, const uchar pt[16], uchar ct[16]);
 static void        rijndaelDecrypt(const u32int rk[], int Nr, const uchar ct[16], uchar pt[16]);
diff --git a/src/libthread/sched.c b/src/libthread/sched.c
t@@ -10,7 +10,6 @@ static char *_psstate[] = {
         "Ready",
         "Rendezvous",
 };
-#endif
 
 static char*
 psstate(int s)
t@@ -19,6 +18,7 @@ psstate(int s)
                 return "unknown";
         return _psstate[s];
 }
+#endif
 
 void
 _schedinit(void *arg)
diff --git a/src/libthread/sun4u.c b/src/libthread/sun4u.c
t@@ -1,9 +1,12 @@
 #include "threadimpl.h"
 
 static void
-launchersparc(int o0, int o1, int o2, int o3, int o4,
+launchersparc(uint o0, uint o1, uint o2, uint o3,
+        uint o4, uint o5, uint o6, uint o7,
         void (*f)(void *arg), void *arg)
 {
+        if(0) print("ls %x %x %x %x %x %x %x %x %x %x at %x\n",
+                o0, o1, o2, o3, o4, o5, o6, o7, f, arg, &o0);
         (*f)(arg);
         threadexits(nil);
 }
t@@ -13,13 +16,26 @@ _threadinitstack(Thread *t, void (*f)(void*), void *arg)
 {
         ulong *tos, *stk;
 
+        /*
+         * This is a bit more complicated than it should be,
+         * because we need to set things up so that gotolabel
+         * (which executes a return) gets us into launchersparc.
+         * So all the registers are going to be renamed before
+         * we get there.  The input registers here become the
+         * output registers there, which is useless.  
+         * The input registers there are inaccessible, so we
+         * have to give launchersparc enough arguments that
+         * everything ends up in the stack.
+         */
         tos = (ulong*)&t->stk[t->stksize&~7];
         stk = tos;
         --stk;
         *--stk = (ulong)arg;
         *--stk = (ulong)f;
+        stk -= 25;        /* would love to understand this */
         t->sched.link = (ulong)launchersparc - 8;
         t->sched.input[6] = 0;
-        t->sched.sp = (ulong)stk - 0x5c;
+        t->sched.sp = (ulong)stk;
+        if(0) print("tis %x %x at %x\n", f, arg, t->sched.sp);
 }
 
diff --git a/src/mkfile b/src/mkfile
t@@ -7,7 +7,7 @@ DIRS=\
         libfmt\
         libframe\
         libhttpd\
-        libip\
+#        libip\
         libregexp\
         libsec\
         libthread\