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>
This commit is contained in:
John Hawthorn 2023-12-20 13:54:32 -08:00
parent 78b27ce62a
commit ffa5f16273

View File

@ -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);
}