From ad675a6ebcc6246c76d2a78a740f95397c7762f2 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Thu, 12 Dec 2019 15:36:19 -0800 Subject: [PATCH] Fix on-demand initialization race conditions [mini] (mono/mono#18161) Fix on-demand initialization race conditions [mini]. Extracted from https://github.com/mono/mono/pull/18150 which reviewer said was too big. Commit migrated from https://github.com/mono/mono/commit/51bc81919fea20c0a253d9c7f5d67ce4972bfeee --- src/mono/mono/mini/aot-compiler.c | 1 + src/mono/mono/mini/debugger-agent.c | 11 +++++++---- src/mono/mono/mini/method-to-ir.c | 1 + src/mono/mono/mini/mini-generic-sharing.c | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mono/mono/mini/aot-compiler.c b/src/mono/mono/mini/aot-compiler.c index 3160c2a..5ed944f 100644 --- a/src/mono/mono/mini/aot-compiler.c +++ b/src/mono/mono/mini/aot-compiler.c @@ -79,6 +79,7 @@ try_get_method_nofail (MonoClass *klass, const char *method_name, int param_coun return result; } +// FIXME Consolidate the multiple functions named get_method_nofail. static MonoMethod* get_method_nofail (MonoClass *klass, const char *method_name, int param_count, int flags) { diff --git a/src/mono/mono/mini/debugger-agent.c b/src/mono/mono/mini/debugger-agent.c index 60163d6..fe07a04 100644 --- a/src/mono/mono/mini/debugger-agent.c +++ b/src/mono/mono/mini/debugger-agent.c @@ -3545,21 +3545,24 @@ dbg_path_get_basename (const char *filename) static void init_jit_info_dbg_attrs (MonoJitInfo *ji) { - static MonoClass *hidden_klass, *step_through_klass, *non_user_klass; ERROR_DECL (error); MonoCustomAttrInfo *ainfo; if (ji->dbg_attrs_inited) return; - if (!hidden_klass) + MONO_STATIC_POINTER_INIT (MonoClass, hidden_klass) hidden_klass = mono_class_load_from_name (mono_defaults.corlib, "System.Diagnostics", "DebuggerHiddenAttribute"); + MONO_STATIC_POINTER_INIT_END (MonoClass, hidden_klass) - if (!step_through_klass) + + MONO_STATIC_POINTER_INIT (MonoClass, step_through_klass) step_through_klass = mono_class_load_from_name (mono_defaults.corlib, "System.Diagnostics", "DebuggerStepThroughAttribute"); + MONO_STATIC_POINTER_INIT_END (MonoClass, step_through_klass) - if (!non_user_klass) + MONO_STATIC_POINTER_INIT (MonoClass, non_user_klass) non_user_klass = mono_class_load_from_name (mono_defaults.corlib, "System.Diagnostics", "DebuggerNonUserCodeAttribute"); + MONO_STATIC_POINTER_INIT_END (MonoClass, non_user_klass) ainfo = mono_custom_attrs_from_method_checked (jinfo_get_method (ji), error); mono_error_cleanup (error); /* FIXME don't swallow the error? */ diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index 65e1947..095a233 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -2278,6 +2278,7 @@ emit_bad_image_failure (MonoCompile *cfg, MonoMethod *caller, MonoMethod *callee mono_emit_jit_icall (cfg, mono_throw_bad_image, NULL); } +// FIXME Consolidate the multiple functions named get_method_nofail. static MonoMethod* get_method_nofail (MonoClass *klass, const char *method_name, int num_params, int flags) { diff --git a/src/mono/mono/mini/mini-generic-sharing.c b/src/mono/mono/mini/mini-generic-sharing.c index e97d106..279fbaf 100644 --- a/src/mono/mono/mini/mini-generic-sharing.c +++ b/src/mono/mono/mini/mini-generic-sharing.c @@ -905,6 +905,7 @@ class_get_rgctx_template_oti (MonoClass *klass, int type_argc, guint32 slot, gbo } } +// FIXME Consolidate the multiple functions named get_method_nofail. static MonoMethod* get_method_nofail (MonoClass *klass, const char *method_name, int num_params, int flags) { -- 2.7.4