--- libcoro/coro.c 2005/03/03 17:20:31 1.13 +++ libcoro/coro.c 2006/10/26 06:50:20 1.21 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001-2005 Marc Alexander Lehmann + * Copyright (c) 2001-2006 Marc Alexander Lehmann * * Redistribution and use in source and binary forms, with or without modifica- * tion, are permitted provided that the following conditions are met: @@ -40,15 +40,28 @@ # elif __i386__ && CORO_LINUX # define STACK_ADJUST_PTR(sp,ss) ((char *)(sp) + (ss)) # define STACK_ADJUST_SIZE(sp,ss) (ss) +# elif __amd64__ && CORO_LINUX +# define STACK_ADJUST_PTR(sp,ss) ((char *)(sp) + (ss) - 8) +# define STACK_ADJUST_SIZE(sp,ss) (ss) # else # define STACK_ADJUST_PTR(sp,ss) (sp) # define STACK_ADJUST_SIZE(sp,ss) (ss) # endif #endif -#if CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX +#if CORO_UCONTEXT +# include +#endif + +#if CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX -#include +#include + +#if CORO_SJLJ +# include +# include +# include +#endif static volatile coro_func coro_init_func; static volatile void *coro_init_arg; @@ -74,7 +87,7 @@ /* trampoline signal handler */ static void -trampoline(int sig) +trampoline (int sig) { if (setjmp (((coro_context *)new_coro)->env)) coro_init (); /* start it */ @@ -102,7 +115,7 @@ makecontext (&(ctx->uc), (void (*)()) coro, 1, arg); -#elif CORO_SJLJ || CORO_LOOSE || CORO_LINUX || CORO_IRIX +#elif CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX # if CORO_SJLJ stack_t ostk, nstk; @@ -158,15 +171,28 @@ if (~ostk.ss_flags & SS_DISABLE) sigaltstack (&ostk, 0); - sigaction (SIGUSR1, &osa, 0); + sigaction (SIGUSR2, &osa, 0); sigprocmask (SIG_SETMASK, &osig, 0); -# elif CORO_LOOSE +# elif CORO_LOSER setjmp (ctx->env); +#if __CYGWIN__ ctx->env[7] = (long)((char *)sptr + ssize); ctx->env[8] = (long)coro_init; +#elif defined(_M_IX86) + ((_JUMP_BUFFER *)&ctx->env)->Eip = (long)coro_init; + ((_JUMP_BUFFER *)&ctx->env)->Esp = (long)STACK_ADJUST_PTR (sptr,ssize); +#elif defined(_M_AMD64) + ((_JUMP_BUFFER *)&ctx->env)->Rip = (__int64)coro_init; + ((_JUMP_BUFFER *)&ctx->env)->Rsp = (__int64)STACK_ADJUST_PTR (sptr,ssize); +#elif defined(_M_IA64) + ((_JUMP_BUFFER *)&ctx->env)->StIIP = (__int64)coro_init; + ((_JUMP_BUFFER *)&ctx->env)->IntSp = (__int64)STACK_ADJUST_PTR (sptr,ssize); +#else +#error "microsoft libc or architecture not supported" +#endif # elif CORO_LINUX @@ -184,7 +210,7 @@ ctx->env[0].__jmpbuf[0].__sp = (void *)((char *)sptr + ssize); #elif defined(__GNU_LIBRARY__) && defined(__amd64__) ctx->env[0].__jmpbuf[JB_PC] = (long)coro_init; - ctx->env[0].__jmpbuf[JB_RSP] = (long)((char *)sptr + ssize); + ctx->env[0].__jmpbuf[JB_RSP] = (long)STACK_ADJUST_PTR (sptr,ssize); #else #error "linux libc or architecture not supported" #endif