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
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static unsafe void InitializeGlobalTablesForModule(TypeManagerHandle typ

private static unsafe void InitializeModuleFrozenObjectSegment(IntPtr segmentStart, int length)
{
if (RuntimeImports.RhpRegisterFrozenSegment(segmentStart, (IntPtr)length) == IntPtr.Zero)
if (RuntimeImports.RhRegisterFrozenSegment((void*)segmentStart, (nuint)length, (nuint)length, (nuint)length) == IntPtr.Zero)
{
// This should only happen if we ran out of memory.
RuntimeExceptionHelpers.FailFast("Failed to register frozen object segment for the module.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@ internal static class RuntimeImports
{
private const string RuntimeLibrary = "*";

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhpRegisterFrozenSegment")]
internal static extern IntPtr RhpRegisterFrozenSegment(IntPtr pSegmentStart, IntPtr length);

[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhpUnregisterFrozenSegment")]
internal static extern void RhpUnregisterFrozenSegment(IntPtr pSegmentHandle);

[RuntimeImport(RuntimeLibrary, "RhpGetModuleSection")]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern IntPtr RhGetModuleSection(ref TypeManagerHandle module, ReadyToRunSectionType section, out int length);
Expand Down
11 changes: 8 additions & 3 deletions src/coreclr/nativeaot/Runtime/MiscHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,17 @@ EXTERN_C NATIVEAOT_API int32_t __cdecl RhpGetCurrentThreadStackTrace(void* pOutp
return RhpCalculateStackTraceWorker(pOutputBuffer, outputBufferLength, pAddressInCurrentFrame);
}

COOP_PINVOKE_HELPER(void*, RhpRegisterFrozenSegment, (void* pSegmentStart, size_t length))
COOP_PINVOKE_HELPER(void*, RhRegisterFrozenSegment, (void * pSection, size_t allocSize, size_t commitSize, size_t reservedSize))
{
return RedhawkGCInterface::RegisterFrozenSegment(pSegmentStart, length);
return RedhawkGCInterface::RegisterFrozenSegment(pSection, allocSize, commitSize, reservedSize);
}

COOP_PINVOKE_HELPER(void, RhpUnregisterFrozenSegment, (void* pSegmentHandle))
COOP_PINVOKE_HELPER(void, RhUpdateFrozenSegment, (void* pSegmentHandle, uint8_t* allocated, uint8_t* committed))
{
RedhawkGCInterface::UpdateFrozenSegment((GcSegmentHandle)pSegmentHandle, allocated, committed);
}

COOP_PINVOKE_HELPER(void, RhUnregisterFrozenSegment, (void* pSegmentHandle))
{
RedhawkGCInterface::UnregisterFrozenSegment((GcSegmentHandle)pSegmentHandle);
}
Expand Down
20 changes: 16 additions & 4 deletions src/coreclr/nativeaot/Runtime/gcrhenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,23 +368,35 @@ void RedhawkGCInterface::BulkEnumGcObjRef(PTR_RtuObjectRef pRefs, uint32_t cRefs
}

// static
GcSegmentHandle RedhawkGCInterface::RegisterFrozenSegment(void * pSection, size_t SizeSection)
GcSegmentHandle RedhawkGCInterface::RegisterFrozenSegment(void * pSection, size_t allocSize, size_t commitSize, size_t reservedSize)
{
ASSERT(allocSize <= commitSize);
ASSERT(commitSize <= reservedSize);
ASSERT(allocSize >= MIN_OBJECT_SIZE);

#ifdef FEATURE_BASICFREEZE
segment_info seginfo;

seginfo.pvMem = pSection;
seginfo.ibFirstObject = sizeof(ObjHeader);
seginfo.ibAllocated = SizeSection;
seginfo.ibCommit = seginfo.ibAllocated;
seginfo.ibReserved = seginfo.ibAllocated;
seginfo.ibAllocated = allocSize;
seginfo.ibCommit = commitSize;
seginfo.ibReserved = reservedSize;

return (GcSegmentHandle)GCHeapUtilities::GetGCHeap()->RegisterFrozenSegment(&seginfo);
#else // FEATURE_BASICFREEZE
return NULL;
#endif // FEATURE_BASICFREEZE
}

// static
void RedhawkGCInterface::UpdateFrozenSegment(GcSegmentHandle seg, uint8_t* allocated, uint8_t* committed)
{
ASSERT(allocated <= committed);

GCHeapUtilities::GetGCHeap()->UpdateFrozenSegment((segment_handle)seg, allocated, committed);
}

// static
void RedhawkGCInterface::UnregisterFrozenSegment(GcSegmentHandle segment)
{
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/nativeaot/Runtime/gcrhinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class RedhawkGCInterface
void * pfnEnumCallback,
void * pvCallbackData);

static GcSegmentHandle RegisterFrozenSegment(void * pSection, size_t SizeSection);
static GcSegmentHandle RegisterFrozenSegment(void * pSection, size_t allocSize, size_t commitSize, size_t reservedSize);
static void UpdateFrozenSegment(GcSegmentHandle seg, uint8_t* allocated, uint8_t* committed);
static void UnregisterFrozenSegment(GcSegmentHandle segment);

#ifdef FEATURE_GC_STRESS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Win32.SafeHandles;

namespace Internal.Runtime
{
internal unsafe partial class FrozenObjectHeapManager
{
static void* ClrVirtualReserve(nuint size)
{
// The shim will return null for failure
return (void*)Interop.Sys.MMap(
0,
size,
Interop.Sys.MemoryMappedProtections.PROT_NONE,
Interop.Sys.MemoryMappedFlags.MAP_PRIVATE | Interop.Sys.MemoryMappedFlags.MAP_ANONYMOUS,
new SafeFileHandle(-1, false),
0);

}

static void* ClrVirtualCommit(void* pBase, nuint size)
{
int result = Interop.Sys.MProtect(
(nint)pBase,
size,
Interop.Sys.MemoryMappedProtections.PROT_READ | Interop.Sys.MemoryMappedProtections.PROT_WRITE);

return result == 0 ? pBase : null;
}

static void ClrVirtualFree(void* pBase, nuint size)
{
Interop.Sys.MUnmap((nint)pBase, size);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Internal.Runtime
{
internal unsafe partial class FrozenObjectHeapManager
{
static void* ClrVirtualReserve(nuint size)
{
return Interop.Kernel32.VirtualAlloc(null, size, Interop.Kernel32.MemOptions.MEM_RESERVE, Interop.Kernel32.PageOptions.PAGE_READWRITE);
}

static void* ClrVirtualCommit(void* pBase, nuint size)
{
return Interop.Kernel32.VirtualAlloc(pBase, size, Interop.Kernel32.MemOptions.MEM_COMMIT, Interop.Kernel32.PageOptions.PAGE_READWRITE);
}

static void ClrVirtualFree(void* pBase, nuint size)
{
Interop.Kernel32.VirtualFree(pBase, size, Interop.Kernel32.MemOptions.MEM_RELEASE);
}
}
}
Loading