Skip to content

[mono] Implement missing functionality for cctor invocation #73955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void Invoke_StaticConstructor_NullObject_NullParameters()
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsInvokingStaticConstructorsSupported))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/40351", TestRuntimes.Mono)]
public void Invoke_StaticConstructorMultipleTimes()
{
ConstructorInfo[] constructors = GetConstructors(typeof(ClassWithStaticConstructorThatIsCalledMultipleTimesViaReflection));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,13 @@ internal RuntimeType[] ArgumentTypes
}
}

private static void InvokeClassConstructor()
[MethodImplAttribute(MethodImplOptions.InternalCall)]
internal static extern void InvokeClassConstructor(QCallTypeHandle type);

private void InvokeClassConstructor()
{
// [TODO] Mechanism for invoking class constructor
// See https://github.com/dotnet/runtime/issues/40351
RuntimeType type = (RuntimeType)DeclaringType;
InvokeClassConstructor(new QCallTypeHandle(ref type));
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/mono/mono/metadata/icall-def.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ HANDLES(RASSEM_7, "InternalGetReferencedAssemblies", ves_icall_System_Reflection
ICALL_TYPE(MCMETH, "System.Reflection.RuntimeConstructorInfo", MCMETH_1)
HANDLES(MCMETH_1, "GetGenericMethodDefinition_impl", ves_icall_RuntimeMethodInfo_GetGenericMethodDefinition, MonoReflectionMethod, 1, (MonoReflectionMethod))
HANDLES(MCMETH_2, "InternalInvoke", ves_icall_InternalInvoke, MonoObject, 4, (MonoReflectionMethod, MonoObject, MonoSpanOfObjects_ref, MonoExceptionOut))
HANDLES(MCMETH_5, "InvokeClassConstructor", ves_icall_InvokeClassConstructor, void, 1, (MonoQCallTypeHandle))
HANDLES_REUSE_WRAPPER(MCMETH_4, "get_metadata_token", ves_icall_reflection_get_token)

ICALL_TYPE(CATTR_DATA, "System.Reflection.RuntimeCustomAttributeData", CATTR_DATA_1)
Expand Down
12 changes: 12 additions & 0 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,18 @@ ves_icall_RuntimeTypeHandle_IsComObject (MonoQCallTypeHandle type_handle, MonoEr
return mono_class_is_com_object (klass);
}

void
ves_icall_InvokeClassConstructor (MonoQCallTypeHandle type_handle, MonoError *error)
{
MonoType *type = type_handle.type;
MonoClass *klass = mono_class_from_mono_type_internal (type);

MonoVTable *vtable = mono_class_vtable_checked (klass, error);
return_if_nok (error);

mono_runtime_class_init_full (vtable, error);
}

guint32
ves_icall_reflection_get_token (MonoObjectHandle obj, MonoError *error)
{
Expand Down