summaryrefslogtreecommitdiff
path: root/vm_backtrace.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2023-12-20 13:54:32 -0800
committerJohn Hawthorn <john@hawthorn.email>2023-12-21 15:23:19 -0800
commitffa5f16273f46c97bfca56e4549b0b38b9322d63 (patch)
treea81aa4e9058bddb21a9b49f9ac01b9d7571d0117 /vm_backtrace.c
parent78b27ce62a7d6f28c73d6fb4f97b0948859be8e0 (diff)
Make rb_profile_frames return 0 for NULL ec
When using M:N threads, EC is set to NULL in the shared native thread when nothing is scheduled. This previously caused a segfault when we try to examine the EC. Returning 0 instead means we may miss profiling information, but a profiler relying on this isn't thread aware anyways, and observing that "nothing" is running is probably correct. Fixes [Bug #20017] Co-authored-by: Dustin Brown <dbrown9@gmail.com>
Diffstat (limited to 'vm_backtrace.c')
-rw-r--r--vm_backtrace.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/vm_backtrace.c b/vm_backtrace.c
index 0d55eae042..6e9436f76a 100644
--- a/vm_backtrace.c
+++ b/vm_backtrace.c
@@ -1641,7 +1641,14 @@ thread_profile_frames(rb_execution_context_t *ec, int start, int limit, VALUE *b
int
rb_profile_frames(int start, int limit, VALUE *buff, int *lines)
{
- rb_execution_context_t *ec = GET_EC();
+ rb_execution_context_t *ec = rb_current_execution_context(false);
+
+ // If there is no EC, we may be attempting to profile a non-Ruby thread or a
+ // M:N shared native thread which has no active Ruby thread.
+ if (!ec) {
+ return 0;
+ }
+
return thread_profile_frames(ec, start, limit, buff, lines);
}