diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs index 0aea60fd1921e0..5148ca0c488d80 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Runtime/CompilerServices/RuntimeHelpersTests.cs @@ -394,7 +394,6 @@ public static void ArrayGetSubArrayCoVarianceTest() } [Fact] - [SkipOnMono("Not presently implemented on Mono")] public static void AllocateTypeAssociatedMemoryInvalidArguments() { Assert.Throws(() => { RuntimeHelpers.AllocateTypeAssociatedMemory(null, 10); }); @@ -402,7 +401,6 @@ public static void AllocateTypeAssociatedMemoryInvalidArguments() } [Fact] - [SkipOnMono("Not presently implemented on Mono")] public static unsafe void AllocateTypeAssociatedMemoryValidArguments() { IntPtr memory = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(RuntimeHelpersTests), 32); 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..ca9ecdbe9f829c 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 @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Tracing; +using System.Runtime.InteropServices; using System.Runtime.Serialization; namespace System.Runtime.CompilerServices @@ -137,9 +138,15 @@ public static void RunModuleConstructor(ModuleHandle module) RunModuleConstructor(module.Value); } - public static IntPtr AllocateTypeAssociatedMemory(Type type, int size) + public static unsafe 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]