… | |
… | |
116 | # define CORO_CLOCK_MONOTONIC 1 |
116 | # define CORO_CLOCK_MONOTONIC 1 |
117 | # define CORO_CLOCK_THREAD_CPUTIME_ID 3 |
117 | # define CORO_CLOCK_THREAD_CPUTIME_ID 3 |
118 | # endif |
118 | # endif |
119 | #endif |
119 | #endif |
120 | |
120 | |
|
|
121 | /* one off bugfix for perl 5.22 */ |
|
|
122 | #if PERL_VERSION_ATLEAST(5,22,0) && !PERL_VERSION_ATLEAST(5,24,0) |
|
|
123 | # undef PadlistNAMES |
|
|
124 | # define PadlistNAMES(pl) *((PADNAMELIST **)PadlistARRAY (pl)) |
|
|
125 | #endif |
|
|
126 | |
|
|
127 | #if PERL_VERSION_ATLEAST(5,24,0) |
|
|
128 | # define SUB_ARGARRAY PL_curpad[0] |
|
|
129 | #else |
|
|
130 | # define SUB_ARGARRAY (SV *)cx->blk_sub.argarray |
|
|
131 | #endif |
|
|
132 | |
|
|
133 | /* perl usually suppresses asserts. for debugging, we sometimes force it to be on */ |
|
|
134 | #if 0 |
|
|
135 | # undef NDEBUG |
|
|
136 | # include <assert.h> |
|
|
137 | #endif |
|
|
138 | |
121 | static double (*nvtime)(); /* so why doesn't it take void? */ |
139 | static double (*nvtime)(); /* so why doesn't it take void? */ |
122 | static void (*u2time)(pTHX_ UV ret[2]); |
140 | static void (*u2time)(pTHX_ UV ret[2]); |
123 | |
141 | |
124 | /* we hijack an hopefully unused CV flag for our purposes */ |
142 | /* we hijack an hopefully unused CV flag for our purposes */ |
125 | #define CVf_SLF 0x4000 |
143 | #define CVf_SLF 0x4000 |
… | |
… | |
730 | static void |
748 | static void |
731 | swap_svs_enter (pTHX_ Coro__State c) |
749 | swap_svs_enter (pTHX_ Coro__State c) |
732 | { |
750 | { |
733 | int i; |
751 | int i; |
734 | |
752 | |
|
|
753 | for (i = 0; i <= AvFILLp (c->swap_sv); i += 2) |
|
|
754 | swap_sv (AvARRAY (c->swap_sv)[i], AvARRAY (c->swap_sv)[i + 1]); |
|
|
755 | } |
|
|
756 | |
|
|
757 | static void |
|
|
758 | swap_svs_leave (pTHX_ Coro__State c) |
|
|
759 | { |
|
|
760 | int i; |
|
|
761 | |
735 | for (i = AvFILLp (c->swap_sv) - 1; i >= 0; i -= 2) |
762 | for (i = AvFILLp (c->swap_sv) - 1; i >= 0; i -= 2) |
736 | swap_sv (AvARRAY (c->swap_sv)[i], AvARRAY (c->swap_sv)[i + 1]); |
|
|
737 | } |
|
|
738 | |
|
|
739 | static void |
|
|
740 | swap_svs_leave (pTHX_ Coro__State c) |
|
|
741 | { |
|
|
742 | int i; |
|
|
743 | |
|
|
744 | for (i = 0; i <= AvFILLp (c->swap_sv); i += 2) |
|
|
745 | swap_sv (AvARRAY (c->swap_sv)[i], AvARRAY (c->swap_sv)[i + 1]); |
763 | swap_sv (AvARRAY (c->swap_sv)[i], AvARRAY (c->swap_sv)[i + 1]); |
746 | } |
764 | } |
747 | |
765 | |
748 | #define SWAP_SVS_ENTER(coro) \ |
766 | #define SWAP_SVS_ENTER(coro) \ |
749 | if (ecb_expect_false ((coro)->swap_sv)) \ |
767 | if (ecb_expect_false ((coro)->swap_sv)) \ |
… | |
… | |
963 | #endif |
981 | #endif |
964 | |
982 | |
965 | New(54,PL_savestack,24,ANY); |
983 | New(54,PL_savestack,24,ANY); |
966 | PL_savestack_ix = 0; |
984 | PL_savestack_ix = 0; |
967 | PL_savestack_max = 24; |
985 | PL_savestack_max = 24; |
|
|
986 | #if PERL_VERSION_ATLEAST (5,24,0) |
|
|
987 | /* perl 5.24 moves SS_MAXPUSH optimisation from */ |
|
|
988 | /* the header macros to PL_savestack_max */ |
|
|
989 | PL_savestack_max -= SS_MAXPUSH; |
|
|
990 | #endif |
968 | |
991 | |
969 | #if !PERL_VERSION_ATLEAST (5,10,0) |
992 | #if !PERL_VERSION_ATLEAST (5,10,0) |
970 | New(54,PL_retstack,4,OP*); |
993 | New(54,PL_retstack,4,OP*); |
971 | PL_retstack_ix = 0; |
994 | PL_retstack_ix = 0; |
972 | PL_retstack_max = 4; |
995 | PL_retstack_max = 4; |
… | |
… | |
1038 | } |
1061 | } |
1039 | |
1062 | |
1040 | return rss; |
1063 | return rss; |
1041 | } |
1064 | } |
1042 | |
1065 | |
1043 | /** coroutine stack handling ************************************************/ |
1066 | /** provide custom get/set/clear methods for %SIG elements ******************/ |
1044 | |
|
|
1045 | static int (*orig_sigelem_get) (pTHX_ SV *sv, MAGIC *mg); |
|
|
1046 | static int (*orig_sigelem_set) (pTHX_ SV *sv, MAGIC *mg); |
|
|
1047 | static int (*orig_sigelem_clr) (pTHX_ SV *sv, MAGIC *mg); |
|
|
1048 | |
1067 | |
1049 | /* apparently < 5.8.8 */ |
1068 | /* apparently < 5.8.8 */ |
1050 | #ifndef MgPV_nolen_const |
1069 | #ifndef MgPV_nolen_const |
1051 | #define MgPV_nolen_const(mg) (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \ |
1070 | #define MgPV_nolen_const(mg) (((((int)(mg)->mg_len)) == HEf_SVKEY) ? \ |
1052 | SvPV_nolen((SV*)((mg)->mg_ptr)) : \ |
1071 | SvPV_nolen((SV*)((mg)->mg_ptr)) : \ |
1053 | (const char*)(mg)->mg_ptr) |
1072 | (const char*)(mg)->mg_ptr) |
1054 | #endif |
1073 | #endif |
|
|
1074 | |
|
|
1075 | /* this will be a patched copy of PL_vtbl_sigelem */ |
|
|
1076 | static MGVTBL coro_sigelem_vtbl; |
|
|
1077 | |
|
|
1078 | static int ecb_cold |
|
|
1079 | coro_sig_copy (pTHX_ SV *sv, MAGIC *mg, SV *nsv, const char *name, I32 namlen) |
|
|
1080 | { |
|
|
1081 | char *key = SvPV_nolen ((SV *)name); |
|
|
1082 | |
|
|
1083 | /* do what mg_copy normally does */ |
|
|
1084 | sv_magic (nsv, mg->mg_obj, PERL_MAGIC_sigelem, name, namlen); |
|
|
1085 | assert (mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual == &PL_vtbl_sigelem); |
|
|
1086 | |
|
|
1087 | /* patch sigelem vtbl, but only for __WARN__ and __DIE__ */ |
|
|
1088 | if (*key == '_' |
|
|
1089 | && (strEQ (key, "__DIE__") |
|
|
1090 | || strEQ (key, "__WARN__"))) |
|
|
1091 | mg_find (nsv, PERL_MAGIC_sigelem)->mg_virtual = &coro_sigelem_vtbl; |
|
|
1092 | |
|
|
1093 | return 1; |
|
|
1094 | } |
|
|
1095 | |
|
|
1096 | /* perl does not have a %SIG vtbl, we provide one so we can override */ |
|
|
1097 | /* the magic vtbl for the __DIE__ and __WARN__ members */ |
|
|
1098 | static const MGVTBL coro_sig_vtbl = { |
|
|
1099 | 0, 0, 0, 0, 0, |
|
|
1100 | coro_sig_copy |
|
|
1101 | }; |
1055 | |
1102 | |
1056 | /* |
1103 | /* |
1057 | * This overrides the default magic get method of %SIG elements. |
1104 | * This overrides the default magic get method of %SIG elements. |
1058 | * The original one doesn't provide for reading back of PL_diehook/PL_warnhook |
1105 | * The original one doesn't provide for reading back of PL_diehook/PL_warnhook |
1059 | * and instead of trying to save and restore the hash elements (extremely slow), |
1106 | * and instead of trying to save and restore the hash elements (extremely slow), |
… | |
… | |
1061 | */ |
1108 | */ |
1062 | static int ecb_cold |
1109 | static int ecb_cold |
1063 | coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) |
1110 | coro_sigelem_get (pTHX_ SV *sv, MAGIC *mg) |
1064 | { |
1111 | { |
1065 | const char *s = MgPV_nolen_const (mg); |
1112 | const char *s = MgPV_nolen_const (mg); |
|
|
1113 | /* the key must be either __DIE__ or __WARN__ here */ |
|
|
1114 | SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook; |
1066 | |
1115 | |
1067 | if (*s == '_') |
1116 | SV *ssv; |
1068 | { |
|
|
1069 | SV **svp = 0; |
|
|
1070 | |
1117 | |
1071 | if (strEQ (s, "__DIE__" )) svp = &PL_diehook; |
|
|
1072 | if (strEQ (s, "__WARN__")) svp = &PL_warnhook; |
|
|
1073 | |
|
|
1074 | if (svp) |
1118 | if (!*svp) |
1075 | { |
|
|
1076 | SV *ssv; |
|
|
1077 | |
|
|
1078 | if (!*svp) |
|
|
1079 | ssv = &PL_sv_undef; |
1119 | ssv = &PL_sv_undef; |
1080 | else if (SvTYPE (*svp) == SVt_PVCV) /* perlio directly stores a CV in warnhook. ugh. */ |
1120 | else if (SvTYPE (*svp) == SVt_PVCV) /* perlio directly stores a CV in warnhook. ugh. */ |
1081 | ssv = sv_2mortal (newRV_inc (*svp)); |
1121 | ssv = sv_2mortal (newRV_inc (*svp)); |
1082 | else |
1122 | else |
1083 | ssv = *svp; |
1123 | ssv = *svp; |
1084 | |
1124 | |
1085 | sv_setsv (sv, ssv); |
1125 | sv_setsv (sv, ssv); |
1086 | return 0; |
1126 | return 0; |
1087 | } |
|
|
1088 | } |
|
|
1089 | |
|
|
1090 | return orig_sigelem_get ? orig_sigelem_get (aTHX_ sv, mg) : 0; |
|
|
1091 | } |
1127 | } |
1092 | |
1128 | |
1093 | static int ecb_cold |
1129 | static int ecb_cold |
1094 | coro_sigelem_clr (pTHX_ SV *sv, MAGIC *mg) |
1130 | coro_sigelem_clr (pTHX_ SV *sv, MAGIC *mg) |
1095 | { |
1131 | { |
1096 | const char *s = MgPV_nolen_const (mg); |
1132 | const char *s = MgPV_nolen_const (mg); |
|
|
1133 | /* the key must be either __DIE__ or __WARN__ here */ |
|
|
1134 | SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook; |
1097 | |
1135 | |
1098 | if (*s == '_') |
|
|
1099 | { |
|
|
1100 | SV **svp = 0; |
|
|
1101 | |
|
|
1102 | if (strEQ (s, "__DIE__" )) svp = &PL_diehook; |
|
|
1103 | if (strEQ (s, "__WARN__")) svp = &PL_warnhook; |
|
|
1104 | |
|
|
1105 | if (svp) |
|
|
1106 | { |
|
|
1107 | SV *old = *svp; |
1136 | SV *old = *svp; |
1108 | *svp = 0; |
1137 | *svp = 0; |
1109 | SvREFCNT_dec (old); |
1138 | SvREFCNT_dec (old); |
1110 | return 0; |
1139 | return 0; |
1111 | } |
|
|
1112 | } |
|
|
1113 | |
|
|
1114 | return orig_sigelem_clr ? orig_sigelem_clr (aTHX_ sv, mg) : 0; |
|
|
1115 | } |
1140 | } |
1116 | |
1141 | |
1117 | static int ecb_cold |
1142 | static int ecb_cold |
1118 | coro_sigelem_set (pTHX_ SV *sv, MAGIC *mg) |
1143 | coro_sigelem_set (pTHX_ SV *sv, MAGIC *mg) |
1119 | { |
1144 | { |
1120 | const char *s = MgPV_nolen_const (mg); |
1145 | const char *s = MgPV_nolen_const (mg); |
|
|
1146 | /* the key must be either __DIE__ or __WARN__ here */ |
|
|
1147 | SV **svp = s[2] == 'D' ? &PL_diehook : &PL_warnhook; |
1121 | |
1148 | |
1122 | if (*s == '_') |
|
|
1123 | { |
|
|
1124 | SV **svp = 0; |
|
|
1125 | |
|
|
1126 | if (strEQ (s, "__DIE__" )) svp = &PL_diehook; |
|
|
1127 | if (strEQ (s, "__WARN__")) svp = &PL_warnhook; |
|
|
1128 | |
|
|
1129 | if (svp) |
|
|
1130 | { |
|
|
1131 | SV *old = *svp; |
1149 | SV *old = *svp; |
1132 | *svp = SvOK (sv) ? newSVsv (sv) : 0; |
1150 | *svp = SvOK (sv) ? newSVsv (sv) : 0; |
1133 | SvREFCNT_dec (old); |
1151 | SvREFCNT_dec (old); |
1134 | return 0; |
1152 | return 0; |
1135 | } |
|
|
1136 | } |
|
|
1137 | |
|
|
1138 | return orig_sigelem_set ? orig_sigelem_set (aTHX_ sv, mg) : 0; |
|
|
1139 | } |
1153 | } |
1140 | |
1154 | |
1141 | static void |
1155 | static void |
1142 | prepare_nop (pTHX_ struct coro_transfer_args *ta) |
1156 | prepare_nop (pTHX_ struct coro_transfer_args *ta) |
1143 | { |
1157 | { |
… | |
… | |
1154 | static int |
1168 | static int |
1155 | slf_check_repeat (pTHX_ struct CoroSLF *frame) |
1169 | slf_check_repeat (pTHX_ struct CoroSLF *frame) |
1156 | { |
1170 | { |
1157 | return 1; |
1171 | return 1; |
1158 | } |
1172 | } |
|
|
1173 | |
|
|
1174 | /** coroutine stack handling ************************************************/ |
1159 | |
1175 | |
1160 | static UNOP init_perl_op; |
1176 | static UNOP init_perl_op; |
1161 | |
1177 | |
1162 | ecb_noinline static void /* noinline to keep it out of the transfer fast path */ |
1178 | ecb_noinline static void /* noinline to keep it out of the transfer fast path */ |
1163 | init_perl (pTHX_ struct coro *coro) |
1179 | init_perl (pTHX_ struct coro *coro) |
… | |
… | |
1206 | myop.op_next = Nullop; |
1222 | myop.op_next = Nullop; |
1207 | myop.op_type = OP_ENTERSUB; |
1223 | myop.op_type = OP_ENTERSUB; |
1208 | myop.op_flags = OPf_WANT_VOID; |
1224 | myop.op_flags = OPf_WANT_VOID; |
1209 | |
1225 | |
1210 | PUSHMARK (SP); |
1226 | PUSHMARK (SP); |
1211 | PUSHs ((SV *)coro->startcv); |
1227 | XPUSHs ((SV *)coro->startcv); |
1212 | PUTBACK; |
1228 | PUTBACK; |
1213 | PL_op = (OP *)&myop; |
1229 | PL_op = (OP *)&myop; |
1214 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
1230 | PL_op = PL_ppaddr[OP_ENTERSUB](aTHX); |
1215 | } |
1231 | } |
1216 | |
1232 | |
… | |
… | |
1364 | av_push (av, SvREFCNT_inc_NN (*bot++)); |
1380 | av_push (av, SvREFCNT_inc_NN (*bot++)); |
1365 | |
1381 | |
1366 | PL_runops = RUNOPS_DEFAULT; |
1382 | PL_runops = RUNOPS_DEFAULT; |
1367 | ENTER; |
1383 | ENTER; |
1368 | SAVETMPS; |
1384 | SAVETMPS; |
|
|
1385 | PUSHMARK (SP); |
1369 | EXTEND (SP, 3); |
1386 | EXTEND (SP, 3); |
1370 | PUSHMARK (SP); |
|
|
1371 | PUSHs (&PL_sv_no); |
1387 | PUSHs (&PL_sv_no); |
1372 | PUSHs (fullname); |
1388 | PUSHs (fullname); |
1373 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1389 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
1374 | PUTBACK; |
1390 | PUTBACK; |
1375 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1391 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
… | |
… | |
1402 | gv_efullname3 (fullname, gv, 0); |
1418 | gv_efullname3 (fullname, gv, 0); |
1403 | |
1419 | |
1404 | PL_runops = RUNOPS_DEFAULT; |
1420 | PL_runops = RUNOPS_DEFAULT; |
1405 | ENTER; |
1421 | ENTER; |
1406 | SAVETMPS; |
1422 | SAVETMPS; |
|
|
1423 | PUSHMARK (SP); |
1407 | EXTEND (SP, 3); |
1424 | EXTEND (SP, 3); |
1408 | PUSHMARK (SP); |
|
|
1409 | PUSHs (&PL_sv_yes); |
1425 | PUSHs (&PL_sv_yes); |
1410 | PUSHs (fullname); |
1426 | PUSHs (fullname); |
1411 | PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); |
1427 | PUSHs (CxHASARGS (cx) ? sv_2mortal (newRV_inc (SUB_ARGARRAY)) : &PL_sv_undef); |
1412 | PUTBACK; |
1428 | PUTBACK; |
1413 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1429 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
1414 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1430 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1415 | SPAGAIN; |
1431 | SPAGAIN; |
1416 | FREETMPS; |
1432 | FREETMPS; |
… | |
… | |
1426 | dSP; |
1442 | dSP; |
1427 | |
1443 | |
1428 | PL_runops = RUNOPS_DEFAULT; |
1444 | PL_runops = RUNOPS_DEFAULT; |
1429 | ENTER; |
1445 | ENTER; |
1430 | SAVETMPS; |
1446 | SAVETMPS; |
1431 | EXTEND (SP, 3); |
|
|
1432 | PL_runops = RUNOPS_DEFAULT; |
|
|
1433 | PUSHMARK (SP); |
1447 | PUSHMARK (SP); |
|
|
1448 | EXTEND (SP, 2); |
1434 | PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); |
1449 | PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); |
1435 | PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); |
1450 | PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); |
1436 | PUTBACK; |
1451 | PUTBACK; |
1437 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); |
1452 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); |
1438 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
1453 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
… | |
… | |
1538 | * coro body here, as perl_run destroys these. Likewise, we cannot catch |
1553 | * coro body here, as perl_run destroys these. Likewise, we cannot catch |
1539 | * runtime errors here, as this is just a random interpreter, not a thread. |
1554 | * runtime errors here, as this is just a random interpreter, not a thread. |
1540 | */ |
1555 | */ |
1541 | |
1556 | |
1542 | /* |
1557 | /* |
|
|
1558 | * pp_entersub in 5.24 no longer ENTERs, but perl_destruct |
|
|
1559 | * requires PL_scopestack_ix, so do it here if required. |
|
|
1560 | */ |
|
|
1561 | if (!PL_scopestack_ix) |
|
|
1562 | ENTER; |
|
|
1563 | |
|
|
1564 | /* |
1543 | * If perl-run returns we assume exit() was being called or the coro |
1565 | * If perl-run returns we assume exit() was being called or the coro |
1544 | * fell off the end, which seems to be the only valid (non-bug) |
1566 | * fell off the end, which seems to be the only valid (non-bug) |
1545 | * reason for perl_run to return. We try to mimic whatever perl is normally |
1567 | * reason for perl_run to return. We try to mimic whatever perl is normally |
1546 | * doing in that case. YMMV. |
1568 | * doing in that case. YMMV. |
1547 | */ |
1569 | */ |
… | |
… | |
2349 | safe_cancel (pTHX_ struct coro *coro, SV **arg, int items) |
2371 | safe_cancel (pTHX_ struct coro *coro, SV **arg, int items) |
2350 | { |
2372 | { |
2351 | if (coro->cctx) |
2373 | if (coro->cctx) |
2352 | croak ("coro inside C callback, unable to cancel at this time, caught"); |
2374 | croak ("coro inside C callback, unable to cancel at this time, caught"); |
2353 | |
2375 | |
2354 | if (coro->flags & CF_NEW) |
2376 | if (coro->flags & (CF_NEW | CF_ZOMBIE)) |
2355 | { |
2377 | { |
2356 | coro_set_status (aTHX_ coro, arg, items); |
2378 | coro_set_status (aTHX_ coro, arg, items); |
2357 | coro_state_destroy (aTHX_ coro); |
2379 | coro_state_destroy (aTHX_ coro); |
2358 | } |
2380 | } |
2359 | else |
2381 | else |
… | |
… | |
2428 | av_clear (GvAV (PL_defgv)); |
2450 | av_clear (GvAV (PL_defgv)); |
2429 | hv_store (hv, "desc", sizeof ("desc") - 1, SvREFCNT_inc_NN (sv_async_pool_idle), 0); |
2451 | hv_store (hv, "desc", sizeof ("desc") - 1, SvREFCNT_inc_NN (sv_async_pool_idle), 0); |
2430 | |
2452 | |
2431 | if (ecb_expect_false (coro->swap_sv)) |
2453 | if (ecb_expect_false (coro->swap_sv)) |
2432 | { |
2454 | { |
|
|
2455 | SWAP_SVS_LEAVE (coro); |
2433 | SvREFCNT_dec_NN (coro->swap_sv); |
2456 | SvREFCNT_dec_NN (coro->swap_sv); |
2434 | coro->swap_sv = 0; |
2457 | coro->swap_sv = 0; |
2435 | } |
2458 | } |
2436 | |
2459 | |
2437 | coro->prio = 0; |
2460 | coro->prio = 0; |
2438 | |
2461 | |
2439 | if (coro->cctx && ecb_expect_false (coro->cctx->flags & CC_TRACE)) |
2462 | if (ecb_expect_false (coro->cctx) && ecb_expect_false (coro->cctx->flags & CC_TRACE)) |
2440 | api_trace (aTHX_ coro_current, 0); |
2463 | api_trace (aTHX_ coro_current, 0); |
2441 | |
2464 | |
2442 | frame->prepare = prepare_schedule; |
2465 | frame->prepare = prepare_schedule; |
2443 | av_push (av_async_pool, SvREFCNT_inc (hv)); |
2466 | av_push (av_async_pool, SvREFCNT_inc (hv)); |
2444 | } |
2467 | } |
… | |
… | |
3573 | |
3596 | |
3574 | map_len = load_len + save_len + 16; |
3597 | map_len = load_len + save_len + 16; |
3575 | |
3598 | |
3576 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
3599 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
3577 | |
3600 | |
|
|
3601 | if (map_base == (char *)MAP_FAILED) |
|
|
3602 | map_base = mmap (0, map_len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
|
|
3603 | |
3578 | assert (("Coro: unable to mmap jit code page, cannot continue.", map_base != (char *)MAP_FAILED)); |
3604 | assert (("Coro: unable to mmap jit code page, cannot continue.", map_base != (char *)MAP_FAILED)); |
3579 | |
3605 | |
3580 | load_perl_slots = (load_save_perl_slots_type)map_base; |
3606 | load_perl_slots = (load_save_perl_slots_type)map_base; |
3581 | memcpy (map_base, load_ptr, load_len); |
3607 | memcpy (map_base, load_ptr, load_len); |
3582 | |
3608 | |
… | |
… | |
3618 | cctx_current = cctx_new_empty (); |
3644 | cctx_current = cctx_new_empty (); |
3619 | |
3645 | |
3620 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
3646 | irsgv = gv_fetchpv ("/" , GV_ADD|GV_NOTQUAL, SVt_PV); |
3621 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
3647 | stdoutgv = gv_fetchpv ("STDOUT", GV_ADD|GV_NOTQUAL, SVt_PVIO); |
3622 | |
3648 | |
3623 | orig_sigelem_get = PL_vtbl_sigelem.svt_get; PL_vtbl_sigelem.svt_get = coro_sigelem_get; |
3649 | { |
3624 | orig_sigelem_set = PL_vtbl_sigelem.svt_set; PL_vtbl_sigelem.svt_set = coro_sigelem_set; |
3650 | /* |
3625 | orig_sigelem_clr = PL_vtbl_sigelem.svt_clear; PL_vtbl_sigelem.svt_clear = coro_sigelem_clr; |
3651 | * we provide a vtbvl for %SIG magic that replaces PL_vtbl_sig |
|
|
3652 | * by coro_sig_vtbl in hash values. |
|
|
3653 | */ |
|
|
3654 | MAGIC *mg = mg_find ((SV *)GvHV (gv_fetchpv ("SIG", GV_ADD | GV_NOTQUAL, SVt_PVHV)), PERL_MAGIC_sig); |
|
|
3655 | |
|
|
3656 | /* this only works if perl doesn't have a vtbl for %SIG */ |
|
|
3657 | assert (!mg->mg_virtual); |
|
|
3658 | |
|
|
3659 | /* |
|
|
3660 | * The irony is that the perl API itself asserts that mg_virtual |
|
|
3661 | * must be non-const, yet perl5porters insisted on marking their |
|
|
3662 | * vtbls as read-only, just to thwart perl modules from patching |
|
|
3663 | * them. |
|
|
3664 | */ |
|
|
3665 | mg->mg_virtual = (MGVTBL *)&coro_sig_vtbl; |
|
|
3666 | mg->mg_flags |= MGf_COPY; |
|
|
3667 | |
|
|
3668 | coro_sigelem_vtbl = PL_vtbl_sigelem; |
|
|
3669 | coro_sigelem_vtbl.svt_get = coro_sigelem_get; |
|
|
3670 | coro_sigelem_vtbl.svt_set = coro_sigelem_set; |
|
|
3671 | coro_sigelem_vtbl.svt_clear = coro_sigelem_clr; |
|
|
3672 | } |
3626 | |
3673 | |
3627 | rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); |
3674 | rv_diehook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::diehook" , 0, SVt_PVCV)); |
3628 | rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); |
3675 | rv_warnhook = newRV_inc ((SV *)gv_fetchpv ("Coro::State::warnhook", 0, SVt_PVCV)); |
3629 | |
3676 | |
3630 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
3677 | coro_state_stash = gv_stashpv ("Coro::State", TRUE); |
… | |
… | |
4031 | coroapi.enterleave_hook = api_enterleave_hook; |
4078 | coroapi.enterleave_hook = api_enterleave_hook; |
4032 | coroapi.enterleave_unhook = api_enterleave_unhook; |
4079 | coroapi.enterleave_unhook = api_enterleave_unhook; |
4033 | coroapi.enterleave_scope_hook = api_enterleave_scope_hook; |
4080 | coroapi.enterleave_scope_hook = api_enterleave_scope_hook; |
4034 | |
4081 | |
4035 | /*GCoroAPI = &coroapi;*/ |
4082 | /*GCoroAPI = &coroapi;*/ |
4036 | sv_setiv (sv, (IV)&coroapi); |
4083 | sv_setiv (sv, PTR2IV (&coroapi)); |
4037 | SvREADONLY_on (sv); |
4084 | SvREADONLY_on (sv); |
4038 | } |
4085 | } |
4039 | } |
4086 | } |
4040 | |
4087 | |
4041 | SV * |
4088 | SV * |