--- libcoro/coro.c 2005/08/30 21:32:17 1.17 +++ 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,12 +40,19 @@ # 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_UCONTEXT +# include +#endif + #if CORO_SJLJ || CORO_LOSER || CORO_LINUX || CORO_IRIX #include @@ -164,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_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 @@ -190,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