Skip to content

Commit f313e8d

Browse files
authored
[mono][interp] Disable inlining of methods that call methods using StackCrawlMark (#116134)
* [mono][interp] Don't inline callers of methods using StackCrawlMark * [mono] Disable inlining of callers of Assembly.GetCallingAssembly The stack mark is used only to prevent inlining of the callers of this method (since it sets a flag on the method in question). The stack mark itself is not currently used on mono.
1 parent a745f28 commit f313e8d

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/mono/System.Private.CoreLib/src/System/Reflection/Assembly.Mono.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ public static Assembly GetExecutingAssembly()
4242
[MethodImplAttribute(MethodImplOptions.InternalCall)]
4343
internal static extern RuntimeAssembly GetExecutingAssembly(ref StackCrawlMark stackMark);
4444

45-
[MethodImplAttribute(MethodImplOptions.InternalCall)]
4645
[System.Security.DynamicSecurityMethod] // Methods doing stack walks has to be marked DynamicSecurityMethod
47-
public static extern Assembly GetCallingAssembly();
46+
public static Assembly GetCallingAssembly()
47+
{
48+
StackCrawlMark stackMark = StackCrawlMark.LookForMyCallersCaller;
49+
return GetCallingAssembly(ref stackMark);
50+
}
51+
52+
[MethodImplAttribute(MethodImplOptions.InternalCall)]
53+
internal static extern RuntimeAssembly GetCallingAssembly(ref StackCrawlMark stackMark);
4854

4955
[MethodImplAttribute(MethodImplOptions.InternalCall)]
5056
internal static extern Assembly GetEntryAssemblyNative();

src/mono/mono/metadata/icall-def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ ICALL_TYPE(OBJ, "System.Object", OBJ_3)
284284
HANDLES(OBJ_3, "MemberwiseClone", ves_icall_System_Object_MemberwiseClone, MonoObject, 1, (MonoObject))
285285

286286
ICALL_TYPE(ASSEM, "System.Reflection.Assembly", ASSEM_2)
287-
HANDLES(ASSEM_2, "GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly, MonoReflectionAssembly, 0, ())
287+
HANDLES(ASSEM_2, "GetCallingAssembly", ves_icall_System_Reflection_Assembly_GetCallingAssembly, MonoReflectionAssembly, 1, (MonoStackCrawlMark_ptr))
288288
HANDLES(ASSEM_3, "GetEntryAssemblyNative", ves_icall_System_Reflection_Assembly_GetEntryAssembly, MonoReflectionAssembly, 0, ())
289289
HANDLES(ASSEM_4, "GetExecutingAssembly", ves_icall_System_Reflection_Assembly_GetExecutingAssembly, MonoReflectionAssembly, 1, (MonoStackCrawlMark_ptr))
290290
HANDLES(ASSEM_6, "InternalGetType", ves_icall_System_Reflection_Assembly_InternalGetType, MonoReflectionType, 5, (MonoReflectionAssembly, MonoReflectionModule, MonoString, MonoBoolean, MonoBoolean))

src/mono/mono/metadata/icall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5145,7 +5145,7 @@ ves_icall_System_Reflection_Assembly_GetEntryAssembly (MonoError *error)
51455145
}
51465146

51475147
MonoReflectionAssemblyHandle
5148-
ves_icall_System_Reflection_Assembly_GetCallingAssembly (MonoError *error)
5148+
ves_icall_System_Reflection_Assembly_GetCallingAssembly (MonoStackCrawlMark *stack_mark, MonoError *error)
51495149
{
51505150
MonoMethod *m;
51515151
MonoMethod *dest;

src/mono/mono/mini/interp/transform.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,6 +3849,8 @@ interp_transform_call (TransformData *td, MonoMethod *method, MonoMethod *target
38493849
} else if (td->method->wrapper_type == MONO_WRAPPER_RUNTIME_INVOKE) {
38503850
// This scenario causes https://github.com/dotnet/runtime/issues/83792
38513851
return FALSE;
3852+
} else if (target_method->flags & METHOD_ATTRIBUTE_REQSECOBJ) {
3853+
return FALSE;
38523854
} else if (has_doesnotreturn_attribute(target_method)) {
38533855
/*
38543856
* Since the method does not return, it's probably a throw helper and will not be called.

0 commit comments

Comments
 (0)