… | |
… | |
29 | # endif |
29 | # endif |
30 | #endif |
30 | #endif |
31 | |
31 | |
32 | #include <errno.h> |
32 | #include <errno.h> |
33 | |
33 | |
|
|
34 | #if !__i386 && !__x86_64 && !__powerpc && !__m68k && !__alpha && !__mips && !__sparc64 |
|
|
35 | # undef STACKGUARD |
|
|
36 | #endif |
|
|
37 | |
|
|
38 | #ifndef STACKGUARD |
|
|
39 | # define STACKGUARD 0 |
|
|
40 | #endif |
|
|
41 | |
34 | #ifdef HAVE_MMAP |
42 | #ifdef HAVE_MMAP |
35 | # include <unistd.h> |
43 | # include <unistd.h> |
36 | # include <sys/mman.h> |
44 | # include <sys/mman.h> |
37 | # ifndef MAP_ANONYMOUS |
45 | # ifndef MAP_ANONYMOUS |
38 | # ifdef MAP_ANON |
46 | # ifdef MAP_ANON |
39 | # define MAP_ANONYMOUS MAP_ANON |
47 | # define MAP_ANONYMOUS MAP_ANON |
40 | # else |
48 | # else |
41 | # undef HAVE_MMAP |
49 | # undef HAVE_MMAP |
42 | # endif |
50 | # endif |
|
|
51 | # endif |
|
|
52 | # include <limits.h> |
|
|
53 | # ifndef PAGESIZE |
|
|
54 | # define PAGESIZE pagesize |
|
|
55 | # define BOOT_PAGESIZE pagesize = sysconf (_SC_PAGESIZE) |
|
|
56 | static long pagesize; |
|
|
57 | # else |
|
|
58 | # define BOOT_PAGESIZE |
43 | # endif |
59 | # endif |
44 | #endif |
60 | #endif |
45 | |
61 | |
46 | #define SUB_INIT "Coro::State::initialize" |
62 | #define SUB_INIT "Coro::State::initialize" |
47 | #define UCORO_STATE "_coro_state" |
63 | #define UCORO_STATE "_coro_state" |
… | |
… | |
147 | AV *padlist = CvPADLIST (cv); |
163 | AV *padlist = CvPADLIST (cv); |
148 | AV *newpadlist, *newpad; |
164 | AV *newpadlist, *newpad; |
149 | |
165 | |
150 | newpadlist = newAV (); |
166 | newpadlist = newAV (); |
151 | AvREAL_off (newpadlist); |
167 | AvREAL_off (newpadlist); |
|
|
168 | #if PERL_VERSION < 9 |
152 | Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1); |
169 | Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1, 1); |
|
|
170 | #else |
|
|
171 | Perl_pad_push (aTHX_ padlist, AvFILLp (padlist) + 1); |
|
|
172 | #endif |
153 | newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)]; |
173 | newpad = (AV *)AvARRAY (padlist)[AvFILLp (padlist)]; |
154 | --AvFILLp (padlist); |
174 | --AvFILLp (padlist); |
155 | |
175 | |
156 | av_store (newpadlist, 0, SvREFCNT_inc (*av_fetch (padlist, 0, FALSE))); |
176 | av_store (newpadlist, 0, SvREFCNT_inc (*av_fetch (padlist, 0, FALSE))); |
157 | av_store (newpadlist, 1, (SV *)newpad); |
177 | av_store (newpadlist, 1, (SV *)newpad); |
… | |
… | |
527 | stack->gencnt = ctx->gencnt = 0; |
547 | stack->gencnt = ctx->gencnt = 0; |
528 | |
548 | |
529 | if (alloc) |
549 | if (alloc) |
530 | { |
550 | { |
531 | #if HAVE_MMAP |
551 | #if HAVE_MMAP |
532 | stack->ssize = STACKSIZE * sizeof (long); /* mmap should do allocate-on-write for us */ |
552 | stack->ssize = ((STACKSIZE * sizeof (long) + PAGESIZE - 1) / PAGESIZE + STACKGUARD) * PAGESIZE; /* mmap should do allocate-on-write for us */ |
533 | stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
553 | stack->sptr = mmap (0, stack->ssize, PROT_EXEC|PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); |
534 | if (stack->sptr == (void *)-1) |
554 | if (stack->sptr != (void *)-1) |
|
|
555 | { |
|
|
556 | # if STACKGUARD |
|
|
557 | mprotect (stack->sptr, STACKGUARD * PAGESIZE, PROT_NONE); |
|
|
558 | # endif |
|
|
559 | } |
|
|
560 | else |
535 | #endif |
561 | #endif |
536 | { |
562 | { |
537 | stack->ssize = - (STACKSIZE * (long)sizeof (long)); |
563 | stack->ssize = - (STACKSIZE * (long)sizeof (long)); |
538 | New (0, stack->sptr, STACKSIZE, long); |
564 | New (0, stack->sptr, STACKSIZE, long); |
539 | } |
565 | } |
… | |
… | |
603 | } |
629 | } |
604 | else |
630 | else |
605 | { |
631 | { |
606 | UNOP myop; |
632 | UNOP myop; |
607 | |
633 | |
608 | PL_op = (OP *)&myop; |
|
|
609 | |
|
|
610 | Zero(&myop, 1, UNOP); |
634 | Zero(&myop, 1, UNOP); |
611 | myop.op_next = Nullop; |
635 | myop.op_next = Nullop; |
612 | myop.op_flags = OPf_WANT_VOID; |
636 | myop.op_flags = OPf_WANT_VOID; |
|
|
637 | |
|
|
638 | PL_op = (OP *)&myop; |
613 | |
639 | |
614 | PUSHMARK(SP); |
640 | PUSHMARK(SP); |
615 | XPUSHs (sub_init); |
641 | XPUSHs (sub_init); |
616 | /* |
642 | /* |
617 | * the next line is slightly wrong, as PL_op->op_next |
643 | * the next line is slightly wrong, as PL_op->op_next |
… | |
… | |
893 | BOOT: |
919 | BOOT: |
894 | { /* {} necessary for stoopid perl-5.6.x */ |
920 | { /* {} necessary for stoopid perl-5.6.x */ |
895 | #ifdef USE_ITHREADS |
921 | #ifdef USE_ITHREADS |
896 | MUTEX_INIT (&coro_mutex); |
922 | MUTEX_INIT (&coro_mutex); |
897 | #endif |
923 | #endif |
|
|
924 | BOOT_PAGESIZE; |
898 | |
925 | |
899 | ucoro_state_sv = newSVpv (UCORO_STATE, sizeof(UCORO_STATE) - 1); |
926 | ucoro_state_sv = newSVpv (UCORO_STATE, sizeof(UCORO_STATE) - 1); |
900 | PERL_HASH(ucoro_state_hash, UCORO_STATE, sizeof(UCORO_STATE) - 1); |
927 | PERL_HASH(ucoro_state_hash, UCORO_STATE, sizeof(UCORO_STATE) - 1); |
901 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
928 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
902 | |
929 | |
… | |
… | |
927 | /*coro->mainstack = 0; *//*actual work is done inside transfer */ |
954 | /*coro->mainstack = 0; *//*actual work is done inside transfer */ |
928 | /*coro->stack = 0;*/ |
955 | /*coro->stack = 0;*/ |
929 | |
956 | |
930 | /* same as JMPENV_BOOTSTRAP */ |
957 | /* same as JMPENV_BOOTSTRAP */ |
931 | /* we might be able to recycle start_env, but safe is safe */ |
958 | /* we might be able to recycle start_env, but safe is safe */ |
932 | /*Zero(&coro->start_env, 1, JMPENV);*/ |
959 | /*Zero (&coro->start_env, 1, JMPENV);*/ |
933 | coro->start_env.je_ret = -1; |
960 | coro->start_env.je_ret = -1; |
934 | coro->start_env.je_mustcatch = TRUE; |
961 | coro->start_env.je_mustcatch = TRUE; |
935 | |
962 | |
936 | RETVAL = coro; |
963 | RETVAL = coro; |
937 | OUTPUT: |
964 | OUTPUT: |