Commit Diff


commit - 040d1d02f5b829f59e63123d7095aea7d04e372b
commit + 05d8c6df6c626f9e80e7d0ffe241c061bda36324
blob - 0c359c9e072aa471bbd08145df523387666ce190 (mode 644)
blob + /dev/null
--- src/lib9/9proc.h
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef _9PROC_H_
-#define _9PROC_H_ 1
-
-enum
-{
-	NPRIV = 16,
-	RENDHASH = 33,
-};
-
-typedef struct Uproc Uproc;
-struct Uproc
-{
-	int pid;
-	int state;
-	void *priv[NPRIV];
-	p9jmp_buf notejb;
-};
-
-extern Uproc *_p9uproc(int);
-extern void _p9uprocdie(void);
-extern void _clearuproc(void);
-
-#endif
blob - 9affe94879a7e4d575ddc1f3ec4092377bd1e739
blob + 5e7c88ed2b1e4e79f6222d1440b8fa08e97b24de
--- src/lib9/_exits.c
+++ src/lib9/_exits.c
@@ -1,12 +1,9 @@
 #include <u.h>
 #include <libc.h>
-#include "9proc.h"
 
 void
 _exits(char *s)
 {
-	_p9uprocdie();
-
 	if(s && *s)
 		_exit(1);
 	_exit(0);
blob - 689261f6378678b2321552254bc74102b2966344
blob + eb3ea21dd6e8214611860a9216008d31df637364
--- src/lib9/lock-pthread.c
+++ src/lib9/lock-pthread.c
@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include <sys/time.h>
 #include <sched.h>
+#include <errno.h>
 #include <libc.h>
 
 static pthread_mutex_t initmutex = PTHREAD_MUTEX_INITIALIZER;
blob - 5b2635b419cb1062f721a58012f2d57f22d40bbd
blob + 4a42905446379952cf1fb10f4db507a095a2aafb
--- src/lib9/main.c
+++ src/lib9/main.c
@@ -1,14 +1,12 @@
 #include <u.h>
 #define NOPLAN9DEFINES
 #include <libc.h>
-#include "9proc.h"
 
 extern void p9main(int, char**);
 
 int
 main(int argc, char **argv)
 {
-	_p9uproc(0);
 	p9main(argc, argv);
 	exits("main");
 	return 99;
blob - 9200d81cc76f80774cf6ec110c5fb2dd130da688
blob + 133fcf41f0b1f346972afce08fd4b459ab0c7c5a
--- src/lib9/mkfile
+++ src/lib9/mkfile
@@ -67,7 +67,6 @@ LIB9OFILES=\
 	_exits.$O\
 	_p9dialparse.$O\
 	_p9dir.$O\
-	_p9proc-$SYSNAME.$O\
 	announce.$O\
 	argv0.$O\
 	atexit.$O\
@@ -99,8 +98,6 @@ LIB9OFILES=\
 	errstr.$O\
 	exec.$O\
 	fcallfmt.$O\
-	fork.$O\
-	ffork-$SYSNAME.$O\
 	get9root.$O\
 	getcallerpc-$OBJTYPE.$O\
 	getenv.$O\
blob - 9156f8912211a1859edce58fb9f64e3493310771
blob + 7f22e0fa7b452a4da414c9b31f3b2bec8486899b
--- src/lib9/notify.c
+++ src/lib9/notify.c
@@ -2,7 +2,6 @@
 #include <signal.h>
 #define NOPLAN9DEFINES
 #include <libc.h>
-#include "9proc.h"
 
 extern char *_p9sigstr(int, char*);
 
@@ -41,6 +40,21 @@ static struct {
 #endif
 };
 
+typedef struct Jmp Jmp;
+struct Jmp
+{
+	p9jmp_buf b;
+};
+
+static Jmp onejmp;
+
+static Jmp*
+getonejmp(void)
+{
+	return &onejmp;
+}
+
+Jmp *(*_notejmpbuf)(void) = getonejmp;
 static void (*notifyf)(void*, char*);
 
 static void
@@ -48,28 +62,35 @@ notifysigf(int sig)
 {
 	int v;
 	char tmp[64];
-	Uproc *up;
+	Jmp *j;
 
-	up = _p9uproc(1);
-	v = p9setjmp(up->notejb);
+	j = (*_notejmpbuf)();
+	v = p9setjmp(j->b);
 	if(v == 0 && notifyf)
 		(*notifyf)(nil, _p9sigstr(sig, tmp));
 	else if(v == 2){
-if(0)print("HANDLED %d\n", sig);
+		if(0)print("HANDLED %d\n", sig);
 		return;
 	}
-if(0)print("DEFAULT %d\n", sig);
+	if(0)print("DEFAULT %d\n", sig);
 	signal(sig, SIG_DFL);
-	kill(getpid(), sig);
+	raise(sig);
 }
-	
+
 int
+noted(int v)
+{
+	p9longjmp((*_notejmpbuf)()->b, v==NCONT ? 2 : 1);
+	abort();
+	return 0;
+}
+
+int
 notify(void (*f)(void*, char*))
 {
 	int i;
 	struct sigaction sa, osa;
 
-	_p9uproc(0);
 	memset(&sa, 0, sizeof sa);
 	if(f == 0)
 		sa.sa_handler = SIG_DFL;
@@ -87,8 +108,12 @@ notify(void (*f)(void*, char*))
 		sigaction(sigs[i].sig, nil, &osa);
 		if(osa.sa_handler != SIG_DFL)
 			continue;
-		sigemptyset(&sa.sa_mask);
-		sigaddset(&sa.sa_mask, i);
+		/*
+		 * We assume that one jump buffer per thread
+		 * is okay, which means that we can't deal with 
+		 * signal handlers called during signal handlers.
+		 */
+		sigfillset(&sa.sa_mask);
 		if(sigs[i].restart)
 			sa.sa_flags |= SA_RESTART;
 		else
@@ -97,14 +122,3 @@ notify(void (*f)(void*, char*))
 	}
 	return 0;
 }
-
-int
-noted(int v)
-{
-	Uproc *up;
-
-	up = _p9uproc(1);
-	p9longjmp(up->notejb, v==NCONT ? 2 : 1);
-	abort();
-	return 0;
-}
blob - 35ba3167a469e98c023c74fafb4d99380fe00a7c
blob + ddedf62e776601edc9ef08d04f3cb2cfe89d8640
--- src/lib9/post9p.c
+++ src/lib9/post9p.c
@@ -14,7 +14,7 @@ post9pservice(int fd, char *name)
 	free(ns);
 	if(s == nil)
 		return -1;
-	switch(rfork(RFPROC|RFFDG)){
+	switch(fork()){
 	case -1:
 		return -1;
 	case 0:
blob - 7d5e21ebf337de43ead276bd3138130ba06469aa (mode 644)
blob + /dev/null
--- src/lib9/rendez-futex.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
-     NAME
-          rendezvous - user level process synchronization
-
-     SYNOPSIS
-          ulong rendezvous(ulong tag, ulong value)
-
-     DESCRIPTION
-          The rendezvous system call allows two processes to synchro-
-          nize and exchange a value.  In conjunction with the shared
-          memory system calls (see segattach(2) and fork(2)), it
-          enables parallel programs to control their scheduling.
-
-          Two processes wishing to synchronize call rendezvous with a
-          common tag, typically an address in memory they share.  One
-          process will arrive at the rendezvous first; it suspends
-          execution until a second arrives.  When a second process
-          meets the rendezvous the value arguments are exchanged
-          between the processes and returned as the result of the
-          respective rendezvous system calls.  Both processes are
-          awakened when the rendezvous succeeds.
-
-          The set of tag values which two processes may use to
-          rendezvous-their tag space-is inherited when a process
-          forks, unless RFREND is set in the argument to rfork; see
-          fork(2).
-
-          If a rendezvous is interrupted the return value is ~0, so
-          that value should not be used in normal communication.
-
- * This simulates rendezvous with shared memory, pause, and SIGUSR1.
- */
-
-#include <u.h>
-typedef u32int u32;
-#include <errno.h>
-#include <sys/time.h>
-#define __user
-#include <linux/linkage.h>
-#include <linux/futex.h>
-#include <libc.h>
-
-enum
-{
-	VOUSHASH = 257,
-};
-
-typedef struct Vous Vous;
-struct Vous
-{
-	Vous *link;
-	Lock lk;
-	int pid;
-	ulong val;
-	ulong tag;
-};
-
-static Vous vouspool[2048];
-static int nvousused;
-static Vous *vousfree;
-static Vous *voushash[VOUSHASH];
-static Lock vouslock;
-
-static Vous*
-getvous(void)
-{
-	Vous *v;
-
-	if(vousfree){
-		v = vousfree;
-		vousfree = v->link;
-	}else if(nvousused < nelem(vouspool))
-		v = &vouspool[nvousused++];
-	else
-		abort();
-	return v;
-}
-
-static void
-putvous(Vous *v)
-{
-	lock(&vouslock);
-	v->link = vousfree;
-	vousfree = v;
-	unlock(&vouslock);
-}
-
-static Vous*
-findvous(ulong tag, ulong val, int pid)
-{
-	int h;
-	Vous *v, **l;
-
-	lock(&vouslock);
-	h = tag%VOUSHASH;
-	for(l=&voushash[h], v=*l; v; l=&(*l)->link, v=*l){
-		if(v->tag == tag){
-			*l = v->link;
-			unlock(&vouslock);
-			return v;
-		}
-	}
-	v = getvous();
-	v->pid = pid;
-	v->link = voushash[h];
-	v->val = val;
-	v->tag = tag;
-	lock(&v->lk);
-	voushash[h] = v;
-	unlock(&vouslock);
-	return v;
-}
-
-#define DBG 0
-ulong
-rendezvous(ulong tag, ulong val)
-{
-	int me, vpid;
-	ulong rval;
-	Vous *v;
-
-	me = getpid();
-	v = findvous(tag, val, me);
-	if(v->pid == me){
-		if(DBG)fprint(2, "pid is %d tag %lux, sleeping\n", me, tag);
-		/*
-		 * No rendezvous partner was found; the next guy
-		 * through will find v and wake us, so we must go
-		 * to sleep.
-		 *
-		 * To go to sleep:
-		 *	1. disable USR1 signals.
-		 *	2. unlock v->lk (tells waker okay to signal us).
-		 *	3. atomically suspend and enable USR1 signals.
-		 *
-		 * The call to ignusr1() could be done once at 
-		 * process creation instead of every time through rendezvous.
-		 */
-		v->val = val;
-		unlock(&v->lk);
-		while(sys_futex((u32int*)&v->tag, FUTEX_WAIT, tag, nil, nil) < 0 && errno==EINTR)
-			;
-		rval = v->val;
-		if(DBG)fprint(2, "pid is %d, awake\n", me);
-		putvous(v);
-	}else{
-		/*
-		 * Found someone to meet.  Wake him:
-		 *
-		 *	A. lock v->lk (waits for him to get to his step 2)
-		 *	B. send a USR1
-		 *
-		 * He won't get the USR1 until he suspends, which
-		 * means it must wake him up (it can't get delivered
-		 * before he sleeps).
-		 */
-		vpid = v->pid;
-		lock(&v->lk);
-		rval = v->val;
-		v->val = val;
-		v->tag++;
-		unlock(&v->lk);
-		sys_futex((u32int*)&v->tag, FUTEX_WAKE, 1, nil, nil);
-	}
-	return rval;
-}
-
blob - d3c8f8b29895cb612fdef059f9c6b123d3eeefb3
blob + aec051a9d20ae00c9cc3335eef644d23bfbdc106
--- src/lib9/rfork.c
+++ src/lib9/rfork.c
@@ -2,7 +2,6 @@
 #include <sys/wait.h>
 #include <signal.h>
 #include <libc.h>
-#include "9proc.h"
 #undef rfork
 
 int
@@ -13,7 +12,6 @@ p9rfork(int flags)
 	int n;
 	char buf[128], *q;
 
-	_p9uproc(0);
 	if((flags&(RFPROC|RFFDG|RFMEM)) == (RFPROC|RFFDG)){
 		/* check other flags before we commit */
 		flags &= ~(RFPROC|RFFDG);
@@ -73,7 +71,6 @@ p9rfork(int flags)
 				}
 			}
 		}
-		_p9uproc(0);
 		if(pid != 0)
 			return pid;
 	}