From 36428bf4c948f01c6a6b8a67ef50c89770532f71 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Sun, 7 Apr 2019 17:20:31 -0400 Subject: [PATCH] [jit] Disable inlining for methods with [System.Security.DynamicSecurityMethod], its used to make methods which contain a StackCrawlMark. Also check that the attribute is present for StackMaekMark locals. Commit migrated from https://github.com/mono/mono/commit/8b1a18784dd17b1a683f3d73ecb51d5b2c7f974f --- src/mono/mono/metadata/tabledefs.h | 2 ++ src/mono/mono/mini/method-to-ir.c | 4 ++++ src/mono/mono/mini/mini.c | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/mono/mono/metadata/tabledefs.h b/src/mono/mono/metadata/tabledefs.h index e3aa51b..6cfc4c8 100644 --- a/src/mono/mono/metadata/tabledefs.h +++ b/src/mono/mono/metadata/tabledefs.h @@ -190,6 +190,8 @@ enum { #define METHOD_ATTRIBUTE_PINVOKE_IMPL 0x2000 #define METHOD_ATTRIBUTE_UNMANAGED_EXPORT 0x0008 +#define METHOD_ATTRIBUTE_REQSECOBJ 0x8000 + /* * For runtime use only */ diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index 01e794e..232af91 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -3760,6 +3760,10 @@ mono_method_check_inlining (MonoCompile *cfg, MonoMethod *method) header.has_clauses) return FALSE; + if (cfg->method->flags & METHOD_ATTRIBUTE_REQSECOBJ) + /* Used to mark methods containing StackCrawlMark locals */ + return FALSE; + /* also consider num_locals? */ /* Do the size check early to avoid creating vtables */ if (!inline_limit_inited) { diff --git a/src/mono/mono/mini/mini.c b/src/mono/mono/mini/mini.c index 8effde3..40f5e6a 100644 --- a/src/mono/mono/mini/mini.c +++ b/src/mono/mono/mini/mini.c @@ -746,6 +746,7 @@ mono_compile_create_var_for_vreg (MonoCompile *cfg, MonoType *type, int opcode, cfg->num_varinfo++; if (cfg->verbose_level > 2) g_print ("created temp %d (R%d) of type %s\n", num, vreg, mono_type_get_name (type)); + return inst; } @@ -753,6 +754,17 @@ MonoInst* mono_compile_create_var (MonoCompile *cfg, MonoType *type, int opcode) { int dreg; + +#ifdef ENABLE_NETCORE + if (type->type == MONO_TYPE_VALUETYPE && !type->byref) { + MonoClass *klass = mono_class_from_mono_type_internal (type); + if (m_class_is_enumtype (klass) && m_class_get_image (klass) == mono_get_corlib () && !strcmp (m_class_get_name (klass), "StackCrawlMark")) { + if (!(cfg->method->flags & METHOD_ATTRIBUTE_REQSECOBJ)) + g_error ("Method '%s' which contains a StackCrawlMark local variable must be decorated with [System.Security.DynamicSecurityMethod].", mono_method_get_full_name (cfg->method)); + } + } +#endif + type = mini_get_underlying_type (type); if (mono_type_is_long (type)) -- 2.7.4