From e27401501809a8ba451f4621657908cbb6664493 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Mon, 23 Nov 2020 12:25:52 -0500 Subject: [PATCH] Add support for stack walks on wasm for the reflection methods which need them. (#45076) Fixes https://github.com/dotnet/runtime/issues/44269. --- src/mono/mono/mini/method-to-ir.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index 1586923d8037d..d738e7d7466a5 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -3489,6 +3489,22 @@ method_needs_stack_walk (MonoCompile *cfg, MonoMethod *cmethod) if (!strcmp (cmethod->name, "GetType")) return TRUE; } + +#if defined(ENABLE_NETCORE) + /* + * In corelib code, methods which need to do a stack walk declare a StackCrawlMark local and pass it as an + * arguments until it reaches an icall. Its hard to detect which methods do that especially with + * StackCrawlMark.LookForMyCallersCaller, so for now, just hardcode the classes which contain the public + * methods whose caller is needed. + */ + if (mono_is_corlib_image (m_class_get_image (cmethod->klass))) { + const char *cname = m_class_get_name (cmethod->klass); + if (!strcmp (cname, "Assembly") || + !strcmp (cname, "AssemblyLoadContext") || + (!strcmp (cname, "Activator"))) + return TRUE; + } +#endif return FALSE; }