6daba0
From 0ade5611df9f981005eed32b369d1e699e520221 Mon Sep 17 00:00:00 2001
6daba0
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
6daba0
Date: Thu, 10 Feb 2022 13:26:44 +0100
6daba0
Subject: [PATCH] Don't query `RubyVM::FrozenCore` for class path.
6daba0
6daba0
The `RubyVM::FrozenCore` class path is corrupted during GC cycle and
6daba0
returns random garbage, which might result in segfault.
6daba0
6daba0
But since it is easy to detect the `RubyVM::FrozenCore`, just provide
6daba0
the class path explicitly as a workaround.
6daba0
6daba0
Other possibility would be to ignore `RubyVM::FrozenCore` simlarly as
6daba0
TracePoint API does:
6daba0
6daba0
https://github.com/ruby/ruby/blob/46f6575157d4c2f6bbd5693896e26a65037e5552/vm_trace.c#L411
6daba0
---
6daba0
 vm.c | 10 +++++++++-
6daba0
 1 file changed, 9 insertions(+), 1 deletion(-)
6daba0
6daba0
diff --git a/vm.c b/vm.c
6daba0
index 8ce8b279d4..3d189fa63a 100644
6daba0
--- a/vm.c
6daba0
+++ b/vm.c
6daba0
@@ -446,7 +446,15 @@ rb_dtrace_setup(rb_execution_context_t *ec, VALUE klass, ID id,
6daba0
     }
6daba0
     type = BUILTIN_TYPE(klass);
6daba0
     if (type == T_CLASS || type == T_ICLASS || type == T_MODULE) {
6daba0
-	VALUE name = rb_class_path(klass);
6daba0
+	VALUE name = Qnil;
6daba0
+	/*
6daba0
+	 * Special treatment for rb_mRubyVMFrozenCore wchi is broken by GC.
6daba0
+         * https://bugs.ruby-lang.org/issues/18257
6daba0
+	 */
6daba0
+	if (klass == rb_mRubyVMFrozenCore)
6daba0
+	    name = rb_str_new_cstr("RubyVM::FrozenCore");
6daba0
+	else
6daba0
+	    name = rb_class_path(klass);
6daba0
 	const char *classname, *filename;
6daba0
 	const char *methodname = rb_id2name(id);
6daba0
 	if (methodname && (filename = rb_source_location_cstr(&args->line_no)) != 0) {
6daba0
-- 
6daba0
2.34.1
6daba0