Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/zerolib/Internal/Startup.Efi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ unsafe readonly struct EFI_BOOT_SERVICES
private readonly void* pad3;
private readonly void* pad4;
public readonly delegate*<int, nint, void**, ulong> AllocatePool;
private readonly void* pad6;
public readonly delegate*<void*, ulong> FreePool;
private readonly void* pad7;
private readonly void* pad8;
private readonly void* pad9;
Expand Down
24 changes: 24 additions & 0 deletions src/zerolib/Internal/Stubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ public static unsafe void RhpAssignRef(void** dst, void* r)
*dst = r;
}

[RuntimeExport("RhSuppressFinalize")]
public static unsafe void RhSuppressFinalize(object obj)
{
fixed (MethodTable** mt = &obj.m_pMethodTable)
{
FreeObject(mt);
}
}

static unsafe MethodTable** AllocObject(uint size)
{
#if WINDOWS
Expand All @@ -148,5 +157,20 @@ public static unsafe void RhpAssignRef(void** dst, void* r)

return result;
}

static unsafe void FreeObject(MethodTable** mt)
{
#if WINDOWS
[DllImport("kernel32")]
static extern MethodTable** LocalFree(MethodTable** ptr);
LocalFree(mt);
#elif LINUX
[DllImport("libSystem.Native")]
static extern void SystemNative_Free(MethodTable** ptr);
SystemNative_Free(mt);
#elif UEFI
StartupCodeHelpers.s_efiSystemTable->BootServices->FreePool((void*)mt);
#endif
}
}
}
18 changes: 18 additions & 0 deletions src/zerolib/System/GC.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.Runtime.CompilerHelpers;

namespace System
{
public static class GC
{
public static void SuppressFinalize(object obj)
{
if (obj != null)
{
StartupCodeHelpers.RhSuppressFinalize(obj);
}
}
}
}
10 changes: 10 additions & 0 deletions src/zerolib/System/IDisposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System
{
public interface IDisposable
{
void Dispose();
}
}