Skip to content

Commit f408cb4

Browse files
Copy the NativeAOT AllocateTypeAssociatedMemory to Mono
Found in dotnet#99019
1 parent 7608b3a commit f408cb4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.Mono.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ public static void RunModuleConstructor(ModuleHandle module)
139139

140140
public static IntPtr AllocateTypeAssociatedMemory(Type type, int size)
141141
{
142-
throw new PlatformNotSupportedException();
142+
if (type is not RuntimeType)
143+
throw new ArgumentException(SR.Arg_MustBeType, nameof(type));
144+
145+
ArgumentOutOfRangeException.ThrowIfNegative(size);
146+
147+
// We don't support unloading; the memory will never be freed.
148+
return (IntPtr)NativeMemory.AllocZeroed((uint)size);
143149
}
144150

145151
[Intrinsic]

0 commit comments

Comments
 (0)