Skip to content

Commit

Permalink
Make rb_profile_frames return 0 for NULL ec
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jhawthorn and dustinbrownman committed Dec 21, 2023
1 parent 78b27ce commit ffa5f16
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion vm_backtrace.c
Expand Up @@ -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);
}

Expand Down

0 comments on commit ffa5f16

Please sign in to comment.