From 48d3bdddbaeabed5fb6a97bfbe65e250d1383a9c Mon Sep 17 00:00:00 2001 From: KJ Tsanaktsidis Date: Sat, 24 Feb 2024 19:31:27 +1100 Subject: [PATCH] Move asan_fake_stack_handle to EC, not thread It's really a property of the EC; each fiber (which has its own EC) also has its own asan_fake_stack_handle. [Bug #20310] --- gc.c | 2 +- thread.c | 3 --- thread_pthread.c | 1 + vm_core.h | 9 ++++----- 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/gc.c b/gc.c index eaa98928ff..07c0735a44 100644 --- a/gc.c +++ b/gc.c @@ -6410,7 +6410,7 @@ gc_mark_machine_stack_location_maybe(rb_objspace_t *objspace, VALUE obj) void *fake_frame_start; void *fake_frame_end; bool is_fake_frame = asan_get_fake_stack_extents( - ec->thread_ptr->asan_fake_stack_handle, obj, + ec->machine.asan_fake_stack_handle, obj, ec->machine.stack_start, ec->machine.stack_end, &fake_frame_start, &fake_frame_end ); diff --git a/thread.c b/thread.c index b8dd862634..e672172a4d 100644 --- a/thread.c +++ b/thread.c @@ -527,9 +527,6 @@ void ruby_thread_init_stack(rb_thread_t *th, void *local_in_parent_frame) { native_thread_init_stack(th, local_in_parent_frame); -#ifdef RUBY_ASAN_ENABLED - th->asan_fake_stack_handle = asan_get_thread_fake_stack_handle(); -#endif } const VALUE * diff --git a/thread_pthread.c b/thread_pthread.c index fb446eee82..cdaf6f240c 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -2081,6 +2081,7 @@ native_thread_init_stack(rb_thread_t *th, void *local_in_parent_frame) rb_nativethread_id_t curr = pthread_self(); #ifdef RUBY_ASAN_ENABLED local_in_parent_frame = asan_get_real_stack_addr(local_in_parent_frame); + th->ec->machine.asan_fake_stack_handle = asan_get_thread_fake_stack_handle(); #endif if (!native_main_thread.id) { diff --git a/vm_core.h b/vm_core.h index da1f568b66..805df18616 100644 --- a/vm_core.h +++ b/vm_core.h @@ -1044,6 +1044,10 @@ struct rb_execution_context_struct { VALUE *stack_end; size_t stack_maxsize; RUBY_ALIGNAS(SIZEOF_VALUE) jmp_buf regs; + +#ifdef RUBY_ASAN_ENABLED + void *asan_fake_stack_handle; +#endif } machine; }; @@ -1164,11 +1168,6 @@ typedef struct rb_thread_struct { void **specific_storage; struct rb_ext_config ext_config; - -#ifdef RUBY_ASAN_ENABLED - void *asan_fake_stack_handle; -#endif - } rb_thread_t; static inline unsigned int