Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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((nuint)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 @@ -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 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