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
12 changes: 6 additions & 6 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2154,14 +2154,14 @@ private uint getClassAttribsInternal(TypeDesc type)
private void* LongLifetimeMalloc(UIntPtr sz)
#pragma warning restore CA1822 // Mark members as static
{
return (void*)Marshal.AllocCoTaskMem((int)sz);
return NativeMemory.Alloc(sz);
}

#pragma warning disable CA1822 // Mark members as static
private void LongLifetimeFree(void* obj)
#pragma warning restore CA1822 // Mark members as static
{
Marshal.FreeCoTaskMem((IntPtr)obj);
NativeMemory.Free(obj);
}

private UIntPtr getClassStaticDynamicInfo(CORINFO_CLASS_STRUCT_* cls)
Expand Down Expand Up @@ -3211,8 +3211,8 @@ private void getVars(CORINFO_METHOD_STRUCT_* ftn, ref uint cVars, ILVarInfo** va
private void reportRichMappings(InlineTreeNode* inlineTree, uint numInlineTree, RichOffsetMapping* mappings, uint numMappings)
#pragma warning restore CA1822 // Mark members as static
{
Marshal.FreeHGlobal((IntPtr)inlineTree);
Marshal.FreeHGlobal((IntPtr)mappings);
NativeMemory.Free(inlineTree);
NativeMemory.Free(mappings);
}

#pragma warning disable CA1822 // Mark members as static
Expand All @@ -3225,14 +3225,14 @@ private void reportMetadata(byte* key, void* value, nuint length)
private void* allocateArray(UIntPtr cBytes)
#pragma warning restore CA1822 // Mark members as static
{
return (void*)Marshal.AllocHGlobal((IntPtr)(void*)cBytes);
return NativeMemory.Alloc(cBytes);
}

#pragma warning disable CA1822 // Mark members as static
private void freeArray(void* array)
#pragma warning restore CA1822 // Mark members as static
{
Marshal.FreeHGlobal((IntPtr)array);
NativeMemory.Free(array);
}

#pragma warning disable CA1822 // Mark members as static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2606,7 +2606,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_

private static IntPtr GetUnmanagedCallbacks()
{
void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 176);
void** callbacks = (void**)NativeMemory.Alloc((nuint)(sizeof(void*) * 176));

callbacks[0] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, byte>)&_isIntrinsic;
callbacks[1] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_METHOD_STRUCT_*, byte>)&_notifyMethodInfoUsage;
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/tools/Common/JitInterface/JitConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ private static unsafe IntPtr CreateUnmanagedInstance()

const int numCallbacks = 2;

void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * numCallbacks);
void** callbacks = (void**)NativeMemory.Alloc((nuint)(sizeof(void*) * numCallbacks));

callbacks[0] = (delegate* unmanaged<IntPtr, byte*, int, int>)&getIntConfigValue;
callbacks[1] = (delegate* unmanaged<IntPtr, byte*, byte*, int, int>)&getStringConfigValue;

IntPtr instance = Marshal.AllocCoTaskMem(sizeof(IntPtr));
IntPtr instance = (IntPtr)NativeMemory.Alloc((nuint)sizeof(IntPtr));
*(IntPtr*)instance = (IntPtr)callbacks;

