[前][次][番号順一覧][スレッド一覧]

ruby-changes:72615

From: Aaron <ko1@a...>
Date: Thu, 21 Jul 2022 05:46:11 +0900 (JST)
Subject: [ruby-changes:72615] 1341dea771 (master): Prevent the stack from being marked twice

https://git.ruby-lang.org/ruby.git/commit/?id=1341dea771

From 1341dea7711ae80aa4c232503fbb5a1be48b648b Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Tue, 12 Jul 2022 16:42:14 -0700
Subject: Prevent the stack from being marked twice

This commit prevents the stack from being marked twice: once via the
Fiber, and once via the Thread.  It introduces an assertion to assert
that the ec on the thread is the same as the ec on the Fiber being
marked via the thread.
---
 cont.c          | 6 ++++++
 internal/cont.h | 2 ++
 vm.c            | 3 +--
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/cont.c b/cont.c
index 36f47d9ee6..590d6c250f 100644
--- a/cont.c
+++ b/cont.c
@@ -1194,6 +1194,12 @@ cont_init_mjit_cont(rb_context_t *cont) https://github.com/ruby/ruby/blob/trunk/cont.c#L1194
     }
 }
 
+struct rb_execution_context_struct *
+rb_fiberptr_get_ec(struct rb_fiber_struct *fiber)
+{
+    return &fiber->cont.saved_ec;
+}
+
 static void
 cont_init(rb_context_t *cont, rb_thread_t *th)
 {
diff --git a/internal/cont.h b/internal/cont.h
index 5ab120e9ab..abffc97104 100644
--- a/internal/cont.h
+++ b/internal/cont.h
@@ -12,6 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/internal/cont.h#L12
 
 struct rb_thread_struct;        /* in vm_core.h */
 struct rb_fiber_struct;         /* in cont.c */
+struct rb_execution_context_struct; /* in vm_core.c */
 
 /* cont.c */
 void rb_fiber_reset_root_local_storage(struct rb_thread_struct *);
@@ -20,5 +21,6 @@ void rb_fiber_init_mjit_cont(struct rb_fiber_struct *fiber); https://github.com/ruby/ruby/blob/trunk/internal/cont.h#L21
 
 VALUE rb_fiberptr_self(struct rb_fiber_struct *fiber);
 unsigned int rb_fiberptr_blocking(struct rb_fiber_struct *fiber);
+struct rb_execution_context_struct * rb_fiberptr_get_ec(struct rb_fiber_struct *fiber);
 
 #endif /* INTERNAL_CONT_H */
diff --git a/vm.c b/vm.c
index c2dda3fdc4..4538c8b607 100644
--- a/vm.c
+++ b/vm.c
@@ -3138,8 +3138,7 @@ thread_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/vm.c#L3138
     RUBY_MARK_UNLESS_NULL(th->top_wrapper);
     if (th->root_fiber) rb_fiber_mark_self(th->root_fiber);
 
-    /* Ensure EC stack objects are pinned */
-    rb_execution_context_mark(th->ec);
+    RUBY_ASSERT(th->ec == rb_fiberptr_get_ec(th->ec->fiber_ptr));
     RUBY_MARK_UNLESS_NULL(th->stat_insn_usage);
     RUBY_MARK_UNLESS_NULL(th->last_status);
     RUBY_MARK_UNLESS_NULL(th->locking_mutex);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]