Skip to content
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 @@ -394,15 +394,13 @@ public static void ArrayGetSubArrayCoVarianceTest()
}

[Fact]
[SkipOnMono("Not presently implemented on Mono")]
public static void AllocateTypeAssociatedMemoryInvalidArguments()
{
Assert.Throws<ArgumentException>(() => { RuntimeHelpers.AllocateTypeAssociatedMemory(null, 10); });
Assert.Throws<ArgumentOutOfRangeException>(() => { RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(RuntimeHelpersTests), -1); });
}

[Fact]
[SkipOnMono("Not presently implemented on Mono")]
public static unsafe void AllocateTypeAssociatedMemoryValidArguments()
{
IntPtr memory = RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(RuntimeHelpersTests), 32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down