summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/afs/src/lwp/fasttime.c27
-rw-r--r--usr.sbin/afs/src/lwp/iomgr.c34
-rw-r--r--usr.sbin/afs/src/lwp/lock.c26
-rw-r--r--usr.sbin/afs/src/lwp/lock.h22
-rw-r--r--usr.sbin/afs/src/lwp/lwp_asm.c358
-rw-r--r--usr.sbin/afs/src/lwp/lwp_asm.h8
-rw-r--r--usr.sbin/afs/src/lwp/lwp_elf.h2
-rw-r--r--usr.sbin/afs/src/lwp/make-process.o.sh.in23
-rw-r--r--usr.sbin/afs/src/lwp/plwp.c799
-rw-r--r--usr.sbin/afs/src/lwp/plwp.h18
-rw-r--r--usr.sbin/afs/src/lwp/preempt.c2
-rw-r--r--usr.sbin/afs/src/lwp/preempt.h8
-rw-r--r--usr.sbin/afs/src/lwp/process-vpp.s2
-rw-r--r--usr.sbin/afs/src/lwp/process.aix22.S2
-rw-r--r--usr.sbin/afs/src/lwp/process.alpha.S2
-rw-r--r--usr.sbin/afs/src/lwp/process.i386.S2
-rw-r--r--usr.sbin/afs/src/lwp/process.ibm032.S2
-rw-r--r--usr.sbin/afs/src/lwp/process.m68k.S2
-rw-r--r--usr.sbin/afs/src/lwp/process.mips.S2
-rw-r--r--usr.sbin/afs/src/lwp/process.ppc.S2
-rw-r--r--usr.sbin/afs/src/lwp/process.rios.S2
-rw-r--r--usr.sbin/afs/src/lwp/process.sparc.S8
-rw-r--r--usr.sbin/afs/src/lwp/process.vax.S2
-rw-r--r--usr.sbin/afs/src/lwp/q.c2
-rw-r--r--usr.sbin/afs/src/lwp/q.h2
-rw-r--r--usr.sbin/afs/src/lwp/rw.c19
-rw-r--r--usr.sbin/afs/src/lwp/testlwp.c63
-rw-r--r--usr.sbin/afs/src/lwp/testprocess.c2
-rw-r--r--usr.sbin/afs/src/lwp/timer.c28
-rw-r--r--usr.sbin/afs/src/lwp/timer.h8
30 files changed, 842 insertions, 637 deletions
diff --git a/usr.sbin/afs/src/lwp/fasttime.c b/usr.sbin/afs/src/lwp/fasttime.c
index 128efc69a1b..4cefa1eb4e0 100644
--- a/usr.sbin/afs/src/lwp/fasttime.c
+++ b/usr.sbin/afs/src/lwp/fasttime.c
@@ -38,7 +38,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
-RCSID("$KTH: fasttime.c,v 1.8 1999/12/31 05:38:58 assar Exp $");
+RCSID("$arla: fasttime.c,v 1.10 2002/12/20 12:54:55 lha Exp $");
#endif
#include <stdio.h>
@@ -56,9 +56,6 @@ RCSID("$KTH: fasttime.c,v 1.8 1999/12/31 05:38:58 assar Exp $");
#include <libelf/nlist.h>
#endif
#endif
-#ifdef USE_MMAPTIME
-#include <mmaptime.h>
-#endif
#include "timer.h"
@@ -97,12 +94,6 @@ FT_Init(int printErrors, int notReally)
if (notReally)
return 0; /* fake success, but leave initState
* wrong. */
-#ifdef USE_MMAPTIME
- printErrors = mmaptime_probe();
-#endif
-
- if (printErrors)
- fprintf(stderr, "FT_Init: mmap not implemented on this kernel\n");
return (-1);
}
@@ -114,15 +105,11 @@ FT_Init(int printErrors, int notReally)
* punt to gettimeofday.
*/
int
-FT_GetTimeOfDay(register struct timeval * tv, register struct timezone * tz)
+FT_GetTimeOfDay(struct timeval * tv, struct timezone * tz)
{
- register int ret;
+ int ret;
-#ifdef USE_MMAPTIME
- ret = mmaptime_gettimeofday(tv, tz);
-#else
ret = gettimeofday(tv, tz);
-#endif
if (!ret) {
/*
@@ -152,28 +139,20 @@ TM_GetTimeOfDay(struct timeval * tv, struct timezone * tz)
int
FT_AGetTimeOfDay(struct timeval * tv, struct timezone * tz)
{
-#ifdef USE_MMAPTIME
- return mmaptime_gettimeofday(tv, tz);
-#else
if (FT_LastTime.tv_sec) {
tv->tv_sec = FT_LastTime.tv_sec;
tv->tv_usec = FT_LastTime.tv_usec;
return 0;
}
return FT_GetTimeOfDay(tv, tz);
-#endif
}
unsigned int
FT_ApproxTime(void)
{
-#ifdef USE_MMAPTIME
- mmaptime_gettimeofday(&FT_LastTime, NULL);
-#else
if (!FT_LastTime.tv_sec) {
FT_GetTimeOfDay(&FT_LastTime, 0);
}
-#endif
return FT_LastTime.tv_sec;
}
diff --git a/usr.sbin/afs/src/lwp/iomgr.c b/usr.sbin/afs/src/lwp/iomgr.c
index 93e55dd2968..7f702bbdfe7 100644
--- a/usr.sbin/afs/src/lwp/iomgr.c
+++ b/usr.sbin/afs/src/lwp/iomgr.c
@@ -35,7 +35,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
-RCSID("$KTH: iomgr.c,v 1.24 2000/02/15 23:53:40 assar Exp $");
+RCSID("$arla: iomgr.c,v 1.25 2002/06/01 17:47:47 lha Exp $");
#endif
#include <stdio.h>
@@ -57,7 +57,7 @@ static void SignalIO(int, fd_set *, fd_set *, fd_set *) ;
static void SignalTimeout(int fds, struct timeval *timeout) ;
static int SignalSignals (void);
-int FT_GetTimeOfDay(register struct timeval *, register struct timezone *);
+int FT_GetTimeOfDay(struct timeval *, struct timezone *);
/********************************\
* *
@@ -216,7 +216,7 @@ FD_LOGAND(fd_set *set1, fd_set *set2)
static struct IoRequest *
NewRequest(void)
{
- register struct IoRequest *request;
+ struct IoRequest *request;
if ((request = iorFreeList) != NULL)
iorFreeList = request->next;
@@ -262,7 +262,7 @@ IOMGR(char *dummy)
woke_someone = TRUE;
TM_Rescan(Requests);
for (;;) {
- register struct IoRequest *req;
+ struct IoRequest *req;
struct TM_Elem *expired;
expired = TM_GetExpired(Requests);
if (expired == NULL) break;
@@ -300,7 +300,7 @@ IOMGR(char *dummy)
nfds = 0;
rfds = wfds = efds = NULL;
FOR_ALL_ELTS(r, Requests, {
- register struct IoRequest *req;
+ struct IoRequest *req;
req = (struct IoRequest *) r -> BackPointer;
if (req->rfds) {
if (rfds)
@@ -414,8 +414,8 @@ SignalIO(int fds, fd_set *rfds, fd_set *wfds, fd_set *efds)
{
/* Look at everyone who's bit mask was affected */
FOR_ALL_ELTS(r, Requests, {
- register struct IoRequest *req;
- register PROCESS pid;
+ struct IoRequest *req;
+ PROCESS pid;
int doit = 0;
req = (struct IoRequest *) r -> BackPointer;
@@ -443,12 +443,12 @@ SignalIO(int fds, fd_set *rfds, fd_set *wfds, fd_set *efds)
}
static void
-SignalTimeout(int fds, register struct timeval *timeout)
+SignalTimeout(int fds, struct timeval *timeout)
{
/* Find everyone who has specified timeout */
FOR_ALL_ELTS(r, Requests, {
- register struct IoRequest *req;
- register PROCESS pid;
+ struct IoRequest *req;
+ PROCESS pid;
req = (struct IoRequest *) r -> BackPointer;
if (TM_eql(&r->TimeLeft, timeout)) {
req -> result = fds;
@@ -484,8 +484,8 @@ static int
SignalSignals (void)
{
bool gotone = FALSE;
- register int i;
- register void (*p)();
+ int i;
+ void (*p)();
long stackSize;
anySigsDelivered = FALSE;
@@ -524,7 +524,7 @@ static PROCESS IOMGR_Id = NULL;
int
IOMGR_SoftSig(void (*aproc)(), char *arock)
{
- register int i;
+ int i;
for (i=0;i<NSOFTSIG;i++) {
if (sigProc[i] == 0) {
/* a free entry */
@@ -596,7 +596,7 @@ IOMGR_Poll(void)
FT_GetTimeOfDay(&tv, 0); /* force accurate time check */
TM_Rescan(Requests);
for (;;) {
- register struct IoRequest *req;
+ struct IoRequest *req;
struct TM_Elem *expired;
expired = TM_GetExpired(Requests);
if (expired == NULL) break;
@@ -679,7 +679,7 @@ int
IOMGR_Select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *timeout)
{
- register struct IoRequest *request;
+ struct IoRequest *request;
int result;
/* See if polling request. If so, handle right here */
@@ -770,9 +770,9 @@ IOMGR_Select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
}
int
-IOMGR_Cancel(register PROCESS pid)
+IOMGR_Cancel(PROCESS pid)
{
- register struct IoRequest *request;
+ struct IoRequest *request;
if ((request = pid->iomgrRequest) == 0) return -1; /* Pid not found */
diff --git a/usr.sbin/afs/src/lwp/lock.c b/usr.sbin/afs/src/lwp/lock.c
index 9aad0fc53d8..4ed3a511c06 100644
--- a/usr.sbin/afs/src/lwp/lock.c
+++ b/usr.sbin/afs/src/lwp/lock.c
@@ -34,7 +34,7 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
-RCSID("$KTH: lock.c,v 1.10 2000/10/20 11:04:47 lha Exp $");
+RCSID("$arla: lock.c,v 1.11 2002/06/01 17:47:47 lha Exp $");
#endif
#include "lwp.h"
#include "lock.h"
@@ -47,7 +47,7 @@ RCSID("$KTH: lock.c,v 1.10 2000/10/20 11:04:47 lha Exp $");
#define TRUE 1
void
-Lock_Init(register struct Lock *lock)
+Lock_Init(struct Lock *lock)
{
lock -> readers_reading = 0;
lock -> excl_locked = 0;
@@ -57,7 +57,7 @@ Lock_Init(register struct Lock *lock)
}
void
-Lock_Obtain(register struct Lock *lock, int how)
+Lock_Obtain(struct Lock *lock, int how)
{
switch (how) {
@@ -104,7 +104,7 @@ Lock_Obtain(register struct Lock *lock, int how)
/* release a lock, giving preference to new readers */
void
-Lock_ReleaseR(register struct Lock *lock)
+Lock_ReleaseR(struct Lock *lock)
{
if (lock->wait_states & READ_LOCK) {
lock->wait_states &= ~READ_LOCK;
@@ -118,7 +118,7 @@ Lock_ReleaseR(register struct Lock *lock)
/* release a lock, giving preference to new writers */
void
-Lock_ReleaseW(register struct Lock *lock)
+Lock_ReleaseW(struct Lock *lock)
{
if (lock->wait_states & EXCL_LOCKS) {
lock->wait_states &= ~EXCL_LOCKS;
@@ -137,7 +137,7 @@ Lock_ReleaseW(register struct Lock *lock)
/* release a write lock and sleep on an address, atomically */
void
-LWP_WaitProcessR(register char *addr, register struct Lock *alock)
+LWP_WaitProcessR(char *addr, struct Lock *alock)
{
ReleaseReadLock(alock);
LWP_WaitProcess(addr);
@@ -145,7 +145,7 @@ LWP_WaitProcessR(register char *addr, register struct Lock *alock)
/* release a write lock and sleep on an address, atomically */
void
-LWP_WaitProcessW(register char *addr, register struct Lock *alock)
+LWP_WaitProcessW(char *addr, struct Lock *alock)
{
ReleaseWriteLock(alock);
LWP_WaitProcess(addr);
@@ -153,7 +153,7 @@ LWP_WaitProcessW(register char *addr, register struct Lock *alock)
/* release a write lock and sleep on an address, atomically */
void
-LWP_WaitProcessS(register char *addr, register struct Lock *alock)
+LWP_WaitProcessS(char *addr, struct Lock *alock)
{
ReleaseSharedLock(alock);
LWP_WaitProcess(addr);
@@ -166,7 +166,7 @@ LWP_WaitProcessS(register char *addr, register struct Lock *alock)
#define PANICPRINT(msg) fprintf(stderr,"Panic in %s at %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, msg)
static int
-WillBlock (register struct Lock *lock, int how)
+WillBlock (struct Lock *lock, int how)
{
switch (how) {
case READ_LOCK:
@@ -182,7 +182,7 @@ WillBlock (register struct Lock *lock, int how)
}
static void
-ObtainOneLock(register struct Lock *lock, int how)
+ObtainOneLock(struct Lock *lock, int how)
{
switch (how) {
case READ_LOCK:
@@ -205,7 +205,7 @@ ObtainOneLock(register struct Lock *lock, int how)
}
static void
-ReleaseOneLock(register struct Lock *lock, int how)
+ReleaseOneLock(struct Lock *lock, int how)
{
switch(how) {
case READ_LOCK:
@@ -232,8 +232,8 @@ ReleaseOneLock(register struct Lock *lock, int how)
*/
void
-_ObtainTwoLocks(register struct Lock *lock1, int how1,
- register struct Lock *lock2, int how2)
+_ObtainTwoLocks(struct Lock *lock1, int how1,
+ struct Lock *lock2, int how2)
{
struct timeval timeout;
diff --git a/usr.sbin/afs/src/lwp/lock.h b/usr.sbin/afs/src/lwp/lock.h
index 3b2e0924638..f87fca91421 100644
--- a/usr.sbin/afs/src/lwp/lock.h
+++ b/usr.sbin/afs/src/lwp/lock.h
@@ -22,7 +22,7 @@
****************************************************************************
*/
-/* $KTH: lock.h,v 1.11 2000/10/20 16:18:35 assar Exp $ */
+/* $arla: lock.h,v 1.13 2002/06/01 17:47:48 lha Exp $ */
/*******************************************************************\
* *
@@ -70,10 +70,10 @@ struct Lock {
/* Prototypes */
-void Lock_ReleaseR(register struct Lock *);
-void Lock_ReleaseW(register struct Lock *);
-void Lock_Obtain(register struct Lock *, int);
-void Lock_Init(register struct Lock *);
+void Lock_ReleaseR(struct Lock *);
+void Lock_ReleaseW(struct Lock *);
+void Lock_Obtain(struct Lock *, int);
+void Lock_Init(struct Lock *);
#define READ_LOCK 1
#define WRITE_LOCK 2
@@ -86,8 +86,10 @@ void Lock_Init(register struct Lock *);
#ifdef LOCK_DEBUG
#define DEBUGWRITE(message,lock) do { \
+ fprintf(stderr,"th#%d ", LWP_Index()); \
fprintf(stderr,message,lock,__FILE__,__LINE__); } while (0)
#define DEBUGWRITE_4(message,lock1,how1,lock2,how2) do { \
+ fprintf(stderr,"th#%d ", LWP_Index()); \
fprintf(stderr,message,lock1,how1,lock2,how2,__FILE__,__LINE__); } while (0)
#else
#define DEBUGWRITE(message,lock) do { ; } while (0)
@@ -283,9 +285,9 @@ void Lock_Init(register struct Lock *);
#define WriteLocked(lock)\
((lock)->excl_locked & WRITE_LOCK)
-void LWP_WaitProcessR(register char *addr, register struct Lock *alock);
-void LWP_WaitProcessW(register char *addr, register struct Lock *alock);
-void LWP_WaitProcessS(register char *addr, register struct Lock *alock);
+void LWP_WaitProcessR(char *addr, struct Lock *alock);
+void LWP_WaitProcessW(char *addr, struct Lock *alock);
+void LWP_WaitProcessS(char *addr, struct Lock *alock);
/* This attempts to obtain two locks in a secure fashion */
@@ -296,7 +298,7 @@ void LWP_WaitProcessS(register char *addr, register struct Lock *alock);
ENDMAC
void
-_ObtainTwoLocks(register struct Lock *lock1, int how1,
- register struct Lock *lock2, int how2);
+_ObtainTwoLocks(struct Lock *lock1, int how1,
+ struct Lock *lock2, int how2);
#endif /* LOCK_H */
diff --git a/usr.sbin/afs/src/lwp/lwp_asm.c b/usr.sbin/afs/src/lwp/lwp_asm.c
index 5e6f354c90c..5728dc8e484 100644
--- a/usr.sbin/afs/src/lwp/lwp_asm.c
+++ b/usr.sbin/afs/src/lwp/lwp_asm.c
@@ -27,17 +27,34 @@
* *
\*******************************************************************/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
/* allocate externs here */
#define LWP_KERNEL
-#include "lwp.h"
+#include <lwp.h>
+#include "preempt.h"
-RCSID("$KTH: lwp_asm.c,v 1.16.2.1 2001/02/21 17:53:17 lha Exp $");
+RCSID("$arla: lwp_asm.c,v 1.27 2002/07/16 19:35:40 lha Exp $");
#ifdef AFS_AIX32_ENV
#include <ulimit.h>
@@ -48,8 +65,6 @@ RCSID("$KTH: lwp_asm.c,v 1.16.2.1 2001/02/21 17:53:17 lha Exp $");
#pragma alloca
#endif
-extern char PRE_Block; /* from preempt.c */
-
#define ON 1
#define OFF 0
#define TRUE 1
@@ -110,10 +125,10 @@ static void Free_PCB(PROCESS pid) ;
static void Exit_LWP(void);
static void Initialize_PCB(PROCESS temp, int priority, char *stack,
int stacksize, void (*ep)() , char *parm,
- char *name) ;
+ const char *name) ;
static long Initialize_Stack(char *stackptr,int stacksize) ;
static int Stack_Used(char *stackptr, int stacksize) ;
-static int Internal_Signal(register char *event) ;
+static int Internal_Signal(char *event) ;
char (*RC_to_ASCII());
#define MAX_PRIORITIES (LWP_MAX_PRIORITY+1)
@@ -146,7 +161,7 @@ int lwp_stackUseEnabled = TRUE; /* pay the price */
int lwp_nextindex;
static void
-lwp_remove(register PROCESS p, register struct QUEUE *q)
+lwp_remove(PROCESS p, struct QUEUE *q)
{
/* Special test for only element on queue */
if (q->count == 1)
@@ -163,7 +178,7 @@ lwp_remove(register PROCESS p, register struct QUEUE *q)
}
static void
-insert(register PROCESS p, register struct QUEUE *q)
+insert(PROCESS p, struct QUEUE *q)
{
if (q->head == NULL) { /* Queue is empty */
q -> head = p;
@@ -188,8 +203,8 @@ move(PROCESS p, struct QUEUE *from, struct QUEUE *to)
/* Iterator macro */
#define for_all_elts(var, q, body)\
{\
- register PROCESS var, _NEXT_;\
- register int _I_;\
+ PROCESS var, _NEXT_;\
+ int _I_;\
for (_I_=q.count, var = q.head; _I_>0; _I_--, var=_NEXT_) {\
_NEXT_ = var -> next;\
body\
@@ -233,7 +248,7 @@ static struct lwp_ctl *lwp_init = 0;
int
LWP_QWait(void)
{
- register PROCESS tp;
+ PROCESS tp;
(tp=lwp_cpptr) -> status = QWAITING;
lwp_remove(tp, &runnable[tp->priority]);
Set_LWP_RC();
@@ -241,7 +256,7 @@ LWP_QWait(void)
}
int
-LWP_QSignal(register PROCESS pid)
+LWP_QSignal(PROCESS pid)
{
if (pid->status == QWAITING) {
pid->status = READY;
@@ -254,7 +269,7 @@ LWP_QSignal(register PROCESS pid)
#ifdef AFS_AIX32_ENV
char *
reserveFromStack(size)
- register long size;
+ long size;
{
char *x;
x = alloca(size);
@@ -262,9 +277,117 @@ reserveFromStack(size)
}
#endif
+#if defined(LWP_REDZONE) && defined(HAVE_MMAP)
+
+/*
+ * Redzone protection of stack
+ *
+ * We protect one page before and one after the stack to make sure
+ * none over/under runs the stack. The size of the stack is saved one
+ * the first page together with a magic number to make sure we free
+ * the right pages.
+ *
+ * If the operating system doesn't support mmap, turn redzone off in
+ * the autoconf glue.
+ */
+
+#define P_SIZE_OFFSET 16
+#define P_MAGIC 0x7442e938
+
+static void *
+lwp_stackmalloc(size_t size)
+{
+ char *p, *p_after, *p_before;
+ size_t pagesize = getpagesize();
+ int pages = (size - 1) / pagesize + 1;
+ int fd = -1;
+
+#ifndef MAP_ANON
+#define MAP_ANON 0
+#ifndef _PATH_DEV_ZERO
+#define _PATH_DEV_ZERO "/dev/zero"
+#endif
+ fd = open(_PATH_DEV_ZERO, O_RDWR, 0644);
+#endif
+
+ p = mmap(0, (pages + 2) * pagesize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON, fd, 0);
+ if (p == MAP_FAILED) {
+ perror("mmap");
+ abort();
+ }
+
+ p_before = p;
+ p += pagesize;
+ p_after = p + pages * pagesize;
+
+ /* store the magic and the length in the first page */
+
+ *((unsigned long *)p_before) = P_MAGIC;
+ *((unsigned long *)(p_before + P_SIZE_OFFSET)) = (pages + 2) * pagesize;
+
+ /* protect pages */
+
+ if (mprotect(p_before, pagesize, PROT_NONE) < 0) {
+ perror("mprotect before");
+ abort();
+ }
+ if (mprotect(p_after, pagesize, PROT_NONE) < 0) {
+ perror("mprotect after");
+ abort();
+ }
+ return p;
+}
+
+static void
+lwp_stackfree(void *ptr, size_t len)
+{
+ size_t pagesize = getpagesize();
+ char *realptr;
+ unsigned long magic;
+ size_t length;
+
+ if (((size_t)ptr) % pagesize != 0)
+ abort();
+
+ realptr = ((char *)ptr) - pagesize;
+
+ if (mprotect(realptr, pagesize, PROT_READ) < 0) {
+ perror("mprotect");
+ abort();
+ }
+
+ magic = *((unsigned long *)realptr);
+ if (magic != P_MAGIC)
+ abort();
+ length = *((unsigned long *)(realptr + P_SIZE_OFFSET));
+ if (len != length - 2 * pagesize)
+ abort();
+
+ if (munmap(realptr, length) < 0) {
+ perror("munmap");
+ exit(1);
+ }
+}
+
+#else
+
+static void *
+lwp_stackmalloc(size_t size)
+{
+ return malloc(size);
+}
+
+static void
+lwp_stackfree(void *ptr, size_t len)
+{
+ free(ptr);
+}
+#endif
+
int
LWP_CreateProcess(void (*ep)(), int stacksize, int priority,
- char *parm, char *name, PROCESS *pid)
+ char *parm, const char *name, PROCESS *pid)
{
PROCESS temp, temp2;
#ifdef AFS_AIX32_ENV
@@ -287,86 +410,89 @@ LWP_CreateProcess(void (*ep)(), int stacksize, int priority,
Debug(0, ("Entered LWP_CreateProcess"))
/* Throw away all dead process control blocks */
purge_dead_pcbs();
- if (lwp_init) {
- temp = (PROCESS) malloc(sizeof(struct lwp_pcb));
- if (temp == NULL) {
- Set_LWP_RC();
- return LWP_ENOMEM;
- }
-
- /* align stacksize */
- stacksize = REGSIZE * ((stacksize+REGSIZE-1) / REGSIZE);
+ if (!lwp_init)
+ return LWP_EINIT;
-#ifdef AFS_AIX32_ENV
- if (!stackptr) {
- /*
- * The following signal action for AIX is necessary so that in case of a
- * crash (i.e. core is generated) we can include the user's data section
- * in the core dump. Unfortunately, by default, only a partial core is
- * generated which, in many cases, isn't too useful.
- *
- * We also do it here in case the main program forgets to do it.
- */
- struct sigaction nsa;
- extern int geteuid();
+
+ temp = (PROCESS) malloc(sizeof(struct lwp_pcb));
+ if (temp == NULL) {
+ Set_LWP_RC();
+ return LWP_ENOMEM;
+ }
+
+ /* align stacksize */
+ stacksize = REGSIZE * ((stacksize+REGSIZE-1) / REGSIZE);
- sigemptyset(&nsa.sa_mask);
- nsa.sa_handler = SIG_DFL;
- nsa.sa_flags = SA_FULLDUMP;
- sigaction(SIGSEGV, &nsa, NULL);
-
- /*
- * First we need to increase the default resource limits,
- * if necessary, so that we can guarantee that we have the
- * resources to create the core file, but we can't always
- * do it as an ordinary user.
- */
- if (!geteuid()) {
+#ifdef AFS_AIX32_ENV
+ if (!stackptr) {
+ /*
+ * The following signal action for AIX is necessary so that in case of a
+ * crash (i.e. core is generated) we can include the user's data section
+ * in the core dump. Unfortunately, by default, only a partial core is
+ * generated which, in many cases, isn't too useful.
+ *
+ * We also do it here in case the main program forgets to do it.
+ */
+ struct sigaction nsa;
+ extern int geteuid();
+
+ sigemptyset(&nsa.sa_mask);
+ nsa.sa_handler = SIG_DFL;
+ nsa.sa_flags = SA_FULLDUMP;
+ sigaction(SIGSEGV, &nsa, NULL);
+
+ /*
+ * First we need to increase the default resource limits,
+ * if necessary, so that we can guarantee that we have the
+ * resources to create the core file, but we can't always
+ * do it as an ordinary user.
+ */
+ if (!geteuid()) {
setlim(RLIMIT_FSIZE, 0, 1048575); /* 1 Gig */
setlim(RLIMIT_STACK, 0, 65536); /* 65 Meg */
setlim(RLIMIT_CORE, 0, 131072); /* 131 Meg */
- }
- /*
- * Now reserve in one scoop all the stack space that will be used
- * by the particular application's main (i.e. non-lwp) body. This
- * is plenty space for any of our applications.
- */
- stackptr = reserveFromStack(lwp_MaxStackSize);
- }
- stackptr -= stacksize;
-#else
- if ((stackptr = (char *) malloc(stacksize)) == NULL) {
- Set_LWP_RC();
- return LWP_ENOMEM;
- }
-#endif
- if (priority < 0 || priority >= MAX_PRIORITIES) {
- Set_LWP_RC();
- return LWP_EBADPRI;
}
- Initialize_Stack(stackptr, stacksize);
- Initialize_PCB(temp, priority, stackptr, stacksize, ep, parm, name);
- insert(temp, &runnable[priority]);
- temp2 = lwp_cpptr;
- if (PRE_Block != 0) Abort_LWP("PRE_Block not 0");
-
- /* Gross hack: beware! */
- PRE_Block = 1;
- lwp_cpptr = temp;
+ /*
+ * Now reserve in one scoop all the stack space that will be used
+ * by the particular application's main (i.e. non-lwp) body. This
+ * is plenty space for any of our applications.
+ */
+ stackptr = reserveFromStack(lwp_MaxStackSize);
+ }
+ stackptr -= stacksize;
+#else /* !AFS_AIX32_ENV */
+ if ((stackptr = (char *) lwp_stackmalloc(stacksize)) == NULL) {
+ Set_LWP_RC();
+ return LWP_ENOMEM;
+ }
+#endif /* AFS_AIX32_ENV */
+ if (priority < 0 || priority >= MAX_PRIORITIES) {
+ Set_LWP_RC();
+ return LWP_EBADPRI;
+ }
+ Initialize_Stack(stackptr, stacksize);
+ Initialize_PCB(temp, priority, stackptr, stacksize, ep, parm, name);
+ insert(temp, &runnable[priority]);
+ temp2 = lwp_cpptr;
+
+ if (PRE_Block != 0)
+ Abort_LWP("PRE_Block not 0");
+
+ /* Gross hack: beware! */
+ PRE_Block = 1;
+ lwp_cpptr = temp;
#ifdef __hp9000s800
- savecontext(Create_Process_Part2, &temp2->context,
- stackptr + (REGSIZE * STACK_HEADROOM));
+ savecontext(Create_Process_Part2, &temp2->context,
+ stackptr + (REGSIZE * STACK_HEADROOM));
#else
- savecontext(Create_Process_Part2, &temp2->context,
- stackptr + stacksize - (REGSIZE * STACK_HEADROOM));
+ savecontext(Create_Process_Part2, &temp2->context,
+ stackptr + stacksize - (REGSIZE * STACK_HEADROOM));
#endif
- /* End of gross hack */
-
- Set_LWP_RC();
- *pid = temp;
- return 0;
- } else
- return LWP_EINIT;
+ /* End of gross hack */
+
+ Set_LWP_RC();
+ *pid = temp;
+ return 0;
}
/* returns pid of current process */
@@ -431,7 +557,7 @@ static void
Dump_Processes(void)
{
if (lwp_init) {
- register int i;
+ int i;
for (i=0; i<MAX_PRIORITIES; i++)
for_all_elts(x, runnable[i], {
printf("[Priority %d]\n", i);
@@ -460,7 +586,7 @@ LWP_InitializeProcessSupport(int priority, PROCESS *pid)
{
PROCESS temp;
struct lwp_pcb dummy;
- register int i;
+ int i;
Debug(0, ("Entered LWP_InitializeProcessSupport"))
if (lwp_init != NULL) return LWP_SUCCESS;
@@ -510,7 +636,7 @@ LWP_INTERNALSIGNAL(void *event, int yield)
int
LWP_TerminateProcessSupport(void)
{
- register int i;
+ int i;
Debug(0, ("Entered Terminate_Process_Support"))
if (lwp_init == NULL) return LWP_EINIT;
@@ -528,7 +654,7 @@ LWP_TerminateProcessSupport(void)
int
LWP_MwaitProcess(int wcount, char *evlist[])
{
- register int ecount, i;
+ int ecount, i;
Debug(0, ("Entered Mwait_Process [waitcnt = %d]", wcount))
@@ -635,7 +761,7 @@ Create_Process_Part2(void)
/* remove a PCB from the process list */
static void
-Delete_PCB(register PROCESS pid)
+Delete_PCB(PROCESS pid)
{
Debug(4, ("Entered Delete_PCB"))
lwp_remove(pid, (pid->blockflag ||
@@ -671,7 +797,6 @@ Dump_One_Process(PROCESS pid)
pid->stacksize, pid->stack);
printf("***LWP: HWM stack usage: ");
printf("%d\n", Stack_Used(pid->stack,pid->stacksize));
- free (pid->stack);
}
printf("***LWP: Current Stack Pointer: %p\n", pid->context.topstack);
if (pid->eventcnt > 0) {
@@ -700,7 +825,7 @@ int LWP_TraceProcesses = 0;
static void
Dispatcher(void)
{
- register int i;
+ int i;
#ifdef DEBUG
static int dispatch_count = 0;
@@ -765,11 +890,14 @@ Dispatcher(void)
*/
if (lwp_cpptr != NULL && lwp_cpptr == runnable[lwp_cpptr->priority].head)
runnable[lwp_cpptr->priority].head = runnable[lwp_cpptr->priority].head->next;
+
/* Find highest priority with runnable processes. */
- for (i=MAX_PRIORITIES-1; i>=0; i--)
- if (runnable[i].head != NULL) break;
+ for (i = MAX_PRIORITIES - 1; i >= 0; i--)
+ if (runnable[i].head != NULL)
+ break;
- if (i < 0) Abort_LWP("No READY processes");
+ if (i < 0)
+ Abort_LWP("No READY processes");
#ifdef DEBUG
if (LWP_TraceProcesses > 0)
@@ -820,7 +948,7 @@ Free_PCB(PROCESS pid)
if (pid -> stack != NULL) {
Debug(0, ("HWM stack usage: %d, [PCB at %p]",
Stack_Used(pid->stack,pid->stacksize), pid))
- free(pid -> stack);
+ lwp_stackfree(pid -> stack, pid->stacksize);
}
if (pid->eventlist != NULL) free(pid->eventlist);
free(pid);
@@ -828,14 +956,14 @@ Free_PCB(PROCESS pid)
static void
Initialize_PCB(PROCESS temp, int priority, char *stack, int stacksize,
- void (*ep)(), char *parm, char *name)
+ void (*ep)(), char *parm, const char *name)
{
- register int i = 0;
-
Debug(4, ("Entered Initialize_PCB"))
- if (name != NULL)
- while (((temp -> name[i] = name[i]) != '\0') && (i < 31)) i++;
- temp -> name[31] = '\0';
+ if (name != NULL) {
+ strncpy(temp -> name, name, sizeof(temp -> name));
+ temp -> name[sizeof(temp -> name) - 1] = '\0';
+ } else
+ temp -> name[0] = '\0';
temp -> status = READY;
temp -> eventlist = (char **)malloc(EVINITSIZE*sizeof(char *));
temp -> eventlistsize = EVINITSIZE;
@@ -865,10 +993,10 @@ Initialize_PCB(PROCESS temp, int priority, char *stack, int stacksize,
}
static int
-Internal_Signal(register char *event)
+Internal_Signal(char *event)
{
int rc = LWP_ENOWAIT;
- register int i;
+ int i;
Debug(0, ("Entered Internal_Signal [event id %p]", event))
if (!lwp_init) return LWP_EINIT;
@@ -897,7 +1025,7 @@ Internal_Signal(register char *event)
static long
Initialize_Stack(char *stackptr, int stacksize)
{
- register int i;
+ int i;
Debug(4, ("Entered Initialize_Stack"))
if (lwp_stackUseEnabled)
@@ -913,9 +1041,9 @@ Initialize_Stack(char *stackptr, int stacksize)
}
static int
-Stack_Used(register char *stackptr, int stacksize)
+Stack_Used(char *stackptr, int stacksize)
{
- register int i;
+ int i;
#ifdef __hp9000s800
if (*(long *) (stackptr + stacksize - 4) == STACKMAGIC)
@@ -955,8 +1083,8 @@ Stack_Used(register char *stackptr, int stacksize)
int
LWP_NewRock(int Tag, char *Value)
{
- register int i;
- register struct rock *ra; /* rock array */
+ int i;
+ struct rock *ra; /* rock array */
ra = lwp_cpptr->rlist;
@@ -982,17 +1110,17 @@ LWP_NewRock(int Tag, char *Value)
int
LWP_GetRock(int Tag, char **Value)
{
- register int i;
- register struct rock *ra;
+ int i;
+ struct rock *ra;
ra = lwp_cpptr->rlist;
- for (i = 0; i < lwp_cpptr->rused; i++)
- if (ra[i].tag == Tag)
- {
+ for (i = 0; i < lwp_cpptr->rused; i++) {
+ if (ra[i].tag == Tag) {
*Value = ra[i].value;
return(LWP_SUCCESS);
- }
+ }
+ }
return(LWP_EBADROCK);
}
diff --git a/usr.sbin/afs/src/lwp/lwp_asm.h b/usr.sbin/afs/src/lwp/lwp_asm.h
index c5c32bfe9cc..4ccb9053695 100644
--- a/usr.sbin/afs/src/lwp/lwp_asm.h
+++ b/usr.sbin/afs/src/lwp/lwp_asm.h
@@ -28,7 +28,7 @@
* *
\*******************************************************************/
-/* $KTH: lwp_asm.h,v 1.17 2000/10/20 11:01:49 lha Exp $ */
+/* $arla: lwp_asm.h,v 1.19 2002/06/01 17:47:48 lha Exp $ */
#ifndef __LWP_INCLUDE_
#define __LWP_INCLUDE_ 1
@@ -168,7 +168,7 @@ struct lwp_ctl { /* LWP control structure */
#ifndef LWP_KERNEL
extern
#endif
- char lwp_debug; /* ON = show LWP debugging trace */
+ int lwp_debug; /* ON = show LWP debugging trace */
#if defined(AFS_SUN5_ENV) || defined(AFS_LINUX_ENV)
#define AFS_POSIX_SIGNALS
@@ -200,7 +200,7 @@ int LWP_DestroyProcess(PROCESS);
int LWP_QWait(void);
/* exported interface */
-int LWP_CreateProcess(void (*)(), int, int, char *, char *, PROCESS *);
+int LWP_CreateProcess(void (*)(), int, int, char *, const char *, PROCESS *);
int LWP_CurrentProcess(PROCESS *);
int LWP_WaitProcess(void *);
int LWP_INTERNALSIGNAL(void *, int);
@@ -213,7 +213,7 @@ int LWP_StackUsed(PROCESS pid, int *max, int *used);
void IOMGR_Sleep(unsigned int);
int IOMGR_Select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
long IOMGR_Poll(void);
-int IOMGR_Cancel(register PROCESS);
+int IOMGR_Cancel(PROCESS);
int IOMGR_Initialize(void);
int IOMGR_SoftSig(void (*aproc)(), char *arock);
int IOMGR_Finalize(void);
diff --git a/usr.sbin/afs/src/lwp/lwp_elf.h b/usr.sbin/afs/src/lwp/lwp_elf.h
index 3dd4e311355..eef66f319e2 100644
--- a/usr.sbin/afs/src/lwp/lwp_elf.h
+++ b/usr.sbin/afs/src/lwp/lwp_elf.h
@@ -1,7 +1,7 @@
/*
* For common usage of elf platforms
*
- * $KTH: lwp_elf.h,v 1.2 2000/03/03 08:53:43 assar Exp $
+ * $arla: lwp_elf.h,v 1.2 2000/03/03 08:53:43 assar Exp $
*/
#ifndef _C_LABEL
diff --git a/usr.sbin/afs/src/lwp/make-process.o.sh.in b/usr.sbin/afs/src/lwp/make-process.o.sh.in
index d22c95c369e..e0e7a9e7190 100644
--- a/usr.sbin/afs/src/lwp/make-process.o.sh.in
+++ b/usr.sbin/afs/src/lwp/make-process.o.sh.in
@@ -3,7 +3,7 @@
# make-process.o.sh
# Try to make process.o various ways.
#
-# $KTH: make-process.o.sh.in,v 1.24.2.1 2001/02/21 17:53:19 lha Exp $
+# $arla: make-process.o.sh.in,v 1.28 2002/11/29 19:48:14 tol Exp $
#
srcdir=@srcdir@
@@ -29,9 +29,9 @@ LWP_O="@LWP_O@"
# Options that you may need to override for your CPU/OS
#
-PROCESS_S="undefined_you_loose"
+PROCESS_S="undefined_you_lose"
USE_AS="no"
-MYDEF=""
+MYDEF="-DUSING_ASM"
#
@@ -72,7 +72,7 @@ case "$HOST_OS" in
*hpux*) OSDEF="-DAFS_HPUX_ENV" ;;
aix*) CPUDEF=""; OSDEF="" ;;
uxpv*)
- $CPP -P ${srcdir}/process-vpp.s > foo.s
+ $CPP $MYDEF -P ${srcdir}/process-vpp.s > foo.s
$AS -o process.o foo.s && $RM -f foo.s && exit 0
$RM -f foo.s
exit 1
@@ -110,7 +110,7 @@ $RM -f process.o
#
-# Some $AS does "intresting" things, like ignorings the -o flag
+# Some $AS does "interesting" things, like ignorings the -o flag
# and creats a .i file that is preprocessed. (Digital Unix)
#
@@ -148,6 +148,19 @@ if test -s process.i ; then
$RM -f process.o
fi
+
+#
+# Try to use $CPP to preprocess
+#
+
+$CPP -I../include -I$srcdir $MYDEF $CPUDEF $OSDEF process.S > process.ss
+$AS process.ss -o process.o
+$RM -f process.ss
+
+# process.o there ?
+$CC -o testprocess testprocess.o process.o preempt.o ${LWP_O} && exit 0
+$RM -f process.o
+
#
# Try to fool $CC by adding a .c extension.
#
diff --git a/usr.sbin/afs/src/lwp/plwp.c b/usr.sbin/afs/src/lwp/plwp.c
index 9ef99f15e08..afe1815c3de 100644
--- a/usr.sbin/afs/src/lwp/plwp.c
+++ b/usr.sbin/afs/src/lwp/plwp.c
@@ -3,7 +3,7 @@
*
* Windows Threads support was added by Love <lha@stacken.kth.se>
* and debugged by Magnus <map@stacken.kth.se> and Robert <rb@abc.se>.
- * It make have a glue layer around the windows primiptives to make
+ * It provides a glue layer around the windows primitives to make
* it look like pthreads.
*/
/*
@@ -31,6 +31,7 @@
#include <config.h>
#endif
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -39,8 +40,9 @@
#define LWP_KERNEL
#include <lwp.h>
+#include "preempt.h"
-RCSID("$KTH: plwp.c,v 1.9 2000/05/12 08:41:32 lha Exp $");
+RCSID("$arla: plwp.c,v 1.22 2003/01/24 19:38:35 tol Exp $");
#ifdef AFS_AIX32_ENV
#include <ulimit.h>
@@ -55,8 +57,6 @@ RCSID("$KTH: plwp.c,v 1.9 2000/05/12 08:41:32 lha Exp $");
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
-extern char PRE_Block; /* from preempt.c */
-
#define ON 1
#define OFF 0
#define TRUE 1
@@ -68,24 +68,26 @@ extern char PRE_Block; /* from preempt.c */
#define MAXINT (~(1<<((sizeof(int)*8)-1)))
#define MINSTACK 44
-
/* Debugging macro */
#ifdef DEBUG
-#define Debug(level, msg)\
- if (lwp_debug && lwp_debug >= level) {\
- printf("***LWP(max=%d) (%p): ", Highest_runnable_priority, lwp_cpptr);\
- printf msg;\
- putchar('\n');\
- }
+#define Debug(level, msg) \
+ do { \
+ if (lwp_debug && lwp_debug >= level) { \
+ printf("***LWP(max=%d) (%p): ", \
+ Highest_runnable_priority, lwp_cpptr); \
+ printf msg; \
+ putchar('\n'); \
+ } \
+ } while(0)
#else
-#define Debug(level, msg)
+#define Debug(level, msg) do {} while (0)
#endif
#define lwp_timerclear(t) (t)->tv_sec = (t)->tv_usec = 0
/* Prototypes */
-static void Abort_LWP(char *msg) ;
+static void Abort_LWP(char *msg, ...) ;
static void Dispatcher(void);
static void Create_Process_Part2(PROCESS temp);
static void purge_dead_pcbs(void) ;
@@ -95,7 +97,7 @@ static void Exit_LWP();
static void Initialize_PCB(PROCESS temp, int priority, char *stack,
int stacksize, void (*ep)() , char *parm,
char *name) ;
-static int Internal_Signal(register char *event) ;
+static int Internal_Signal(char *event) ;
char (*RC_to_ASCII());
#define MAX_PRIORITIES (LWP_MAX_PRIORITY+1)
@@ -119,19 +121,19 @@ int lwp_nextindex = 0;
/* Iterator macro */
#define for_all_elts(var, q, body)\
{\
- register PROCESS var, _NEXT_;\
- register int _I_;\
+ PROCESS var, _NEXT_;\
+ int _I_;\
for (_I_=q.count, var = q.head; _I_>0; _I_--, var=_NEXT_) {\
_NEXT_ = var -> next;\
body\
}\
}
-static struct lwp_ctl *lwp_init = 0;
+static struct lwp_ctl *lwp_init = NULL;
static void Dump_One_Process(PROCESS pid);
static void Dump_Processes();
-static void Delete_PCB(register PROCESS pid);
+static void Delete_PCB(PROCESS pid);
static void Free_PCB(PROCESS pid);
static void Cal_Highest_runnable_priority();
static int InitializeProcessSupport(int, PROCESS *);
@@ -169,79 +171,72 @@ HANDLE run_sem, ct_mutex;
#define LWP_INT_UNLOCK(sem) ReleaseMutex (sem)
#endif
-static DWORD LWP_INT_LOCK(HANDLE *sem)
+static
+DWORD LWP_INT_LOCK(HANDLE *sem)
{
- DWORD ret = WaitForSingleObject(*sem, INFINITE);
+ DWORD ret;
+ Debug(0, ("LWP_INT_LOCK: sem = %p", *sem));
+ ret = WaitForSingleObject(*sem, INFINITE);
if (ret == WAIT_FAILED) {
- DWORD err = GetLastError();
- Debug(0, ("LWP_INT_LOCK: h = %p, wait = %ld, %ld\n",
- *sem, ret, err));
+ DWORD err = GetLastError();
+ Debug(0, ("LWP_INT_LOCK: h = %p, wait = %ld, %ld\n",
+ *sem, ret, err));
}
+ Debug(0, ("LWP_INT_LOCK: got %p", *sem));
return ret;
}
static DWORD LWP_INT_UNLOCK(HANDLE *sem)
{
- DWORD ret = ReleaseMutex(*sem);
+ DWORD ret;
+ Debug(0, ("LWP_INT_UNLOCK: sem = %p", *sem));
+ ret = ReleaseMutex(*sem);
if (!ret) {
- DWORD err = GetLastError();
- Debug(0, ("LWP_INT_UNLOCK: h = %p, wait = %ld, %ld\n",
- *sem, ret, err));
+ DWORD err = GetLastError();
+ Debug(0, ("LWP_INT_UNLOCK: h = %p, wait = %ld, %ld\n",
+ *sem, ret, err));
}
+ Debug(0, ("LWP_INT_UNLOCK: %p released", *sem));
return ret;
}
static DWORD LWP_INT_WAIT(HANDLE *cond, HANDLE *mutex)
{
- DWORD ret;
- static int times = 0;
- int this_time = times++;
-
- Debug(0, ("LWP_INT_WAIT(%d): cond: %p mutex: %p\n",
- this_time, *cond, *mutex));
- ret = ReleaseMutex (*mutex);
- if (!ret) {
- DWORD err = GetLastError();
- Debug(0, ("LWP_INT_WAIT(%d): ReleaseMutex failed: %ld error: %ld mutex\n",
- this_time, ret, err, *mutex));
- abort();
- }
- ret = WaitForSingleObject (*cond, INFINITE);
- if (ret != WAIT_OBJECT_0) {
- Debug(0, ("LWP_INT_WAIT(%d): WaitForSingleObject(cond) failed: %ld mutex: %p\n",
- this_time, ret, *mutex));
- abort();
- }
- ret = WaitForSingleObject (*mutex, INFINITE);
- if (ret != WAIT_OBJECT_0) {
- Debug(0, ("LWP_INT_WAIT(%d): WaitForSingleObject(mutex) failed: %ld mutex: %p\n",
- this_time, ret, *mutex));
- abort();
- }
-#if 0
- ret = SignalObjectAndWait(*mutex, *cond, INFINITE, FALSE /* XXX */);
- if (ret != WAIT_OBJECT_0) {
- DWORD err = GetLastError();
- Debug(0, ("LWP_INT_WAIT(%d): SignalObjectAndWait failed: %ld error: %ld mutex: %p cond: %p\n", this_time, ret, err, *mutex, *cond));
- /* XXX */
- return ret;
- }
- Debug(0, ("LWP_INT_WAIT(%d): woke up, waiting for mutex: cond: %p mutex: %p\n", this_time, *cond, *mutex));
- ret = WaitForSingleObject(*mutex, INFINITE);
- if (ret != WAIT_OBJECT_0) {
- Debug(0, ("LWP_INT_WAIT(%d): WaitForSingleObject(mutex) failed: %ld mutex: %p\n", this_time, ret, *mutex));
- /* XXX */
- return ret;
- }
-#endif
- Debug(0, ("LWP_INT_WAIT(%d): got mutex: cond: %p mutex: %p\n",
- this_time, *cond, *mutex));
- return 0;
+ DWORD ret;
+ static int times = 0;
+ int this_time = times++;
+
+ Debug(0, ("LWP_INT_WAIT(%d): cond: %p mutex: %p",
+ this_time, *cond, *mutex));
+ ret = ReleaseMutex (*mutex);
+ if (!ret) {
+ DWORD err = GetLastError();
+ Debug(0, ("LWP_INT_WAIT(%d): ReleaseMutex failed: %ld error: "
+ "%ld mutex\n", this_time, err, *mutex));
+ abort();
+ }
+ Debug(0, ("LWP_INT_WAIT(%d): mutex released, waiting", this_time));
+ ret = WaitForSingleObject (*cond, INFINITE);
+ if (ret != WAIT_OBJECT_0) {
+ Debug(0, ("LWP_INT_WAIT(%d): WaitForSingleObject(cond) failed: "
+ "%ld mutex: %p\n", this_time, ret, *mutex));
+ abort();
+ }
+ Debug(0, ("LWP_INT_WAIT(%d): got sem, waiting for mutex", this_time));
+ ret = WaitForSingleObject (*mutex, INFINITE);
+ if (ret != WAIT_OBJECT_0) {
+ Debug(0, ("LWP_INT_WAIT(%d): WaitForSingleObject(mutex) failed: "
+ "%ld mutex: %p\n", this_time, ret, *mutex));
+ abort();
+ }
+ Debug(0, ("LWP_INT_WAIT(%d): got mutex: cond: %p mutex: %p",
+ this_time, *cond, *mutex));
+ return 0;
}
#define LWP_INT_SIGNAL(cond) do { \
Debug(0, ("LWP_INT_SIGNAL: cond: %p\n", *cond)); \
-PulseEvent (*cond); } while (0)
+SetEvent (*cond); } while (0)
#define LWP_INT_EXIT(t) ExitThread ((int)t); /* XXX */
@@ -249,7 +244,7 @@ PulseEvent (*cond); } while (0)
#endif
static void
-lwpremove(register PROCESS p, register struct QUEUE *q)
+lwpremove(PROCESS p, struct QUEUE *q)
{
/* Special test for only element on queue */
if (q->count == 1)
@@ -267,7 +262,7 @@ lwpremove(register PROCESS p, register struct QUEUE *q)
}
static void
-lwpinsert(register PROCESS p, register struct QUEUE *q)
+lwpinsert(PROCESS p, struct QUEUE *q)
{
if (q->head == NULL) { /* Queue is empty */
q -> head = p;
@@ -292,14 +287,15 @@ lwpmove(PROCESS p, struct QUEUE *from, struct QUEUE *to)
int
LWP_TerminateProcessSupport() /* terminate all LWP support */
{
- register int i;
+ int i;
Debug(0, ("Entered Terminate_Process_Support"));
- if (lwp_init == NULL) return LWP_EINIT;
+ if (lwp_init == NULL)
+ return LWP_EINIT;
/* free all space allocated */
for (i=0; i<MAX_PRIORITIES; i++)
- for_all_elts(cur, runnable[i], { Free_PCB(cur);})
- for_all_elts(cur, blocked, { Free_PCB(cur);})
+ for_all_elts(cur, runnable[i], { Free_PCB(cur);});
+ for_all_elts(cur, blocked, { Free_PCB(cur);});
free((char *)lwp_init);
lwp_init = NULL;
return LWP_SUCCESS;
@@ -310,11 +306,11 @@ LWP_GetRock(int Tag, char **Value)
{
/* Obtains the pointer Value associated with the rock Tag of this LWP.
Returns:
- LWP_SUCCESS if specified rock exists and Value has been filled
- LWP_EBADROCK rock specified does not exist
+ LWP_SUCCESS if specified rock exists and Value has been filled
+ LWP_EBADROCK rock specified does not exist
*/
- register int i;
- register struct rock *ra;
+ int i;
+ struct rock *ra;
ra = lwp_cpptr->rlist;
@@ -322,15 +318,15 @@ LWP_GetRock(int Tag, char **Value)
if (ra[i].tag == Tag) {
#ifdef PTHREADS_LWP
#ifdef PTHREAD_GETSPECIFIC_TWOARG
- pthread_getspecific(ra[i].val, Value);
+ pthread_getspecific(ra[i].val, Value);
#else
- *Value = pthread_getspecific(ra[i].val);
+ *Value = pthread_getspecific(ra[i].val);
#endif
#elif WINDOWS_THREADS_LWP
- *Value = TlsGetValue((unsigned long) ra[i].val);
+ *Value = TlsGetValue((unsigned long) ra[i].val);
#endif
- /**Value = ra[i].value;*/
- return(LWP_SUCCESS);
+ /**Value = ra[i].value;*/
+ return(LWP_SUCCESS);
}
return(LWP_EBADROCK);
}
@@ -340,19 +336,19 @@ int
LWP_NewRock(int Tag, char *Value)
{
/* Finds a free rock and sets its value to Value.
- Return codes:
- LWP_SUCCESS Rock did not exist and a new one was used
- LWP_EBADROCK Rock already exists.
- LWP_ENOROCKS All rocks are in use.
-
- From the above semantics, you can only set a rock value once.
- This is specifically to prevent multiple users of the LWP
- package from accidentally using the same Tag value and
- clobbering others. You can always use one level of
- indirection to obtain a rock whose contents can change. */
+ Return codes:
+ LWP_SUCCESS Rock did not exist and a new one was used
+ LWP_EBADROCK Rock already exists.
+ LWP_ENOROCKS All rocks are in use.
+
+ From the above semantics, you can only set a rock value once.
+ This is specifically to prevent multiple users of the LWP
+ package from accidentally using the same Tag value and
+ clobbering others. You can always use one level of
+ indirection to obtain a rock whose contents can change. */
- register int i;
- register struct rock *ra; /* rock array */
+ int i;
+ struct rock *ra; /* rock array */
ra = lwp_cpptr->rlist;
@@ -367,11 +363,11 @@ LWP_NewRock(int Tag, char *Value)
#ifdef HAVE_PTHREAD_KEYCREATE
if (pthread_keycreate(&ra[lwp_cpptr->rused].val, NULL))
#else
- if (pthread_key_create(&ra[lwp_cpptr->rused].val, NULL))
+ if (pthread_key_create(&ra[lwp_cpptr->rused].val, NULL))
#endif
- return(LWP_EBADROCK);
+ return(LWP_EBADROCK);
if (pthread_setspecific(ra[lwp_cpptr->rused].val, Value))
- return(LWP_EBADROCK);
+ return(LWP_EBADROCK);
#elif defined(WINDOWS_THREADS_LWP)
ra[lwp_cpptr->rused].val = (LPVOID) TlsAlloc();
@@ -391,9 +387,9 @@ static void
Dispose_of_Dead_PCB(PROCESS cur)
{
- Debug(0, ("Entered Dispose_of_Dead_PCB"));
- Delete_PCB(cur);
- Free_PCB(cur);
+ Debug(0, ("Entered Dispose_of_Dead_PCB"));
+ Delete_PCB(cur);
+ Free_PCB(cur);
}
int
@@ -401,8 +397,8 @@ LWP_CurrentProcess(PROCESS *pid)
{
Debug(0, ("Entered Current_Process"));
if (lwp_init) {
- *pid = lwp_cpptr;
- return LWP_SUCCESS;
+ *pid = lwp_cpptr;
+ return LWP_SUCCESS;
} else
return LWP_EINIT;
}
@@ -432,7 +428,7 @@ LWP_WaitProcess(void *event)
}
static void
-Delete_PCB(register PROCESS pid)
+Delete_PCB(PROCESS pid)
{
Debug(0, ("Entered Delete_PCB"));
lwpremove(pid, (pid->blockflag || pid->status==WAITING ||
@@ -444,7 +440,7 @@ static void
purge_dead_pcbs()
{
for_all_elts(cur, blocked, { if (cur->status == DESTROYED)
- Dispose_of_Dead_PCB(cur); })
+ Dispose_of_Dead_PCB(cur); });
}
static void
@@ -457,15 +453,16 @@ static void
Dump_Processes()
{
if (lwp_init) {
- register int i;
+ int i;
for (i=0; i<MAX_PRIORITIES; i++)
for_all_elts(x, runnable[i], {
printf("[Priority %d]\n", i);
Dump_One_Process(x);
- })
- for_all_elts(x, blocked, { Dump_One_Process(x); })
- } else
+ });
+ for_all_elts(x, blocked, { Dump_One_Process(x); });
+ } else {
printf("***LWP: LWP support not initialized\n");
+ }
}
char *
@@ -495,7 +492,7 @@ LWP_QWait()
{
PROCESS old_cpptr;
- Debug(0, ("LWP_QWait: %s is going to QWait\n", lwp_cpptr->name));
+ Debug(0, ("LWP_QWait: %s is going to QWait", lwp_cpptr->name));
lwp_cpptr->status = QWAITING;
if (runnable[lwp_cpptr->priority].count == 0)
Cal_Highest_runnable_priority();
@@ -507,23 +504,23 @@ LWP_QWait()
lwpremove(lwp_cpptr, &runnable[Highest_runnable_priority]);
lwp_timerclear(&lwp_cpptr->lastReady);
LWP_INT_LOCK(&ct_mutex);
- Debug(0, ("LWP_QWait:%s going to wake up %s \n", old_cpptr->name,
+ Debug(0, ("LWP_QWait:%s going to wake up %s", old_cpptr->name,
lwp_cpptr->name));
LWP_INT_SIGNAL(&lwp_cpptr->c);
/* sleep on your own condition */
- Debug(0, ("LWP_QWait:%s going to wait on own condition \n",
+ Debug(0, ("LWP_QWait:%s going to wait on own condition",
old_cpptr->name));
LWP_INT_WAIT(&old_cpptr->c, &ct_mutex);
LWP_INT_UNLOCK(&ct_mutex);
- Debug(0, ("LWP_QWait:%s woke up \n",
+ Debug(0, ("LWP_QWait:%s woke up",
old_cpptr->name));
lwp_cpptr = old_cpptr;
/* return only if calling process' priority is the highest */
if (lwp_cpptr->priority < Highest_runnable_priority)
- Dispatcher();
+ Dispatcher();
return LWP_SUCCESS;
}
@@ -533,19 +530,19 @@ int
LWP_QSignal(PROCESS pid)
{
if (pid->status == QWAITING) {
- Debug(0, ("LWP_Qsignal: %s is going to QSignal %s\n", lwp_cpptr->name,
- pid->name));
- pid->status = READY;
- lwpinsert(pid, &runnable[pid->priority]);
- Debug(0, ("LWP_QSignal: Just inserted %s into runnable queue\n",
- pid->name));
- gettimeofday(&pid->lastReady, 0);
- Highest_runnable_priority =
- MAX(Highest_runnable_priority, pid->priority);
- Debug(0, ("%s priority= %d; HRP = %d; Signalled process pri = %d",
- lwp_cpptr->name, lwp_cpptr->priority,
- Highest_runnable_priority, pid->priority));
- return LWP_SUCCESS;
+ Debug(0, ("LWP_Qsignal: %s is going to QSignal %s\n", lwp_cpptr->name,
+ pid->name));
+ pid->status = READY;
+ lwpinsert(pid, &runnable[pid->priority]);
+ Debug(0, ("LWP_QSignal: Just inserted %s into runnable queue\n",
+ pid->name));
+ gettimeofday(&pid->lastReady, 0);
+ Highest_runnable_priority =
+ MAX(Highest_runnable_priority, pid->priority);
+ Debug(0, ("%s priority= %d; HRP = %d; Signalled process pri = %d",
+ lwp_cpptr->name, lwp_cpptr->priority,
+ Highest_runnable_priority, pid->priority));
+ return LWP_SUCCESS;
}
else return LWP_ENOWAIT;
}
@@ -564,231 +561,234 @@ LWP_CreateProcess(void (*ep)(), int stacksize, int priority,
HANDLE ct;
#endif
PROCESS old_cpptr;
-
+
Debug(0, ("Entered LWP_CreateProcess to create %s at priority %d\n",
name, priority));
old_cpptr = lwp_cpptr;
/* Throw away all dead process control blocks */
purge_dead_pcbs();
+
+ if (lwp_init == NULL)
+ return LWP_EINIT;
- if (lwp_init) {
- /* allocate the memory for the pcb - check for malloc errors */
- temp = (PROCESS)malloc (sizeof (struct lwp_pcb));
- if (temp == NULL) {
+ /* allocate the memory for the pcb - check for malloc errors */
+ temp = (PROCESS)malloc (sizeof (struct lwp_pcb));
+ if (temp == NULL) {
Dispatcher();
return LWP_ENOMEM;
- }
-
- /* check priorities */
- if (priority < 0 || priority >= MAX_PRIORITIES) {
+ }
+
+ /* check priorities */
+ if (priority < 0 || priority >= MAX_PRIORITIES) {
Dispatcher();
return LWP_EBADPRI;
- }
-
- Initialize_PCB(temp, priority, NULL, 0, ep, parm, name);
-
- /* make the process runnable by placing it in the runnable q */
- lwpinsert(temp, &runnable[priority]);
- gettimeofday(&temp->lastReady, 0);
-
- if (PRE_Block != 0) Abort_LWP("PRE_Block not 0");
-
- PRE_Block = 1;
- Proc_Running = FALSE; /* sem set true by forked process */
-
+ }
+
+ Initialize_PCB(temp, priority, NULL, 0, ep, parm, name);
+
+ /* make the process runnable by placing it in the runnable q */
+ lwpinsert(temp, &runnable[priority]);
+ gettimeofday(&temp->lastReady, 0);
+
+ if (PRE_Block != 0)
+ Abort_LWP("PRE_Block not 0");
+
+ PRE_Block = 1;
+ Proc_Running = FALSE; /* sem set true by forked process */
+
#if defined(PTHREADS_LWP)
- pthread_attr_init(&cta);
+ pthread_attr_init(&cta);
#ifdef _POSIX_THREAD_ATTR_STACKSIZE
- pthread_attr_setstacksize(&cta, stacksize);
+ pthread_attr_setstacksize(&cta, stacksize);
#endif
- retval = pthread_create(&ct, &cta, (void *)Create_Process_Part2, temp);
- if (!retval) {
- pthread_detach(ct);
- temp->a = cta;
+ retval = pthread_create(&ct, &cta, (void *)Create_Process_Part2, temp);
+ if (retval != 0)
+ Abort_LWP("pthread_create failed to create thread %d/%d",
+ retval, errno);
+
+ pthread_detach(ct);
+ temp->a = cta;
#elif defined(WINDOWS_THREADS_LWP)
- Debug(0,("Before CreateThread Create_Process_Part2"));
- ct = CreateThread (NULL,
- stacksize, (LPTHREAD_START_ROUTINE) Create_Process_Part2,
- temp, 0, NULL);
- Debug(0,("After CreateThread Create_Process_Part2"));
- if (ct != NULL) {
- temp->t = ct;
+ Debug(0,("Before CreateThread Create_Process_Part2"));
+ ct = CreateThread (NULL,
+ stacksize, (LPTHREAD_START_ROUTINE)Create_Process_Part2,
+ temp, 0, NULL);
+ Debug(0,("After CreateThread Create_Process_Part2"));
+ if (ct == NULL)
+ Abort_LWP("CreateThread failed to create thread: %d",
+ (int)GetLastError());
+ temp->t = ct;
#endif
- /* check if max priority has changed */
- Highest_runnable_priority = MAX(Highest_runnable_priority, priority);
-
- LWP_INT_LOCK(&run_sem);
- Debug(0, ("Before creating process yields Proc_Running = %d\n",
- Proc_Running));
- while( !Proc_Running ){
- LWP_INT_UNLOCK(&run_sem);
+ /* check if max priority has changed */
+ Highest_runnable_priority = MAX(Highest_runnable_priority, priority);
+
+ LWP_INT_LOCK(&run_sem);
+ Debug(0, ("Before creating process yields Proc_Running = %d\n",
+ Proc_Running));
+ while( !Proc_Running ){
+ LWP_INT_UNLOCK(&run_sem);
#if defined(PTHREADS_LWP)
#if defined(HAVE_THR_YIELD)
- thr_yield();
+ thr_yield();
#elif defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
- sched_yield();
+ sched_yield();
#else
- pthread_yield();
+ pthread_yield();
#endif
#elif defined(WINDOWS_THREADS_LWP)
- Sleep(0); /* XXX */
-#endif
- LWP_INT_LOCK(&run_sem);
- Debug(0,("After creating proc yields and gets back control Proc_Running = %d\n",
- Proc_Running));
- }
- LWP_INT_UNLOCK(&run_sem);
-
- lwp_cpptr = old_cpptr;
-
- Dispatcher();
- *pid = temp;
- return LWP_SUCCESS;
- }
- } else {
-#ifdef PTHREADS_LWP
- pthread_attr_destroy(&cta);
+ Sleep(0); /* XXX */
#endif
+ LWP_INT_LOCK(&run_sem);
+ Debug(0,("After creating proc yields and gets back control Proc_Running = %d\n",
+ Proc_Running));
}
- return LWP_EINIT;
+ LWP_INT_UNLOCK(&run_sem);
+
+ lwp_cpptr = old_cpptr;
+
+ Dispatcher();
+ *pid = temp;
+ return LWP_SUCCESS;
}
int
LWP_DestroyProcess(PROCESS pid)
{
- void *t;
+ void *t;
- Debug(0, ("Entered Destroy_Process"));
- if (lwp_init) {
+ Debug(0, ("Entered Destroy_Process"));
+ if (lwp_init) {
#if defined(PTHREADS_LWP)
- pthread_attr_destroy(&pid->a);
+ pthread_attr_destroy(&pid->a);
#elif defined(WINDOWS_THREADS_LWP)
- CloseHandle (pid->t);
+ CloseHandle (pid->t);
#endif
- if (lwp_cpptr == pid){
- /* kill myself */
- pid->status = DESTROYED;
- Free_PCB(pid);
- Cal_Highest_runnable_priority();
+ if (lwp_cpptr == pid){
+ /* kill myself */
+ pid->status = DESTROYED;
+ Free_PCB(pid);
+ Cal_Highest_runnable_priority();
- /* Calculate next runnable lwp and signal it */
- lwp_cpptr = runnable[Highest_runnable_priority].head;
- lwpremove(lwp_cpptr, &runnable[Highest_runnable_priority]);
+ /* Calculate next runnable lwp and signal it */
+ lwp_cpptr = runnable[Highest_runnable_priority].head;
+ lwpremove(lwp_cpptr, &runnable[Highest_runnable_priority]);
- LWP_INT_LOCK(&ct_mutex);
- LWP_INT_SIGNAL(&lwp_cpptr->c);
- LWP_INT_UNLOCK(&ct_mutex);
- LWP_INT_EXIT(t);
- } else {
- /* kill some other process - mark status destroyed -
- if process is blocked, it will be purged on next create proc;
- if it is runnable the dispatcher will kill it */
- pid->status = DESTROYED ;
- Dispatcher();
- }
- return LWP_SUCCESS ;
- } else
- return LWP_EINIT;
+ LWP_INT_LOCK(&ct_mutex);
+ LWP_INT_SIGNAL(&lwp_cpptr->c);
+ LWP_INT_UNLOCK(&ct_mutex);
+ LWP_INT_EXIT(t);
+ } else {
+ /* kill some other process - mark status destroyed -
+ if process is blocked, it will be purged on next create proc;
+ if it is runnable the dispatcher will kill it */
+ pid->status = DESTROYED ;
+ Dispatcher();
+ }
+ return LWP_SUCCESS ;
+ } else
+ return LWP_EINIT;
}
int
LWP_DispatchProcess() /* explicit voluntary preemption */
{
- Debug(0, ("Entered Dispatch_Process"))
+ Debug(0, ("Entered Dispatch_Process"));
if (lwp_init) {
Dispatcher();
return LWP_SUCCESS;
- } else
+ } else {
return LWP_EINIT;
+ }
}
int
LWP_Init(int version, int priority, PROCESS *pid)
{
- lwp_debug = 0;
- if (version != LWP_VERSION)
+ lwp_debug = 0;
+ if (version != LWP_VERSION)
{
- fprintf(stderr, "**** FATAL ERROR: LWP VERSION MISMATCH ****\n");
- exit(-1);
+ fprintf(stderr, "**** FATAL ERROR: LWP VERSION MISMATCH ****\n");
+ exit(-1);
}
- else return(InitializeProcessSupport(priority, pid));
+ else return(InitializeProcessSupport(priority, pid));
}
int
LWP_InitializeProcessSupport(int priority, PROCESS *pid)
{
- return(InitializeProcessSupport(priority, pid));
+ return(InitializeProcessSupport(priority, pid));
}
static int
InitializeProcessSupport(int priority, PROCESS *pid)
{
- PROCESS temp;
- register int i;
+ PROCESS temp;
+ int i;
- Debug(0, ("Entered InitializeProcessSupport"));
- if (lwp_init != NULL) return LWP_SUCCESS;
+ Debug(0, ("Entered InitializeProcessSupport"));
+ if (lwp_init != NULL)
+ return LWP_SUCCESS;
- /* check priorities and set up running and blocked queues */
- if (priority >= MAX_PRIORITIES) return LWP_EBADPRI;
- for (i=0; i<MAX_PRIORITIES; i++) {
- runnable[i].head = NULL;
- runnable[i].count = 0;
- }
- blocked.head = NULL;
- blocked.count = 0;
- lwp_init = (struct lwp_ctl *) malloc(sizeof(struct lwp_ctl));
- temp = (PROCESS) malloc(sizeof(struct lwp_pcb));
- if (lwp_init == NULL || temp == NULL)
- Abort_LWP("Insufficient Storage to Initialize LWP Support");
+ /* check priorities and set up running and blocked queues */
+ if (priority >= MAX_PRIORITIES) return LWP_EBADPRI;
+ for (i=0; i<MAX_PRIORITIES; i++) {
+ runnable[i].head = NULL;
+ runnable[i].count = 0;
+ }
+ blocked.head = NULL;
+ blocked.count = 0;
+ lwp_init = (struct lwp_ctl *) malloc(sizeof(struct lwp_ctl));
+ temp = (PROCESS) malloc(sizeof(struct lwp_pcb));
+ if (lwp_init == NULL || temp == NULL)
+ Abort_LWP("Insufficient Storage to Initialize LWP Support");
- /* check parameters */
- Initialize_PCB(temp, priority, NULL, 0, NULL, NULL,"Main Process");
- gettimeofday(&temp->lastReady, 0);
+ /* check parameters */
+ Initialize_PCB(temp, priority, NULL, 0, NULL, NULL,"Main Process");
+ gettimeofday(&temp->lastReady, 0);
#if 0
- Highest_runnable_priority = priority;
+ Highest_runnable_priority = priority;
#endif
- /* initialize mutex and semaphore */
- Proc_Running = TRUE;
+ /* initialize mutex and semaphore */
+ Proc_Running = TRUE;
#if defined(PTHREADS_LWP)
- pthread_mutex_init(&run_sem, NULL);
- pthread_mutex_init(&ct_mutex, NULL);
+ pthread_mutex_init(&run_sem, NULL);
+ pthread_mutex_init(&ct_mutex, NULL);
#elif defined(WINDOWS_THREADS_LWP)
- run_sem = CreateMutex (NULL, FALSE, "run_sem");
- if (run_sem == NULL) abort();
- ct_mutex = CreateMutex (NULL, FALSE, "ct_mutex");
- if (ct_mutex == NULL) abort();
+ run_sem = CreateMutex (NULL, FALSE, "run_sem");
+ if (run_sem == NULL) abort();
+ ct_mutex = CreateMutex (NULL, FALSE, "ct_mutex");
+ if (ct_mutex == NULL) abort();
#endif
- lwp_cpptr = temp;
- Dispatcher();
- *pid = temp;
- return LWP_SUCCESS;
+ lwp_cpptr = temp;
+ Dispatcher();
+ *pid = temp;
+ return LWP_SUCCESS;
}
int
LWP_INTERNALSIGNAL(void *event, int yield)
{
- Debug(0, ("Entered LWP_SignalProcess, yield=%d", yield));
- if (lwp_init) {
- int rc;
- rc = Internal_Signal(event);
- if (yield) {
- Cal_Highest_runnable_priority();
- Debug(0, ("hipri=%d", Highest_runnable_priority));
- Dispatcher();
- }
- return rc;
- } else
- return LWP_EINIT;
+ Debug(0, ("Entered LWP_SignalProcess, yield=%d", yield));
+ if (lwp_init) {
+ int rc;
+ rc = Internal_Signal(event);
+ if (yield) {
+ Cal_Highest_runnable_priority();
+ Debug(0, ("hipri=%d", Highest_runnable_priority));
+ Dispatcher();
+ }
+ return rc;
+ } else
+ return LWP_EINIT;
}
int
LWP_MwaitProcess(int wcount, char *evlist[]) /* wait on m of n events */
{
- register int ecount, i;
+ int ecount, i;
PROCESS old_cpptr;
Debug(0, ("Entered Mwait_Process [waitcnt = %d]", wcount));
@@ -814,8 +814,8 @@ LWP_MwaitProcess(int wcount, char *evlist[]) /* wait on m of n events */
/* reallocate eventlist if new list has more elements than before */
if (ecount > lwp_cpptr->eventlistsize) {
lwp_cpptr->eventlist =
- (char **)realloc((char *)lwp_cpptr->eventlist,
- ecount*sizeof(char *));
+ (char **)realloc((char *)lwp_cpptr->eventlist,
+ ecount*sizeof(char *));
lwp_cpptr->eventlistsize = ecount;
}
@@ -832,7 +832,7 @@ LWP_MwaitProcess(int wcount, char *evlist[]) /* wait on m of n events */
lwp_cpptr -> waitcnt = wcount;
lwp_cpptr -> eventcnt = ecount;
if (runnable[lwp_cpptr->priority].count == 0)
- Cal_Highest_runnable_priority();
+ Cal_Highest_runnable_priority();
old_cpptr = lwp_cpptr;
/* wake up next lwp */
@@ -845,11 +845,11 @@ LWP_MwaitProcess(int wcount, char *evlist[]) /* wait on m of n events */
LWP_INT_SIGNAL(&lwp_cpptr->c);
/* sleep on your own condition */
- Debug(0, ("WaitProcess:%s going to wait \n", old_cpptr->name))
+ Debug(0, ("WaitProcess:%s going to wait \n", old_cpptr->name));
LWP_INT_WAIT(&old_cpptr->c, &ct_mutex);
LWP_INT_UNLOCK(&ct_mutex);
- Debug(0, ("WaitProcess:%s woke up \n", old_cpptr->name))
+ Debug(0, ("WaitProcess:%s woke up \n", old_cpptr->name));
/* update the global pointer */
lwp_cpptr = old_cpptr;
@@ -872,10 +872,15 @@ LWP_StackUsed(PROCESS pid, int *max, int *used)
}
static void
-Abort_LWP(char *msg)
+Abort_LWP(char *msg, ...)
{
+ va_list ap;
+
Debug(0, ("Entered Abort_LWP"));
- printf("***LWP Abort: %s\n", msg);
+ va_start(ap, msg);
+ printf("***LWP Abort ");
+ vprintf(msg, ap);
+ va_end(ap);
Dump_Processes();
Exit_LWP();
}
@@ -886,9 +891,12 @@ Create_Process_Part2(PROCESS temp)
/* set the global Proc_Running to signal the parent */
LWP_INT_LOCK(&run_sem);
Proc_Running = TRUE;
- LWP_INT_WAIT(&temp->c, &run_sem);
LWP_INT_UNLOCK(&run_sem);
+ LWP_INT_LOCK(&ct_mutex);
+ LWP_INT_WAIT(&temp->c, &ct_mutex);
+ LWP_INT_UNLOCK(&ct_mutex);
+
lwp_cpptr = temp;
#if defined(PTHREADS_LWP)
@@ -912,14 +920,14 @@ Dump_One_Process(PROCESS pid)
printf("***LWP: Initial entry point: 0x%x\n", (int)pid->ep);
if (pid->blockflag) printf("BLOCKED and ");
switch (pid->status) {
- case READY: printf("READY"); break;
- case WAITING: printf("WAITING"); break;
- case DESTROYED: printf("DESTROYED"); break;
- default: printf("unknown");
- }
+ case READY: printf("READY"); break;
+ case WAITING: printf("WAITING"); break;
+ case DESTROYED: printf("DESTROYED"); break;
+ default: printf("unknown");
+ }
putchar('\n');
printf("***LWP: Priority: %d \tInitial parameter: 0x%x\n",
- pid->priority, (int)pid->parm);
+ pid->priority, (int)pid->parm);
if (pid->eventcnt > 0) {
printf("***LWP: Number of events outstanding: %d\n", pid->waitcnt);
@@ -935,86 +943,87 @@ Dump_One_Process(PROCESS pid)
static void
Dispatcher() /* Lightweight process dispatcher */
{
- void *t;
- int my_priority;
- PROCESS old_cpptr;
+ void *t;
+ int my_priority;
+ PROCESS old_cpptr;
#if 1
- int i = Highest_runnable_priority;
+ int i = Highest_runnable_priority;
- Cal_Highest_runnable_priority();
- if (Highest_runnable_priority != i) {
- printf("hipri was %d actually %d\n", i, Highest_runnable_priority);
+ Cal_Highest_runnable_priority();
+ if (Highest_runnable_priority != i) {
+ printf("hipri was %d actually %d\n", i, Highest_runnable_priority);
#if 0
- Dump_Processes();
+ Dump_Processes();
#endif
- }
- Highest_runnable_priority = i;
+ }
+ Highest_runnable_priority = i;
#endif
- my_priority = lwp_cpptr->priority;
- Debug(0, ("Dispatcher: %d runnable at pri %d hi %d blk %d",
- runnable[my_priority].count, my_priority,
- Highest_runnable_priority, PRE_Block));
- PRE_Block = 1;
- if ((my_priority < Highest_runnable_priority) ||
- (runnable[my_priority].count > 0))
- {
- Debug(0, ("Dispatcher: %s is now yielding", lwp_cpptr->name));
- /* I have to quit */
- old_cpptr = lwp_cpptr;
- lwpinsert(old_cpptr, &runnable[my_priority]);
- gettimeofday(&old_cpptr->lastReady, 0);
- lwp_cpptr = runnable[Highest_runnable_priority].head;
+ my_priority = lwp_cpptr->priority;
+ Debug(0, ("Dispatcher: %d runnable at pri %d hi %d blk %d",
+ runnable[my_priority].count, my_priority,
+ Highest_runnable_priority, PRE_Block));
+ PRE_Block = 1;
+ if ((my_priority < Highest_runnable_priority) ||
+ (runnable[my_priority].count > 0))
+ {
+ Debug(0, ("Dispatcher: %s is now yielding", lwp_cpptr->name));
+ /* I have to quit */
+ old_cpptr = lwp_cpptr;
+ lwpinsert(old_cpptr, &runnable[my_priority]);
+ gettimeofday(&old_cpptr->lastReady, 0);
+ lwp_cpptr = runnable[Highest_runnable_priority].head;
+
+ /* remove next process from runnable queue and signal it */
+ lwpremove(lwp_cpptr, &runnable[Highest_runnable_priority]);
+ LWP_INT_LOCK(&ct_mutex);
+ Debug(0, ("Dispatcher: %s going to signal %s condition",
+ old_cpptr->name, lwp_cpptr->name));
- /* remove next process from runnable queue and signal it */
- lwpremove(lwp_cpptr, &runnable[Highest_runnable_priority]);
- LWP_INT_LOCK(&ct_mutex);
- Debug(0, ("Dispatcher: %s going to signal %s condition\n",
- old_cpptr->name, lwp_cpptr->name))
+ LWP_INT_SIGNAL(&lwp_cpptr->c);
- LWP_INT_SIGNAL(&lwp_cpptr->c);
-
- /* now sleep until somebody wakes me */
- Debug(0, ("Dispatcher: %s going to wait on own condition\n",
- old_cpptr->name))
- LWP_INT_WAIT(&old_cpptr->c, &ct_mutex);
- LWP_INT_UNLOCK(&ct_mutex);
- Debug(0, ("Dispatcher: %s woke up\n",
- old_cpptr->name))
+ /* now sleep until somebody wakes me */
+ Debug(0, ("Dispatcher: %s going to wait on own condition",
+ old_cpptr->name));
+ LWP_INT_WAIT(&old_cpptr->c, &ct_mutex);
+ LWP_INT_UNLOCK(&ct_mutex);
+ Debug(0, ("Dispatcher: %s woke up",
+ old_cpptr->name));
+
+ /* update global pointer */
+ lwp_cpptr = old_cpptr;
+ } else {
+ Debug(0, ("Dispatcher: %s still running", lwp_cpptr->name));
+ }
+ /* make sure HRP is set correct */
+ Highest_runnable_priority = lwp_cpptr->priority;
+ if (lwp_cpptr->status == DESTROYED){
+ /* the process was runnable but got destroyed by somebody */
+ Free_PCB(lwp_cpptr);
+ Cal_Highest_runnable_priority();
+ lwp_cpptr = runnable[Highest_runnable_priority].head;
+ lwpremove(lwp_cpptr, &runnable[Highest_runnable_priority]);
- /* update global pointer */
- lwp_cpptr = old_cpptr;
- } else {
- Debug(0, ("Dispatcher: %s still running", lwp_cpptr->name))
- }
- /* make sure HRP is set correct */
- Highest_runnable_priority = lwp_cpptr->priority;
- if (lwp_cpptr->status == DESTROYED){
- /* the process was runnable but got destroyed by somebody */
- Free_PCB(lwp_cpptr);
- Cal_Highest_runnable_priority();
- lwp_cpptr = runnable[Highest_runnable_priority].head;
- lwpremove(lwp_cpptr, &runnable[Highest_runnable_priority]);
-
- LWP_INT_LOCK(&ct_mutex);
- LWP_INT_SIGNAL(&lwp_cpptr->c);
- LWP_INT_UNLOCK(&ct_mutex);
- LWP_INT_EXIT(t);
- }
+ LWP_INT_LOCK(&ct_mutex);
+ LWP_INT_SIGNAL(&lwp_cpptr->c);
+ LWP_INT_UNLOCK(&ct_mutex);
+ LWP_INT_EXIT(t);
+ }
#if 0
- if (PRE_Block != 1) Abort_LWP("PRE_Block not 1");
+ if (PRE_Block != 1) Abort_LWP("PRE_Block not 1");
#endif
- PRE_Block = 0;
+ PRE_Block = 0;
}
static void
Free_PCB(PROCESS pid)
{
- Debug(0, ("Entered Free_PCB"))
+ Debug(0, ("Entered Free_PCB"));
- if (pid->eventlist != NULL) free((char *)pid->eventlist);
+ if (pid->eventlist != NULL)
+ free((char *)pid->eventlist);
free((char *)pid);
}
@@ -1022,11 +1031,12 @@ static void
Initialize_PCB(PROCESS temp, int priority, char *stack, int stacksize,
void (*ep)(), char *parm, char *name)
{
- register int i = 0;
+ int i = 0;
- Debug(0, ("Entered Initialize_PCB"))
+ Debug(0, ("Entered Initialize_PCB"));
if (name != NULL)
- while (((temp -> name[i] = name[i]) != '\0') && (i < 31)) i++;
+ while (((temp -> name[i] = name[i]) != '\0') && (i < 31))
+ i++;
temp -> name[31] = '\0';
temp -> status = READY;
temp -> eventlist = (char **)malloc(EVINITSIZE*sizeof(char *));
@@ -1045,6 +1055,7 @@ Initialize_PCB(PROCESS temp, int priority, char *stack, int stacksize,
temp -> prev = NULL;
temp -> rused = 0;
temp -> level = 1; /* non-preemptable */
+ temp -> stacksize = stacksize;
lwp_timerclear(&temp->lastReady);
/* initialize the mutex and condition */
@@ -1059,42 +1070,47 @@ Initialize_PCB(PROCESS temp, int priority, char *stack, int stacksize,
Debug(0, ("Init_PCB: event = %p\n", temp->c));
#endif
-
- Debug(0, ("Leaving Initialize_PCB\n"))
+ Debug(0, ("Leaving Initialize_PCB\n"));
}
static int
-Internal_Signal(register char *event)
+Internal_Signal(char *event)
{
- int rc = LWP_ENOWAIT;
- register int i;
+ int rc = LWP_ENOWAIT;
+ int i;
- Debug(0, ("Entered Internal_Signal [event id 0x%x]", (int)event));
- if (!lwp_init) return LWP_EINIT;
- if (event == NULL) return LWP_EBADEVENT;
+ Debug(0, ("Entered Internal_Signal [event id 0x%x]", (int)event));
+ if (lwp_init == NULL)
+ return LWP_EINIT;
+ if (event == NULL)
+ return LWP_EBADEVENT;
- for_all_elts(temp, blocked, { /* for all pcb's on the blocked q */
- if (temp->status == WAITING)
- for (i=0; i < temp->eventcnt; i++) { /* check each event in list */
- if (temp -> eventlist[i] == event) {
- temp -> eventlist[i] = NULL;
- rc = LWP_SUCCESS;
- Debug(0, ("decrementing %s to %d", temp->name, (temp->waitcnt-1)));
- /* reduce waitcnt by 1 for the signal */
- /* if wcount reaches 0 then make the process runnable */
- if (--temp->waitcnt == 0) {
- temp -> status = READY;
- temp -> wakevent = i+1;
- lwpmove(temp, &blocked, &runnable[temp->priority]);
- gettimeofday(&temp->lastReady, 0);
- Highest_runnable_priority =
- MAX(Highest_runnable_priority, temp->priority);
- Debug(0, ("marked runnable. hi_pri %d, %d at %d", Highest_runnable_priority, runnable[temp->priority].count, temp->priority));
- break;
- }
- }
- }
- })
+ for_all_elts(temp, blocked, { /* for all pcb's on the blocked q */
+ if (temp->status == WAITING)
+ for (i=0; i < temp->eventcnt; i++) { /* check each event in list */
+ if (temp -> eventlist[i] == event) {
+ temp -> eventlist[i] = NULL;
+ rc = LWP_SUCCESS;
+ Debug(0, ("decrementing %s to %d", temp->name,
+ (temp->waitcnt-1)));
+ /* reduce waitcnt by 1 for the signal */
+ /* if wcount reaches 0 then make the process runnable */
+ if (--temp->waitcnt == 0) {
+ temp -> status = READY;
+ temp -> wakevent = i+1;
+ lwpmove(temp, &blocked, &runnable[temp->priority]);
+ gettimeofday(&temp->lastReady, 0);
+ Highest_runnable_priority =
+ MAX(Highest_runnable_priority, temp->priority);
+ Debug(0, ("marked runnable. hi_pri %d, %d at %d",
+ Highest_runnable_priority,
+ runnable[temp->priority].count,
+ temp->priority));
+ break;
+ }
+ }
+ }
+ });
return rc;
}
@@ -1104,17 +1120,22 @@ static void
Cal_Highest_runnable_priority()
{
int i;
+
#if 0
Dump_Processes();
#endif
- for (i = LWP_MAX_PRIORITY; runnable[i].count == 0 && i >=0; i--);
+
+ for (i = MAX_PRIORITIES - 1; i >= 0 ; i--)
+ if (runnable[i].count != 0)
+ break;
#if 0
if (i < 0)
- Abort_LWP("No ready processes");
- else
- Highest_runnable_priority = i;
-#else
+ Abort_LWP("No ready processes");
+#endif
if (i >= 0)
- Highest_runnable_priority = i;
+ Highest_runnable_priority = i;
+#if 0
+ else
+ abort();
#endif
}
diff --git a/usr.sbin/afs/src/lwp/plwp.h b/usr.sbin/afs/src/lwp/plwp.h
index ad40a93e72e..39b6370de8d 100644
--- a/usr.sbin/afs/src/lwp/plwp.h
+++ b/usr.sbin/afs/src/lwp/plwp.h
@@ -1,5 +1,5 @@
/*
- * $KTH: plwp.h,v 1.5 2000/10/20 11:01:46 lha Exp $
+ * $arla: plwp.h,v 1.9 2003/01/03 16:26:08 tol Exp $
*/
#ifndef LWP_INCLUDED
@@ -9,10 +9,6 @@
#include <config.h>
#endif
-#ifdef WINDOWS_THREADS_LWP
-#include <windows.h>
-#endif
-
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -35,10 +31,14 @@
#include <roken.h>
+#ifdef WINDOWS_THREADS_LWP
+#include <windows.h>
+#endif
+
#ifndef LWP_KERNEL
extern
#endif
-char lwp_debug; /* ON = show LWP debugging trace */
+ int lwp_debug; /* ON = show LWP debugging trace */
extern int lwp_stackUseEnabled;
extern int lwp_MaxStackSeen;
@@ -116,7 +116,7 @@ int IOMGR_Initialize(void);
int IOMGR_Finalize(void);
long IOMGR_Poll(void);
int IOMGR_Select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
-int IOMGR_Cancel(register PROCESS);
+int IOMGR_Cancel(PROCESS);
int IOMGR_Signal(int, char *);
int IOMGR_CancelSignal(int);
void IOMGR_Sleep(unsigned int);
@@ -125,7 +125,7 @@ int FT_Init(int, int);
#if __GNUC__ >= 2
struct timezone;
#endif
-int FT_GetTimeOfDay(register struct timeval *, register struct timezone *);
+int FT_GetTimeOfDay(struct timeval *, struct timezone *);
int TM_GetTimeOfDay(struct timeval *, struct timezone *);
int FT_AGetTimeOfDay(struct timeval *, struct timezone *);
unsigned int FT_ApproxTime(void);
@@ -192,8 +192,6 @@ struct lwp_ctl { /* LWP control structure */
char dsptchstack[800]; /* stack for dispatcher use only */
};
-extern char PRE_Block; /* used in preemption control (in preempt.c) */
-
/* Debugging macro */
#ifdef LWPDEBUG
#define lwpdebug(level, msg)\
diff --git a/usr.sbin/afs/src/lwp/preempt.c b/usr.sbin/afs/src/lwp/preempt.c
index e712aa154b6..e618c88092d 100644
--- a/usr.sbin/afs/src/lwp/preempt.c
+++ b/usr.sbin/afs/src/lwp/preempt.c
@@ -32,7 +32,7 @@
#include <lwp.h>
#include "preempt.h"
-RCSID("$KTH: preempt.c,v 1.7 2000/02/20 04:15:37 assar Exp $");
+RCSID("$arla: preempt.c,v 1.9 2002/06/02 11:59:54 lha Exp $");
char PRE_Block = 0; /* used in lwp.c and process.s */
diff --git a/usr.sbin/afs/src/lwp/preempt.h b/usr.sbin/afs/src/lwp/preempt.h
index 606130cb50f..15dbdce0300 100644
--- a/usr.sbin/afs/src/lwp/preempt.h
+++ b/usr.sbin/afs/src/lwp/preempt.h
@@ -1,8 +1,8 @@
-/* $KTH: /afs/stacken.kth.se/src/SourceRepository/arla/lwp/preempt.h,v 1.2 1999/02/01 04:56:31 assar Exp $ */
-/* $KTH: /afs/stacken.kth.se/src/SourceRepository/arla/lwp/preempt.h,v $ */
+/* $arla: /afs/stacken.kth.se/src/SourceRepository/arla/lwp/preempt.h,v 1.3 2002/06/02 11:59:54 lha Exp $ */
+/* $arla: /afs/stacken.kth.se/src/SourceRepository/arla/lwp/preempt.h,v $ */
#if !defined(lint) && !defined(LOCORE) && defined(RCS_HDRS)
-static char *rcsidpreempt = "$KTH: /afs/stacken.kth.se/src/SourceRepository/arla/lwp/preempt.h,v 1.2 1999/02/01 04:56:31 assar Exp $";
+static char *rcsidpreempt = "$arla: /afs/stacken.kth.se/src/SourceRepository/arla/lwp/preempt.h,v 1.3 2002/06/02 11:59:54 lha Exp $";
#endif
/*
@@ -44,3 +44,5 @@ static char *rcsidpreempt = "$KTH: /afs/stacken.kth.se/src/SourceRepository/arla
int PRE_InitPreempt(struct timeval *);
int PRE_EndPreempt(void);
+extern char PRE_Block;
+
diff --git a/usr.sbin/afs/src/lwp/process-vpp.s b/usr.sbin/afs/src/lwp/process-vpp.s
index 0227b426cbe..25abcbc1000 100644
--- a/usr.sbin/afs/src/lwp/process-vpp.s
+++ b/usr.sbin/afs/src/lwp/process-vpp.s
@@ -37,7 +37,7 @@
* SUCH DAMAGE.
*/
-/* $KTH: process-vpp.s,v 1.1 1998/10/25 19:41:15 joda Exp $ */
+/* $arla: process-vpp.s,v 1.1 1998/10/25 19:41:15 joda Exp $ */
/* LWP context switch for Fujitsu UXP/V */
diff --git a/usr.sbin/afs/src/lwp/process.aix22.S b/usr.sbin/afs/src/lwp/process.aix22.S
index fb28724f3b7..d224105b934 100644
--- a/usr.sbin/afs/src/lwp/process.aix22.S
+++ b/usr.sbin/afs/src/lwp/process.aix22.S
@@ -1,4 +1,4 @@
-/* $KTH: process.aix22.S,v 1.1 2000/01/02 02:11:15 lha Exp $ */
+/* $arla: process.aix22.S,v 1.1 2000/01/02 02:11:15 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/process.alpha.S b/usr.sbin/afs/src/lwp/process.alpha.S
index 34eb4a4cec3..dc36d55f521 100644
--- a/usr.sbin/afs/src/lwp/process.alpha.S
+++ b/usr.sbin/afs/src/lwp/process.alpha.S
@@ -1,4 +1,4 @@
-/* $KTH: process.alpha.S,v 1.1 2000/01/02 02:11:15 lha Exp $ */
+/* $arla: process.alpha.S,v 1.1 2000/01/02 02:11:15 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/process.i386.S b/usr.sbin/afs/src/lwp/process.i386.S
index 4705911688b..3a519bc44ad 100644
--- a/usr.sbin/afs/src/lwp/process.i386.S
+++ b/usr.sbin/afs/src/lwp/process.i386.S
@@ -1,4 +1,4 @@
-/* $KTH: process.i386.S,v 1.1 2000/01/02 02:11:16 lha Exp $ */
+/* $arla: process.i386.S,v 1.1 2000/01/02 02:11:16 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/process.ibm032.S b/usr.sbin/afs/src/lwp/process.ibm032.S
index 2b776e6cf8d..65c9d8e461a 100644
--- a/usr.sbin/afs/src/lwp/process.ibm032.S
+++ b/usr.sbin/afs/src/lwp/process.ibm032.S
@@ -1,4 +1,4 @@
-/* $KTH: process.ibm032.S,v 1.1 2000/01/02 02:11:16 lha Exp $ */
+/* $arla: process.ibm032.S,v 1.1 2000/01/02 02:11:16 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/process.m68k.S b/usr.sbin/afs/src/lwp/process.m68k.S
index 23ed94ac56c..ecb11ce8e7f 100644
--- a/usr.sbin/afs/src/lwp/process.m68k.S
+++ b/usr.sbin/afs/src/lwp/process.m68k.S
@@ -1,4 +1,4 @@
-/* $KTH: process.m68k.S,v 1.7 2000/08/25 14:49:04 lha Exp $ */
+/* $arla: process.m68k.S,v 1.7 2000/08/25 14:49:04 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/process.mips.S b/usr.sbin/afs/src/lwp/process.mips.S
index dfaecd67462..1b1d28eecef 100644
--- a/usr.sbin/afs/src/lwp/process.mips.S
+++ b/usr.sbin/afs/src/lwp/process.mips.S
@@ -1,4 +1,4 @@
-/* $KTH: process.mips.S,v 1.1 2000/01/02 02:11:17 lha Exp $ */
+/* $arla: process.mips.S,v 1.1 2000/01/02 02:11:17 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/process.ppc.S b/usr.sbin/afs/src/lwp/process.ppc.S
index d4ee95d0d01..09aa40a1b7f 100644
--- a/usr.sbin/afs/src/lwp/process.ppc.S
+++ b/usr.sbin/afs/src/lwp/process.ppc.S
@@ -1,4 +1,4 @@
-/* $KTH: process.ppc.S,v 1.3 2000/10/14 11:12:37 lha Exp $ */
+/* $arla: process.ppc.S,v 1.3 2000/10/14 11:12:37 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/process.rios.S b/usr.sbin/afs/src/lwp/process.rios.S
index 8fc961b1d1f..6de6e70a849 100644
--- a/usr.sbin/afs/src/lwp/process.rios.S
+++ b/usr.sbin/afs/src/lwp/process.rios.S
@@ -1,4 +1,4 @@
-/* $KTH: process.rios.S,v 1.1 2000/01/02 02:11:19 lha Exp $ */
+/* $arla: process.rios.S,v 1.1 2000/01/02 02:11:19 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/process.sparc.S b/usr.sbin/afs/src/lwp/process.sparc.S
index 94675ea7e29..69242c9a334 100644
--- a/usr.sbin/afs/src/lwp/process.sparc.S
+++ b/usr.sbin/afs/src/lwp/process.sparc.S
@@ -1,4 +1,4 @@
-/* $KTH: process.sparc.S,v 1.2.4.1 2002/08/13 22:47:40 lha Exp $ */
+/* $arla: process.sparc.S,v 1.5 2002/06/24 22:40:02 lha Exp $ */
/*
****************************************************************************
@@ -114,11 +114,11 @@ globals = 8
/* These declarations are needed if you're running Solaris 7,
* and are compiling with -xarch=v9 and have an as from WorkShop
* Compilers 5.0 98/12/21 (or more recent). Hopefully,
- * AS_UNDERSTANDS_REGISTER will be set correctly by configure, if
- * that's not the case, edit here and send a bug report.
+ * PROG_AS_UNDERSTANDS_REGISTER will be set correctly by configure,
+ * if that's not the case, edit here and send a bug report.
*/
-#if AS_UNDERSTANDS_REGISTER
+#if PROG_AS_UNDERSTANDS_REGISTER
.register %g2, #scratch
.register %g3, #scratch
.register %g6, #scratch
diff --git a/usr.sbin/afs/src/lwp/process.vax.S b/usr.sbin/afs/src/lwp/process.vax.S
index e3745704141..ddf1808f7b9 100644
--- a/usr.sbin/afs/src/lwp/process.vax.S
+++ b/usr.sbin/afs/src/lwp/process.vax.S
@@ -1,4 +1,4 @@
-/* $KTH: process.vax.S,v 1.1 2000/01/02 02:11:20 lha Exp $ */
+/* $arla: process.vax.S,v 1.1 2000/01/02 02:11:20 lha Exp $ */
/*
****************************************************************************
diff --git a/usr.sbin/afs/src/lwp/q.c b/usr.sbin/afs/src/lwp/q.c
index 8336eac02fa..85fddea3cb3 100644
--- a/usr.sbin/afs/src/lwp/q.c
+++ b/usr.sbin/afs/src/lwp/q.c
@@ -11,7 +11,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
-RCSID("$KTH: q.c,v 1.8 1999/12/31 05:39:49 assar Exp $") ;
+RCSID("$arla: q.c,v 1.8 1999/12/31 05:39:49 assar Exp $") ;
#endif
#include <stdio.h>
diff --git a/usr.sbin/afs/src/lwp/q.h b/usr.sbin/afs/src/lwp/q.h
index ad89f49c4ed..81393657968 100644
--- a/usr.sbin/afs/src/lwp/q.h
+++ b/usr.sbin/afs/src/lwp/q.h
@@ -1,4 +1,4 @@
-/* $KTH: q.h,v 1.2 1998/02/12 01:03:32 assar Exp $ */
+/* $arla: q.h,v 1.2 1998/02/12 01:03:32 assar Exp $ */
void lwp_insque(void *, void *);
void lwp_remque(void *);
diff --git a/usr.sbin/afs/src/lwp/rw.c b/usr.sbin/afs/src/lwp/rw.c
index 63d318d5b37..2af5f8c35f0 100644
--- a/usr.sbin/afs/src/lwp/rw.c
+++ b/usr.sbin/afs/src/lwp/rw.c
@@ -94,17 +94,17 @@ queue *q;
int asleep; /* Number of processes sleeping -- used for
clean termination */
-static int read_process(int id)
+static void
+read_process(char *id)
{
- printf("\t[Reader %d]\n", id);
- LWP_NewRock(1, (char *)id);
+ printf("\t[Reader %d]\n", *(int *)id);
+ LWP_NewRock(1, id);
LWP_DispatchProcess(); /* Just relinquish control for now */
PRE_PreemptMe();
for (;;) {
int i;
char *tmp;
- int foo;
/* Wait until there is something in the queue */
asleep++;
@@ -118,8 +118,7 @@ static int read_process(int id)
for (i=0; i<10000; i++) ;
PRE_BeginCritical();
LWP_GetRock(1, &tmp);
- foo = (int)tmp;
- printf("[%d: %s]\n", foo, Remove(q));
+ printf("[%d: %s]\n", *(int *)tmp, Remove(q));
PRE_EndCritical();
ReleaseReadLock(&q->lock);
LWP_DispatchProcess();
@@ -203,6 +202,7 @@ main(int argc, char **argv)
int nreaders, i;
long interval; /* To satisfy Brad */
PROCESS *readers;
+ int *readersid;
PROCESS writer, master;
struct timeval tv;
char rname[9];
@@ -236,10 +236,13 @@ main(int argc, char **argv)
/* Now create readers */
printf("[Creating Readers...\n");
readers = (PROCESS *) calloc(nreaders, sizeof(PROCESS));
+ readersid = (int *) calloc(nreaders, sizeof(int));
for (i=0; i<nreaders; i++) {
snprintf(rname, sizeof(rname), "Reader %d", i);
- LWP_CreateProcess((void (*)())(read_process),
- STACK_SIZE, 0, (char *)i, rname, &readers[i]);
+ readersid[i] = i;
+ LWP_CreateProcess(read_process,
+ STACK_SIZE, 0, (char *)&readersid[i],
+ rname, &readers[i]);
}
printf("done]\n");
diff --git a/usr.sbin/afs/src/lwp/testlwp.c b/usr.sbin/afs/src/lwp/testlwp.c
index 5c3115c9f63..22a9d14883a 100644
--- a/usr.sbin/afs/src/lwp/testlwp.c
+++ b/usr.sbin/afs/src/lwp/testlwp.c
@@ -38,7 +38,7 @@
* multiple commands on the command line to run several tests at the
* same time.
*
- * $KTH: testlwp.c,v 1.8 2000/10/20 17:10:38 lha Exp $
+ * $arla: testlwp.c,v 1.9 2002/06/01 17:47:49 lha Exp $
*
*/
@@ -54,7 +54,11 @@
static void Producer(void *foo) ;
static void Consumer(void *foo) ;
+#ifndef AFS_LWP_MINSTACKSIZE
#define LWPTEST_STACKSIZE (16*1024)
+#else
+#define LWPTEST_STACKSIZE AFS_LWP_MINSTACKSIZE
+#endif
/*
* Classic Producer Consumer thread testing
@@ -274,6 +278,49 @@ deadlock_read2 (void)
ObtainWriteLock(&lock);
}
+/*
+ * the terms overrun and underrun stack are used somewhat wrong here,
+ * in what direction do your stack grow
+ */
+
+/*
+ * when testing if the stack thingy work, it might not be so smart to
+ * use the stack (automatic variables) for storage :)
+ */
+
+int stack_i, stack_printed = 0;
+
+static void
+overrun_stack (void *arg)
+{
+ char foo[10];
+ int stack_i, stack_printed = 0;
+
+ for (stack_i = 10; stack_i > -LWPTEST_STACKSIZE * 2; stack_i--) {
+ if (stack_i < -LWPTEST_STACKSIZE - 100 && !stack_printed) {
+ printf("hum overrun stack now\n");
+ stack_printed = 1;
+ }
+ foo[stack_i] = 0x4e;
+ }
+}
+
+
+static void
+underrun_stack (void *arg)
+{
+ char foo[10];
+
+ for (stack_i = 0; stack_i < LWPTEST_STACKSIZE * 2; stack_i++) {
+ if (stack_i > LWPTEST_STACKSIZE + 100&& !stack_printed) {
+ printf("hum underrun stack now\n");
+ stack_printed = 1;
+ }
+ foo[stack_i] = 0xe4;
+ }
+}
+
+
/*
* Usage
*/
@@ -291,6 +338,8 @@ usage(char *progname)
"deadlock-write\tdeadlockdetection\n"
"deadlock-read\tdeadlockdetection\n"
"deadlock-read2\tdeadlockdetection\n"
+ "overrun-stack\tover run the stack\n"
+ "underrun-stack\tunder run the stack\n"
"version\t\tPrint version\n");
printf("Use several of these tests together to test their interopability\n");
@@ -334,9 +383,19 @@ int main(int argc, char **argv)
deadlock_read();
} else if (strcasecmp("deadlock-read2", argv[1]) == 0) {
deadlock_read2();
+ } else if (strcasecmp("overrun-stack", argv[1]) == 0) {
+ PROCESS tpid;
+ if (LWP_CreateProcess (overrun_stack, LWPTEST_STACKSIZE, 1,
+ NULL, "overunner", &tpid))
+ errx (1, "Cannot create stack overrunner process");
+ } else if (strcasecmp("underrun-stack", argv[1]) == 0) {
+ PROCESS tpid;
+ if (LWP_CreateProcess (underrun_stack, LWPTEST_STACKSIZE, 1,
+ NULL, "underrunner", &tpid))
+ errx (1, "Cannot create stack underrunner process");
} else if (strcasecmp("version", argv[1]) == 0) {
printf("Version: "
- "$KTH: testlwp.c,v 1.8 2000/10/20 17:10:38 lha Exp $\n");
+ "$arla: testlwp.c,v 1.9 2002/06/01 17:47:49 lha Exp $\n");
exit (0);
} else {
printf("unknown command %s\n", argv[1]);
diff --git a/usr.sbin/afs/src/lwp/testprocess.c b/usr.sbin/afs/src/lwp/testprocess.c
index 932e7fd58b6..8b39a37cf23 100644
--- a/usr.sbin/afs/src/lwp/testprocess.c
+++ b/usr.sbin/afs/src/lwp/testprocess.c
@@ -8,7 +8,7 @@
*
* Todo: really a test-program
*
- * $KTH: testprocess.c,v 1.1 1998/06/09 11:52:53 lha Exp $
+ * $arla: testprocess.c,v 1.1 1998/06/09 11:52:53 lha Exp $
*/
int savecontext();
diff --git a/usr.sbin/afs/src/lwp/timer.c b/usr.sbin/afs/src/lwp/timer.c
index d739d6fd34c..6a570e4ef41 100644
--- a/usr.sbin/afs/src/lwp/timer.c
+++ b/usr.sbin/afs/src/lwp/timer.c
@@ -31,7 +31,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
-RCSID("$KTH: timer.c,v 1.5 1998/05/18 05:44:41 art Exp $");
+RCSID("$arla: timer.c,v 1.6 2002/06/01 17:47:50 lha Exp $");
#endif
#include <sys/time.h>
@@ -58,11 +58,11 @@ static int globalInitDone = 0;
/* t1 = t2 - t3 */
static void
-subtract(register struct timeval *t1,
- register struct timeval *t2,
- register struct timeval *t3)
+subtract(struct timeval *t1,
+ struct timeval *t2,
+ struct timeval *t3)
{
- register int sec2, usec2, sec3, usec3;
+ int sec2, usec2, sec3, usec3;
sec2 = t2 -> tv_sec;
usec2 = t2 -> tv_usec;
@@ -92,7 +92,7 @@ subtract(register struct timeval *t1,
/* t1 += t2; */
static void
-add(register struct timeval *t1, register struct timeval *t2)
+add(struct timeval *t1, struct timeval *t2)
{
t1 -> tv_usec += t2 -> tv_usec;
t1 -> tv_sec += t2 -> tv_sec;
@@ -105,7 +105,7 @@ add(register struct timeval *t1, register struct timeval *t2)
/* t1 == t2 */
bool
-TM_eql(register struct timeval *t1, register struct timeval *t2)
+TM_eql(struct timeval *t1, struct timeval *t2)
{
return (t1->tv_usec == t2->tv_usec) && (t1->tv_sec == t2->tv_sec);
}
@@ -115,7 +115,7 @@ TM_eql(register struct timeval *t1, register struct timeval *t2)
/*
obsolete, commentless procedure, all done by hand expansion now.
static bool
-geq(register struct timeval *t1, register struct timeval *t2)
+geq(struct timeval *t1, struct timeval *t2)
{
return (t1->tv_sec > t2->tv_sec) ||
(t1->tv_sec == t2->tv_sec && t1->tv_usec >= t2->tv_usec);
@@ -123,7 +123,7 @@ geq(register struct timeval *t1, register struct timeval *t2)
*/
static bool
-blocking(register struct TM_Elem *t)
+blocking(struct TM_Elem *t)
{
return (t->TotalTime.tv_sec < 0 || t->TotalTime.tv_usec < 0);
}
@@ -135,7 +135,7 @@ blocking(register struct TM_Elem *t)
*/
int
-TM_Init(register struct TM_Elem **list)
+TM_Init(struct TM_Elem **list)
{
if (!globalInitDone) {
FT_Init (0, 0);
@@ -158,7 +158,7 @@ TM_Init(register struct TM_Elem **list)
}
int
-TM_Final(register struct TM_Elem **list)
+TM_Final(struct TM_Elem **list)
{
if (list == NIL || *list == NIL)
return -1;
@@ -178,7 +178,7 @@ TM_Insert(struct TM_Elem *tlistPtr, struct TM_Elem *elem)
/* pointer to head pointer of timer list */
/* element to be inserted */
{
- register struct TM_Elem *next;
+ struct TM_Elem *next;
/* TimeLeft must be set for function IOMGR with infinite timeouts */
elem -> TimeLeft = elem -> TotalTime;
@@ -216,7 +216,7 @@ TM_Rescan(struct TM_Elem *tlist)
/* head pointer of timer list */
{
struct timeval time;
- register int expired;
+ int expired;
FT_AGetTimeOfDay(&time, 0);
expired = 0;
@@ -258,7 +258,7 @@ TM_GetExpired(struct TM_Elem *tlist)
struct TM_Elem *
TM_GetEarliest(struct TM_Elem *tlist)
{
- register struct TM_Elem *e;
+ struct TM_Elem *e;
e = tlist -> Next;
return (e == tlist ? NIL : e);
diff --git a/usr.sbin/afs/src/lwp/timer.h b/usr.sbin/afs/src/lwp/timer.h
index 25d1a1a5281..ef4cff58895 100644
--- a/usr.sbin/afs/src/lwp/timer.h
+++ b/usr.sbin/afs/src/lwp/timer.h
@@ -43,20 +43,20 @@ extern struct TM_Elem *TM_GetExpired();
extern struct TM_Elem *TM_GetEarliest();
#endif
-int TM_Init(register struct TM_Elem **list);
+int TM_Init(struct TM_Elem **list);
int TM_Rescan(struct TM_Elem *tlist);
struct TM_Elem *TM_GetExpired(struct TM_Elem *tlist);
struct TM_Elem *TM_GetEarliest(struct TM_Elem *tlist);
typedef unsigned char bool; /* XXX - this is not the correct place */
-bool TM_eql(register struct timeval *, register struct timeval *);
-int TM_Final(register struct TM_Elem **);
+bool TM_eql(struct timeval *, struct timeval *);
+int TM_Final(struct TM_Elem **);
void TM_Insert(struct TM_Elem *, struct TM_Elem *);
#define FOR_ALL_ELTS(var, list, body)\
{\
- register struct TM_Elem *_LIST_, *var, *_NEXT_;\
+ struct TM_Elem *_LIST_, *var, *_NEXT_;\
_LIST_ = (list);\
for (var = _LIST_ -> Next; var != _LIST_; var = _NEXT_) {\
_NEXT_ = var -> Next;\