return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ internal unsafe partial class CorInfoImpl
tw.WriteLine(@"
private static IntPtr GetUnmanagedCallbacks()
{
void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * " + total + @");
void** callbacks = (void**)NativeMemory.Alloc((nuint)(sizeof(void*) * " + total + @"));
");

int index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ internal static unsafe void DispatchJSImportAsyncPost(JSFunctionBinding signatur
exc.slot.ReceiverShouldFree = true;

var bytes = sizeof(JSMarshalerArgument) * arguments.Length;
void* cpy = (void*)Marshal.AllocHGlobal(bytes);
void* cpy = NativeMemory.Alloc((nuint)bytes);
arguments.CopyTo(new Span<JSMarshalerArgument>(cpy, arguments.Length));
var sig = (nint)signature.Header;

Expand All @@ -440,7 +440,7 @@ internal static unsafe JSFunctionBinding BindJSImportImpl(string functionName, s
if (exceptionPtr != IntPtr.Zero)
{
var message = Marshal.PtrToStringUni(exceptionPtr)!;
Marshal.FreeHGlobal(exceptionPtr);
NativeMemory.Free((void*)exceptionPtr);
throw new JSException(message);
}

Expand Down Expand Up @@ -480,7 +480,7 @@ internal static unsafe void ResolveOrRejectPromise(JSProxyContext targetContext,

// this copy is freed in SystemInteropJS_ResolveOrRejectPromise
var bytes = sizeof(JSMarshalerArgument) * arguments.Length;
void* cpy = (void*)Marshal.AllocHGlobal(bytes);
void* cpy = NativeMemory.Alloc((nuint)bytes);
arguments.CopyTo(new Span<JSMarshalerArgument>(cpy, arguments.Length));

// async
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public PromiseHolder(JSProxyContext targetContext)
GCHandle = (IntPtr)InteropServices.GCHandle.Alloc(this, GCHandleType.Normal);
ProxyContext = targetContext;
#if FEATURE_WASM_MANAGED_THREADS
State = (PromiseHolderState*)Marshal.AllocHGlobal(sizeof(PromiseHolderState));
State = (PromiseHolderState*)NativeMemory.Alloc((nuint)sizeof(PromiseHolderState));
Interlocked.Exchange(ref (*State).IsResolving, 0);
#endif
}
Expand All @@ -36,7 +36,7 @@ public PromiseHolder(JSProxyContext targetContext, nint gcvHandle)
GCHandle = gcvHandle;
ProxyContext = targetContext;
#if FEATURE_WASM_MANAGED_THREADS
State = (PromiseHolderState*)Marshal.AllocHGlobal(sizeof(PromiseHolderState));
State = (PromiseHolderState*)NativeMemory.Alloc((nuint)sizeof(PromiseHolderState));
Interlocked.Exchange(ref (*State).IsResolving, 0);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static unsafe JSFunctionBinding GetMethodSignature(ReadOnlySpan<JSMarshal
}

// this is never unallocated
IntPtr buffer = Marshal.AllocHGlobal(size);
IntPtr buffer = (IntPtr)NativeMemory.Alloc((nuint)size);

var signature = new JSFunctionBinding
{
Expand Down Expand Up @@ -185,7 +185,7 @@ public static unsafe JSFunctionBinding GetMethodSignature(ReadOnlySpan<JSMarshal

public static unsafe void FreeMethodSignatureBuffer(JSFunctionBinding signature)
{
Marshal.FreeHGlobal((nint)signature.Header);
NativeMemory.Free(signature.Header);
signature.Header = null;
signature.Sigs = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public void ReleasePromiseHolder(nint holderGCHandle)
#if FEATURE_WASM_MANAGED_THREADS
unsafe
{
Marshal.FreeHGlobal((IntPtr)holder.State);
NativeMemory.Free(holder.State);
holder.State = null;
}
#endif
Expand Down Expand Up @@ -442,7 +442,7 @@ public unsafe void ReleaseJSOwnedObjectByGCHandle(nint gcHandle)
holderCallback = holder.Callback;
holder.IsDisposed = true;
#if FEATURE_WASM_MANAGED_THREADS
Marshal.FreeHGlobal((IntPtr)holder.State);
NativeMemory.Free(holder.State);
holder.State = null;
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void ToJS(byte? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
public void ToManaged(out byte[]? value)
public unsafe void ToManaged(out byte[]? value)
{
if (slot.Type == MarshalerType.None)
{
Expand All @@ -92,15 +92,15 @@ public void ToManaged(out byte[]? value)
}
value = new byte[slot.Length];
Marshal.Copy(slot.IntPtrValue, value, 0, slot.Length);
Marshal.FreeHGlobal(slot.IntPtrValue);
NativeMemory.Free((void*)slot.IntPtrValue);
}

/// <summary>
/// Implementation of the argument marshaling.
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
public void ToJS(byte[]? value)
public unsafe void ToJS(byte[]? value)
{
if (value == null)
{
Expand All @@ -109,7 +109,7 @@ public void ToJS(byte[]? value)
}
slot.Length = value.Length;
slot.Type = MarshalerType.Array;
slot.IntPtrValue = Marshal.AllocHGlobal(value.Length * sizeof(byte));
slot.IntPtrValue = (IntPtr)NativeMemory.Alloc((nuint)(value.Length * sizeof(byte)));
slot.ElementType = MarshalerType.Byte;
Marshal.Copy(value, 0, slot.IntPtrValue, slot.Length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void ToJS(double? value)
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToManaged(out double[]? value)
public unsafe void ToManaged(out double[]? value)
{
if (slot.Type == MarshalerType.None)
{
Expand All @@ -95,7 +95,7 @@ public void ToManaged(out double[]? value)
}
value = new double[slot.Length];
Marshal.Copy(slot.IntPtrValue, value, 0, slot.Length);
Marshal.FreeHGlobal(slot.IntPtrValue);
NativeMemory.Free((void*)slot.IntPtrValue);
}

/// <summary>
Expand All @@ -106,15 +106,15 @@ public void ToManaged(out double[]? value)
#if !DEBUG
[MethodImpl(MethodImplOptions.AggressiveInlining)]
#endif
public void ToJS(double[] value)
public unsafe void ToJS(double[] value)
{
if (value == null)
{
slot.Type = MarshalerType.None;
return;
}
slot.Type = MarshalerType.Array;
slot.IntPtrValue = Marshal.AllocHGlobal(value.Length * sizeof(double));
slot.IntPtrValue = (IntPtr)NativeMemory.Alloc((nuint)(value.Length * sizeof(double)));
slot.Length = value.Length;
slot.ElementType = MarshalerType.Double;
Marshal.Copy(value, 0, slot.IntPtrValue, slot.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void ToJS(int? value)
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
public void ToManaged(out int[]? value)
public unsafe void ToManaged(out int[]? value)
{
if (slot.Type == MarshalerType.None)
{
Expand All @@ -92,23 +92,23 @@ public void ToManaged(out int[]? value)
}
value = new int[slot.Length];
Marshal.Copy(slot.IntPtrValue, value, 0, slot.Length);
Marshal.FreeHGlobal(slot.IntPtrValue);
NativeMemory.Free((void*)slot.IntPtrValue);
}

/// <summary>
/// Implementation of the argument marshaling.
/// It's used by JSImport code generator and should not be used by developers in source code.
/// </summary>
/// <param name="value">The value to be marshaled.</param>
public void ToJS(int[]? value)
public unsafe void ToJS(int[]? value)
{
if (value == null)
{
slot.Type = MarshalerType.None;
return;
}
slot.Type = MarshalerType.Array;
slot.IntPtrValue = Marshal.AllocHGlobal(value.Length * sizeof(int));
slot.IntPtrValue = (IntPtr)NativeMemory.Alloc((nuint)(value.Length * sizeof(int)));
slot.Length = value.Length;
slot.ElementType = MarshalerType.Int32;
Marshal.Copy(value, 0, slot.IntPtrValue, slot.Length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public unsafe void ToManaged(out JSObject?[]? value)
arg.ToManaged(out val);
value[i] = val;
}
Marshal.FreeHGlobal(slot.IntPtrValue);
NativeMemory.Free((void*)slot.IntPtrValue);
}

/// <summary>
Expand All @@ -110,7 +110,7 @@ public unsafe void ToJS(JSObject?[] value)
int bytes = value.Length * sizeof(JSMarshalerArgument);
slot.Type = MarshalerType.Array;
slot.ElementType = MarshalerType.JSObject;
JSMarshalerArgument* payload = (JSMarshalerArgument*)Marshal.AllocHGlobal(bytes);
JSMarshalerArgument* payload = (JSMarshalerArgument*)NativeMemory.Alloc((nuint)bytes);
Unsafe.InitBlock(payload, 0, (uint)bytes);
for (int i = 0; i < slot.Length; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public unsafe void ToManaged(out object?[]? value)
#if !ENABLE_JS_INTEROP_BY_VALUE
Interop.Runtime.DeregisterGCRoot(slot.IntPtrValue);
#endif
Marshal.FreeHGlobal(slot.IntPtrValue);
NativeMemory.Free((void*)slot.IntPtrValue);
}

/// <summary>
Expand All @@ -375,7 +375,7 @@ public unsafe void ToJS(object?[] value)
slot.Length = value.Length;
int bytes = value.Length * sizeof(JSMarshalerArgument);
slot.Type = MarshalerType.Array;
JSMarshalerArgument* payload = (JSMarshalerArgument*)Marshal.AllocHGlobal(bytes);
JSMarshalerArgument* payload = (JSMarshalerArgument*)NativeMemory.Alloc((nuint)bytes);
Unsafe.InitBlock(payload, 0, (uint)bytes);
#if !ENABLE_JS_INTEROP_BY_VALUE
Interop.Runtime.RegisterGCRoot(payload, bytes, IntPtr.Zero);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public unsafe void ToManaged(out string? value)
}
#if ENABLE_JS_INTEROP_BY_VALUE
value = Marshal.PtrToStringUni(slot.IntPtrValue, slot.Length);
Marshal.FreeHGlobal(slot.IntPtrValue);
NativeMemory.Free((void*)slot.IntPtrValue);
#else
fixed (void* argAsRoot = &slot.IntPtrValue)
{
Expand Down Expand Up @@ -96,7 +96,7 @@ public unsafe void ToManaged(out string?[]? value)
#if !ENABLE_JS_INTEROP_BY_VALUE
Interop.Runtime.DeregisterGCRoot(slot.IntPtrValue);
#endif
Marshal.FreeHGlobal(slot.IntPtrValue);
NativeMemory.Free((void*)slot.IntPtrValue);
}

/// <summary>
Expand All @@ -117,7 +117,7 @@ public unsafe void ToJS(string?[] value)
slot.Length = value.Length;
int bytes = value.Length * sizeof(JSMarshalerArgument);
slot.Type = MarshalerType.Array;
JSMarshalerArgument* payload = (JSMarshalerArgument*)Marshal.AllocHGlobal(bytes);
JSMarshalerArgument* payload = (JSMarshalerArgument*)NativeMemory.Alloc((nuint)bytes);
Unsafe.InitBlock(payload, 0, (uint)bytes);
#if !ENABLE_JS_INTEROP_BY_VALUE
Interop.Runtime.RegisterGCRoot(payload, bytes, IntPtr.Zero);
Expand Down
Loading