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