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

ruby-changes:74368

From: Yuta <ko1@a...>
Date: Sun, 6 Nov 2022 05:03:41 +0900 (JST)
Subject: [ruby-changes:74368] 3a6cdeda89 (master): [wasm] Scan machine stack based on `ec->machine.stack_{start, end}`

https://git.ruby-lang.org/ruby.git/commit/?id=3a6cdeda89

From 3a6cdeda89280ade714f158830acee88fb36306d Mon Sep 17 00:00:00 2001
From: Yuta Saito <kateinoigakukun@g...>
Date: Sat, 5 Nov 2022 16:10:35 +0000
Subject: [wasm] Scan machine stack based on `ec->machine.stack_{start,end}`

fiber machine stack is placed outside of C stack allocated by wasm-ld,
so highest stack address recorded by `rb_wasm_record_stack_base` is
invalid when running on non-main fiber.
Therefore, we should scan `stack_{start,end}` which always point a valid
stack range in any context.
---
 gc.c           | 6 ++++--
 thread_none.c  | 7 +++++++
 wasm/machine.c | 6 +++---
 wasm/machine.h | 5 ++---
 4 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/gc.c b/gc.c
index f2bccbca16..4adf86bf77 100644
--- a/gc.c
+++ b/gc.c
@@ -6756,8 +6756,10 @@ mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec https://github.com/ruby/ruby/blob/trunk/gc.c#L6756
 static void
 mark_current_machine_context(rb_objspace_t *objspace, rb_execution_context_t *ec)
 {
-    rb_wasm_scan_stack(rb_mark_locations);
-    each_stack_location(objspace, ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], gc_mark_maybe);
+    VALUE *stack_start, *stack_end;
+    SET_STACK_END;
+    GET_STACK_BOUNDS(stack_start, stack_end, 1);
+    each_stack_location(objspace, ec, stack_start, stack_end, gc_mark_maybe);
 
     rb_wasm_scan_locals(rb_mark_locations);
     each_stack_location(objspace, ec, rb_stack_range_tmp[0], rb_stack_range_tmp[1], gc_mark_maybe);
diff --git a/thread_none.c b/thread_none.c
index cf4658e571..a82ced684e 100644
--- a/thread_none.c
+++ b/thread_none.c
@@ -15,6 +15,10 @@ https://github.com/ruby/ruby/blob/trunk/thread_none.c#L15
 
 #include <time.h>
 
+#if defined(__wasm__) && !defined(__EMSCRIPTEN__)
+# include "wasm/machine.h"
+#endif
+
 #define TIME_QUANTUM_MSEC (100)
 #define TIME_QUANTUM_USEC (TIME_QUANTUM_MSEC * 1000)
 #define TIME_QUANTUM_NSEC (TIME_QUANTUM_USEC * 1000)
@@ -143,6 +147,9 @@ ruby_init_stack(volatile VALUE *addr) https://github.com/ruby/ruby/blob/trunk/thread_none.c#L147
 static int
 native_thread_init_stack(rb_thread_t *th)
 {
+#if defined(__wasm__) && !defined(__EMSCRIPTEN__)
+    th->ec->machine.stack_start = (VALUE *)rb_wasm_stack_get_base();
+#endif
     return 0; // success
 }
 
diff --git a/wasm/machine.c b/wasm/machine.c
index 238041f93e..2ca8462502 100644
--- a/wasm/machine.c
+++ b/wasm/machine.c
@@ -49,10 +49,10 @@ rb_wasm_record_stack_base(void) https://github.com/ruby/ruby/blob/trunk/wasm/machine.c#L49
     return 0;
 }
 
-void
-_rb_wasm_scan_stack(rb_wasm_scan_func scan, void *current)
+void *
+rb_wasm_stack_get_base(void)
 {
-    scan(current, rb_wasm_stack_base);
+    return rb_wasm_stack_base;
 }
 
 void *
diff --git a/wasm/machine.h b/wasm/machine.h
index 4cf7228684..1a60e51d11 100644
--- a/wasm/machine.h
+++ b/wasm/machine.h
@@ -8,9 +8,8 @@ typedef void (*rb_wasm_scan_func)(void*, void*); https://github.com/ruby/ruby/blob/trunk/wasm/machine.h#L8
 // Used by conservative GC
 void rb_wasm_scan_locals(rb_wasm_scan_func scan);
 
-// Scan userland C-stack memory space in WebAssembly. Used by conservative GC
-#define rb_wasm_scan_stack(scan) _rb_wasm_scan_stack((scan), rb_wasm_get_stack_pointer())
-void _rb_wasm_scan_stack(rb_wasm_scan_func scan, void *current);
+// Get base address of userland C-stack memory space in WebAssembly. Used by conservative GC
+void *rb_wasm_stack_get_base(void);
 
 
 // Get the current stack pointer
-- 
cgit v1.2.3


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

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