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

ruby-changes:71957

From: Samuel <ko1@a...>
Date: Wed, 25 May 2022 18:51:05 +0900 (JST)
Subject: [ruby-changes:71957] 86602484a2 (master): Ensure we retain the main fiber stack bounds.

https://git.ruby-lang.org/ruby.git/commit/?id=86602484a2

From 86602484a28fe345d9d164fe33d765d5e2791c58 Mon Sep 17 00:00:00 2001
From: Samuel Williams <samuel.williams@o...>
Date: Wed, 25 May 2022 18:13:04 +1200
Subject: Ensure we retain the main fiber stack bounds.

---
 cont.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/cont.c b/cont.c
index 12d79726ad..fba292ae9d 100644
--- a/cont.c
+++ b/cont.c
@@ -739,7 +739,8 @@ fiber_pool_stack_release(struct fiber_pool_stack * stack) https://github.com/ruby/ruby/blob/trunk/cont.c#L739
         fiber_pool_stack_free(&vacancy->stack);
     }
 #else
-    // This is entirely optional, but clears the dirty flag from the stack memory, so it won't get swapped to disk when there is memory pressure:
+    // This is entirely optional, but clears the dirty flag from the stack
+    // memory, so it won't get swapped to disk when there is memory pressure:
     if (stack->pool->free_stacks) {
         fiber_pool_stack_free(&vacancy->stack);
     }
@@ -778,7 +779,16 @@ fiber_entry(struct coroutine_context * from, struct coroutine_context * to) https://github.com/ruby/ruby/blob/trunk/cont.c#L779
     rb_fiber_t *fiber = to->argument;
 
 #if defined(COROUTINE_SANITIZE_ADDRESS)
-    __sanitizer_finish_switch_fiber(to->fake_stack, NULL, NULL);
+    // Address sanitizer will copy the previous stack base and stack size into
+    // the "from" fiber. `coroutine_initialize_main` doesn't generally know the
+    // stack bounds (base + size). Therefore, the main fiber `stack_base` and
+    // `stack_size` will be NULL/0. It's specifically important in that case to
+    // get the (base+size) of the previous fiber and save it, so that later when
+    // we return to the main coroutine, we don't supply (NULL, 0) to
+    // __sanitizer_start_switch_fiber which royally messes up the internal state
+    // of ASAN and causes (sometimes) the following message:
+    // "WARNING: ASan is ignoring requested __asan_handle_no_return"
+    __sanitizer_finish_switch_fiber(to->fake_stack, (const void**)&from->stack_base, &from->stack_size);
 #endif
 
     rb_thread_t *thread = fiber->cont.saved_ec.thread_ptr;
@@ -821,7 +831,8 @@ fiber_initialize_coroutine(rb_fiber_t *fiber, size_t * vm_stack_size) https://github.com/ruby/ruby/blob/trunk/cont.c#L831
     return vm_stack;
 }
 
-// Release the stack from the fiber, it's execution context, and return it to the fiber pool.
+// Release the stack from the fiber, it's execution context, and return it to
+// the fiber pool.
 static void
 fiber_stack_release(rb_fiber_t * fiber)
 {
-- 
cgit v1.2.1


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

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