… | |
… | |
31 | #else |
31 | #else |
32 | # define PAGESIZE 0 |
32 | # define PAGESIZE 0 |
33 | # define BOOT_PAGESIZE (void)0 |
33 | # define BOOT_PAGESIZE (void)0 |
34 | #endif |
34 | #endif |
35 | |
35 | |
36 | #if USE_VALGRIND |
36 | #if CORO_USE_VALGRIND |
37 | # include <valgrind/valgrind.h> |
37 | # include <valgrind/valgrind.h> |
38 | # define REGISTER_STACK(cctx,start,end) (cctx)->valgrind_id = VALGRIND_STACK_REGISTER ((start), (end)) |
38 | # define REGISTER_STACK(cctx,start,end) (cctx)->valgrind_id = VALGRIND_STACK_REGISTER ((start), (end)) |
39 | #else |
39 | #else |
40 | # define REGISTER_STACK(cctx,start,end) |
40 | # define REGISTER_STACK(cctx,start,end) |
41 | #endif |
41 | #endif |
… | |
… | |
74 | #ifndef SvRV_set |
74 | #ifndef SvRV_set |
75 | # define SvRV_set(s,v) SvRV(s) = (v) |
75 | # define SvRV_set(s,v) SvRV(s) = (v) |
76 | #endif |
76 | #endif |
77 | |
77 | |
78 | #if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 |
78 | #if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 |
79 | # undef STACKGUARD |
79 | # undef CORO_STACKGUARD |
80 | #endif |
80 | #endif |
81 | |
81 | |
82 | #ifndef STACKGUARD |
82 | #ifndef CORO_STACKGUARD |
83 | # define STACKGUARD 0 |
83 | # define CORO_STACKGUARD 0 |
84 | #endif |
84 | #endif |
85 | |
85 | |
86 | /* prefer perl internal functions over our own? */ |
86 | /* prefer perl internal functions over our own? */ |
87 | #ifndef PREFER_PERL_FUNCTIONS |
87 | #ifndef CORO_PREFER_PERL_FUNCTIONS |
88 | # define PREFER_PERL_FUNCTIONS 0 |
88 | # define CORO_PREFER_PERL_FUNCTIONS 0 |
89 | #endif |
89 | #endif |
90 | |
90 | |
91 | /* The next macro should declare a variable stacklevel that contains and approximation |
91 | /* The next macro should declare a variable stacklevel that contains and approximation |
92 | * to the current C stack pointer. Its property is that it changes with each call |
92 | * to the current C stack pointer. Its property is that it changes with each call |
93 | * and should be unique. */ |
93 | * and should be unique. */ |
… | |
… | |
148 | JMPENV *top_env; |
148 | JMPENV *top_env; |
149 | coro_context cctx; |
149 | coro_context cctx; |
150 | |
150 | |
151 | int inuse; |
151 | int inuse; |
152 | |
152 | |
153 | #if USE_VALGRIND |
153 | #if CORO_USE_VALGRIND |
154 | int valgrind_id; |
154 | int valgrind_id; |
155 | #endif |
155 | #endif |
156 | } coro_cctx; |
156 | } coro_cctx; |
157 | |
157 | |
158 | enum { |
158 | enum { |
… | |
… | |
288 | |
288 | |
289 | if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0) |
289 | if (mg && AvFILLp ((av = (AV *)mg->mg_obj)) >= 0) |
290 | CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; |
290 | CvPADLIST (cv) = (AV *)AvARRAY (av)[AvFILLp (av)--]; |
291 | else |
291 | else |
292 | { |
292 | { |
293 | #if PREFER_PERL_FUNCTIONS |
293 | #if CORO_PREFER_PERL_FUNCTIONS |
294 | /* this is probably cleaner, but also slower? */ |
294 | /* this is probably cleaner, but also slower? */ |
295 | CV *cp = Perl_cv_clone (cv); |
295 | CV *cp = Perl_cv_clone (cv); |
296 | CvPADLIST (cv) = CvPADLIST (cp); |
296 | CvPADLIST (cv) = CvPADLIST (cp); |
297 | CvPADLIST (cp) = 0; |
297 | CvPADLIST (cp) = 0; |
298 | SvREFCNT_dec (cp); |
298 | SvREFCNT_dec (cp); |
… | |
… | |
436 | * allocate various perl stacks. This is an exact copy |
436 | * allocate various perl stacks. This is an exact copy |
437 | * of perl.c:init_stacks, except that it uses less memory |
437 | * of perl.c:init_stacks, except that it uses less memory |
438 | * on the (sometimes correct) assumption that coroutines do |
438 | * on the (sometimes correct) assumption that coroutines do |
439 | * not usually need a lot of stackspace. |
439 | * not usually need a lot of stackspace. |
440 | */ |
440 | */ |
441 | #if PREFER_PERL_FUNCTIONS |
441 | #if CORO_PREFER_PERL_FUNCTIONS |
442 | # define coro_init_stacks init_stacks |
442 | # define coro_init_stacks init_stacks |
443 | #else |
443 | #else |
444 | static void |
444 | static void |
445 | coro_init_stacks () |
445 | coro_init_stacks () |
446 | { |
446 | { |
… | |
… | |
632 | |
632 | |
633 | Newz (0, cctx, 1, coro_cctx); |
633 | Newz (0, cctx, 1, coro_cctx); |
634 | |
634 | |
635 | #if HAVE_MMAP |
635 | #if HAVE_MMAP |
636 | |
636 | |
637 | cctx->ssize = ((STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + STACKGUARD) * PAGESIZE; |
637 | cctx->ssize = ((CORO_STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + CORO_STACKGUARD) * PAGESIZE; |
638 | /* mmap supposedly does allocate-on-write for us */ |
638 | /* mmap supposedly does allocate-on-write for us */ |
639 | cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
639 | cctx->sptr = mmap (0, cctx->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
640 | |
640 | |
641 | if (cctx->sptr != (void *)-1) |
641 | if (cctx->sptr != (void *)-1) |
642 | { |
642 | { |
643 | # if STACKGUARD |
643 | # if CORO_STACKGUARD |
644 | mprotect (cctx->sptr, STACKGUARD * PAGESIZE, PROT_NONE); |
644 | mprotect (cctx->sptr, CORO_STACKGUARD * PAGESIZE, PROT_NONE); |
645 | # endif |
645 | # endif |
646 | REGISTER_STACK ( |
646 | REGISTER_STACK ( |
647 | cctx, |
647 | cctx, |
648 | STACKGUARD * PAGESIZE + (char *)cctx->sptr, |
648 | CORO_STACKGUARD * PAGESIZE + (char *)cctx->sptr, |
649 | cctx->ssize + (char *)cctx->sptr |
649 | cctx->ssize + (char *)cctx->sptr |
650 | ); |
650 | ); |
651 | |
651 | |
652 | coro_create (&cctx->cctx, coro_run, (void *)cctx, cctx->sptr, cctx->ssize); |
652 | coro_create (&cctx->cctx, coro_run, (void *)cctx, cctx->sptr, cctx->ssize); |
653 | } |
653 | } |
654 | else |
654 | else |
655 | #endif |
655 | #endif |
656 | { |
656 | { |
657 | cctx->ssize = -STACKSIZE * (long)sizeof (long); |
657 | cctx->ssize = -CORO_STACKSIZE * (long)sizeof (long); |
658 | New (0, cctx->sptr, STACKSIZE, long); |
658 | New (0, cctx->sptr, CORO_STACKSIZE, long); |
659 | |
659 | |
660 | if (!cctx->sptr) |
660 | if (!cctx->sptr) |
661 | { |
661 | { |
662 | perror ("FATAL: unable to allocate stack for coroutine"); |
662 | perror ("FATAL: unable to allocate stack for coroutine"); |
663 | _exit (EXIT_FAILURE); |
663 | _exit (EXIT_FAILURE); |
… | |
… | |
681 | if (!cctx) |
681 | if (!cctx) |
682 | return; |
682 | return; |
683 | |
683 | |
684 | --cctx_count; |
684 | --cctx_count; |
685 | |
685 | |
686 | #if USE_VALGRIND |
686 | #if CORO_USE_VALGRIND |
687 | VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); |
687 | VALGRIND_STACK_DEREGISTER (cctx->valgrind_id); |
688 | #endif |
688 | #endif |
689 | |
689 | |
690 | #if HAVE_MMAP |
690 | #if HAVE_MMAP |
691 | if (cctx->ssize > 0) |
691 | if (cctx->ssize > 0) |