aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib9/ctime.c2
-rw-r--r--src/libthread/mkfile4
-rw-r--r--src/libthread/sysofiles.sh14
-rw-r--r--src/libthread/test/tprimes.c1
-rw-r--r--src/libthread/thread.c7
-rw-r--r--src/libthread/threadimpl.h19
-rw-r--r--src/mkhdr1
7 files changed, 29 insertions, 19 deletions
diff --git a/src/lib9/ctime.c b/src/lib9/ctime.c
index c5e11569..a9ce7b7a 100644
--- a/src/lib9/ctime.c
+++ b/src/lib9/ctime.c
@@ -130,7 +130,7 @@ gmtime(long tim)
char*
asctime(Tm *t)
{
- char *ncp;
+ const char *ncp;
static char cbuf[30];
strcpy(cbuf, "Thu Jan 01 00:00:00 GMT 1970\n");
diff --git a/src/libthread/mkfile b/src/libthread/mkfile
index 99f899cc..9c06f331 100644
--- a/src/libthread/mkfile
+++ b/src/libthread/mkfile
@@ -52,6 +52,4 @@ test:V: tprimes tspawn
echo tspawn should take 3 seconds, not 6
$PLAN9/bin/time ./tspawn sleep 3 >/dev/null
-CLEANFILES=p1.txt p2.txt tp1.txt tp2.txt
-
-
+CLEANFILES=p1.txt p2.txt tp1.txt tp2.txt test/*.$O
diff --git a/src/libthread/sysofiles.sh b/src/libthread/sysofiles.sh
index 32600a71..b136bcf9 100644
--- a/src/libthread/sysofiles.sh
+++ b/src/libthread/sysofiles.sh
@@ -4,24 +4,18 @@ test -f $PLAN9/config && . $PLAN9/config
tag="$OBJTYPE-$SYSNAME-${SYSVERSION:-`uname -r`}-${CC9:-cc}"
case "$tag" in
-*-Linux-2.6.*)
- echo pthread.o
- ;;
-*-FreeBSD-[5-9].*)
- echo pthread.o
- ;;
-*-Linux-*)
+*-Linux-2.[0-5]*)
# will have to fix this for linux power pc
echo ${SYSNAME}-${OBJTYPE}-asm.o $SYSNAME.o
;;
-*-FreeBSD-*)
+*-FreeBSD-[0-4].*)
echo ${SYSNAME}-${OBJTYPE}-asm.o $SYSNAME.o
;;
*-NetBSD-*)
echo ${SYSNAME}-${OBJTYPE}-asm.o $SYSNAME.o
;;
-*-Darwin-*)
- echo ${SYSNAME}-${OBJTYPE}-asm.o ${SYSNAME}-${OBJTYPE}.o pthread.o
+*-Darwin-10.[5-6].*)
+ echo ${SYSNAME}-${OBJTYPE}-asm.o $SYSNAME-${OBJTYPE}.o pthread.o
;;
*-OpenBSD-*)
echo ${SYSNAME}-${OBJTYPE}-asm.o ${SYSNAME}-${OBJTYPE}.o $SYSNAME.o
diff --git a/src/libthread/test/tprimes.c b/src/libthread/test/tprimes.c
index 56744984..77626b6d 100644
--- a/src/libthread/test/tprimes.c
+++ b/src/libthread/test/tprimes.c
@@ -80,6 +80,7 @@ threadmain(int argc, char **argv)
mk(countthread, c, STACK);
mk(filterthread, c, STACK);
recvp(chancreate(sizeof(void*), 0));
+ threadexitsall(0);
}
void
diff --git a/src/libthread/thread.c b/src/libthread/thread.c
index 06230f53..731a68cb 100644
--- a/src/libthread/thread.c
+++ b/src/libthread/thread.c
@@ -91,7 +91,7 @@ threadstart(uint y, uint x)
z |= y;
t = (_Thread*)z;
-/*print("threadstart %p\n", v); */
+//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);
@@ -114,17 +114,21 @@ threadalloc(void (*fn)(void*), void *arg, uint stack)
t->stk = (uchar*)(t+1);
t->stksize = stack;
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 */
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. */
/* leave a few words open on both ends */
@@ -141,6 +145,7 @@ threadalloc(void (*fn)(void*), void *arg, uint stack)
* 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 */
diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h
index 8b931ae7..0352d755 100644
--- a/src/libthread/threadimpl.h
+++ b/src/libthread/threadimpl.h
@@ -24,7 +24,7 @@ extern int swapcontext(ucontext_t*, ucontext_t*);
extern void makecontext(ucontext_t*, void(*)(), int, ...);
#endif
-#if defined(__APPLE__)
+#if defined(__APPLE__) && !defined(__x86_64__)
/*
* OS X before 10.5 (Leopard) does not provide
* swapcontext nor makecontext, so we have to use our own.
@@ -40,8 +40,10 @@ extern void makecontext(ucontext_t*, void(*)(), int, ...);
# define makecontext libthread_makecontext
# if defined(__i386__)
# include "386-ucontext.h"
-# else
+# elif defined(__power__)
# include "power-ucontext.h"
+# else
+# error "unknown architecture"
# endif
#endif
@@ -99,6 +101,15 @@ enum
struct Context
{
ucontext_t uc;
+#ifdef __APPLE__
+ /*
+ * On Snow Leopard, etc., the context routines exist,
+ * so we use them, but apparently they write past the
+ * end of the ucontext_t. Sigh. We put some extra
+ * scratch space here for them.
+ */
+ uchar buf[512];
+#endif
};
struct Execjob
@@ -116,12 +127,12 @@ struct _Thread
_Thread *allnext;
_Thread *allprev;
Context context;
+ void (*startfn)(void*);
+ void *startarg;
uint id;
uchar *stk;
uint stksize;
int exiting;
- void (*startfn)(void*);
- void *startarg;
Proc *proc;
char name[256];
char state[256];
diff --git a/src/mkhdr b/src/mkhdr
index 076f4e6b..c7e9ddde 100644
--- a/src/mkhdr
+++ b/src/mkhdr
@@ -38,5 +38,6 @@ YFLAGS=-d
LIB=
SHORTLIB=9
+<|cat $PLAN9/config 2>/dev/null || true
<|cat $PLAN9/src/mk.$SYSNAME-$OBJTYPE 2>/dev/null || true