--- pcl.c.orig	2004-11-11 00:36:44.638754472 +0900
+++ pcl.c	2004-11-08 20:16:20.000000000 +0900
@@ -327,33 +327,94 @@
 
 #else /* #if defined(CO_USE_SIGCONTEXT) */
 
-static int co_set_context(co_ctx_t *ctx, void *func, char *stkbase, long stksiz) {
+static int co_set_context(co_ctx_t *ctx, void *func, char *stkbase, long stacksize) {
 	char *stack;
 
-	stack = stkbase + stksiz - sizeof(int);
+	stack = stkbase - sizeof(int);
 
 	setjmp(ctx->cc);
 
-#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
-    && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(JB_PC) && defined(JB_SP)
-	ctx->cc[0].__jmpbuf[JB_PC] = (int) func;
-	ctx->cc[0].__jmpbuf[JB_SP] = (int) stack;
-#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
-    && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && defined(__mc68000__)
-	ctx->cc[0].__jmpbuf[0].__aregs[0] = (long) func;
-	ctx->cc[0].__jmpbuf[0].__sp = (int *) stack;
-#elif defined(__GNU_LIBRARY__) && defined(__i386__)
-	ctx->cc[0].__jmpbuf[0].__pc = func;
-	ctx->cc[0].__jmpbuf[0].__sp = stack;
-#elif defined(_WIN32) && defined(_MSC_VER)
-	((_JUMP_BUFFER *) &ctx->cc)->Eip = (long) func;
-	((_JUMP_BUFFER *) &ctx->cc)->Esp = (long) stack;
-#elif defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
-    && __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 0 && (defined(__powerpc64__) || defined(__powerpc__))
-	ctx->cc[0].__jmpbuf[JB_LR] = (int) func;
-	ctx->cc[0].__jmpbuf[JB_GPR1] = (int) stack;
+    /* from Io's Scheduler.c */
+#if defined(_BSD_PPC_SETJMP_H_)
+    /* OSX/PPC */
+    #define setjmp _setjmp /* no need for signal masks */
+    #define longjmp _longjmp
+    memset(((char *)stack) + stacksize - 64, 0, 64);	/* very crude... */
+    ctx->cc[0] = ((int)stack + stacksize - 64 + 15) & ~15;
+    ctx->cc[21] = (int)func;
+    
+#elif defined(_IRIX4_SIGJBLEN)
+    /* Irix/SGI */
+    ctx->cc[JB_SP] = (__uint64_t)((char *)stack + stacksize - 8);
+    ctx->cc[JB_PC] = (__uint64_t)func;
+    
+#elif defined(JB_GPR1)
+    /* Linux/PPC */
+    ctx->cc->__jmpbuf[JB_GPR1] = ((int) stack + stacksize - 64 + 15) & ~15;
+    ctx->cc->__jmpbuf[JB_LR] = (int) func;
+    
+#elif defined(JB_RBX)
+    /* Linux/Opteron */
+    ctx->cc->__jmpbuf[JB_RSP] = (long int )stack + stacksize;
+    ctx->cc->__jmpbuf[JB_PC] = func;
+    
+#elif defined(JB_SP)
+    /* Linux/x86 with glibc2 */
+    ctx->cc->__jmpbuf[JB_SP] = (int)stack + stacksize;
+    ctx->cc->__jmpbuf[JB_PC] = (int)func;
+    
+#elif defined(_I386_JMP_BUF_H)
+    /* x86-linux with libc5 */
+    ctx->cc->__sp = stackend;
+    ctx->cc->__pc = func;
+    
+#elif defined(__JMP_BUF_SP)
+    /* arm-linux on the sharp zauras */
+    ctx->cc->__jmpbuf[__JMP_BUF_SP] = (int)stack + stacksize;
+    ctx->cc->__jmpbuf[__JMP_BUF_SP+1] = (int)func;
+    
+#elif defined(__CYGWIN__) 
+    /* Cygwin */
+    ctx->cc[7] = (int)((int)stack + stacksize);
+    ctx->cc[8] = (int)func;
+    
+#elif defined(__MINGW32__) 
+    ctx->cc[4] = (int)((unsigned char *)stack + stacksize - 100);   /* esp */
+    ctx->cc[5] = (int)func; /* eip */
+      
+#elif defined(_MSC_VER)
+    /* win32 visual c */
+    /* should this be the same as __MINGW32__? */
+    ctx->cc[4] = (int)((unsigned char *)stack + stacksize);  /* esp */
+    ctx->cc[5] = (int)func; /* eip */
+
+#elif defined(__SYMBIAN32__)
+    ctx->cc[0] = 0;
+    ctx->cc[1] = 0;
+    ctx->cc[2] = 0;
+    ctx->cc[3] = (unsigned int)stack + CSTACK_STACKSIZE - 64;
+    ctx->cc[9] = (int)func;
+    ctx->cc[8] =  ctx->cc[3] + 32;
+    
+#elif defined(_JBLEN) && (_JBLEN == 81)
+    /* FreeBSD/Alpha */
+    ctx->cc->_jb[2] = (long)func;     /* sc_pc */
+    ctx->cc->_jb[26+4] = (long)func;  /* sc_regs[R_RA] */
+    ctx->cc->_jb[27+4] = (long)func;  /* sc_regs[R_T12] */
+    ctx->cc->_jb[30+4] = (long)(stack + stacksize); /* sc_regs[R_SP] */
+    
+#elif defined(_JB_ATTRIBUTES)
+    /* NetBSD i386? */
+    ctx->cc[2] = (long)(stack + stacksize);
+    ctx->cc[0] = (long)func;
+    
+#elif defined(_JBLEN)
+    /* i386-BSD and NetBSD on IA32 */
+    ctx->cc->_jb[2] = (long)(stack + stacksize);
+    ctx->cc->_jb[0] = (long)func;
+    
 #else
-#error "PCL: Unsupported setjmp/longjmp platform. Please report to <davidel@xmailserver.org>"
+#error "Io Scheduler error: no setup_jmpbuf entry for this platform (original message: PCL: Unsupported setjmp/longjmp platform. Please report to <davidel@xmailserver.org>)"
 #endif
 
 	return 0;
