File tree 1 file changed +45
-0
lines changed
1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -1511,6 +1511,51 @@ cont_restore_thread(rb_context_t *cont)
1511
1511
rb_raise (rb_eRuntimeError , "can't call across trace_func" );
1512
1512
}
1513
1513
1514
+ #if defined(__wasm__ ) && !defined(__EMSCRIPTEN__ )
1515
+ if (th -> ec -> tag != sec -> tag ) {
1516
+ /* find the lowest common ancestor tag of the current EC and the saved EC */
1517
+
1518
+ struct rb_vm_tag * lowest_common_ancestor = NULL ;
1519
+ size_t num_tags = 0 ;
1520
+ size_t num_saved_tags = 0 ;
1521
+ for (struct rb_vm_tag * tag = th -> ec -> tag ; tag != NULL ; tag = tag -> prev ) {
1522
+ ++ num_tags ;
1523
+ }
1524
+ for (struct rb_vm_tag * tag = sec -> tag ; tag != NULL ; tag = tag -> prev ) {
1525
+ ++ num_saved_tags ;
1526
+ }
1527
+
1528
+ size_t min_tags = num_tags <= num_saved_tags ? num_tags : num_saved_tags ;
1529
+
1530
+ struct rb_vm_tag * tag = th -> ec -> tag ;
1531
+ while (num_tags > min_tags ) {
1532
+ tag = tag -> prev ;
1533
+ -- num_tags ;
1534
+ }
1535
+
1536
+ struct rb_vm_tag * saved_tag = sec -> tag ;
1537
+ while (num_saved_tags > min_tags ) {
1538
+ saved_tag = saved_tag -> prev ;
1539
+ -- num_saved_tags ;
1540
+ }
1541
+
1542
+ while (min_tags > 0 ) {
1543
+ if (tag == saved_tag ) {
1544
+ lowest_common_ancestor = tag ;
1545
+ break ;
1546
+ }
1547
+ tag = tag -> prev ;
1548
+ saved_tag = saved_tag -> prev ;
1549
+ -- min_tags ;
1550
+ }
1551
+
1552
+ /* free all the jump buffers between the current EC's tag and the lowest common ancestor tag */
1553
+ for (struct rb_vm_tag * tag = th -> ec -> tag ; tag != lowest_common_ancestor ; tag = tag -> prev ) {
1554
+ rb_vm_tag_jmpbuf_deinit (& tag -> buf );
1555
+ }
1556
+ }
1557
+ #endif
1558
+
1514
1559
/* copy vm stack */
1515
1560
#ifdef CAPTURE_JUST_VALID_VM_STACK
1516
1561
MEMCPY (th -> ec -> vm_stack ,
You can’t perform that action at this time.
0 commit comments