From f408cb40e289919bca355e5da01aba71305df2ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= <35800402+MichalPetryka@users.noreply.github.com> Date: Wed, 28 Feb 2024 20:36:33 +0100 Subject: [PATCH] Copy the NativeAOT AllocateTypeAssociatedMemory to Mono Found in #99019 --- .../Runtime/CompilerServices/RuntimeHelpers.Mono.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs index 391bfaec6a2a46..030a24a0d3ec05 100644 --- a/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs @@ -139,7 +139,13 @@ public static void RunModuleConstructor(ModuleHandle module) public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) { - throw new PlatformNotSupportedException(); + if (type is not RuntimeType) + throw new ArgumentException(SR.Arg_MustBeType, nameof(type)); + + ArgumentOutOfRangeException.ThrowIfNegative(size); + + // We don't support unloading; the memory will never be freed. + return (IntPtr)NativeMemory.AllocZeroed((uint)size); } [Intrinsic]