Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
19cb0fd
Initial plan
Copilot Dec 31, 2025
94e2e1b
Move X86Base._cpuidex QCall implementation to shared location
Copilot Dec 31, 2025
b9bd895
Fix build errors: update csproj files and include CommonMacros.h for …
Copilot Dec 31, 2025
60923ca
Update src/coreclr/runtime/MiscNativeHelpers.cpp
jkotas Dec 31, 2025
90fa732
Update src/coreclr/runtime/MiscNativeHelpers.cpp
jkotas Dec 31, 2025
89bf1d7
Remove extra blank lines in MiscHelpers.cpp and fix NativeAOT build
Copilot Dec 31, 2025
06bba12
Move Interlocked_MemoryBarrierProcessWide, Buffer_Clear, and Buffer_M…
Copilot Dec 31, 2025
bb20748
Rename __cpuidex to CpuId to match public method name
Copilot Dec 31, 2025
0f883dd
Rename __cpuidex to CpuId in Mono implementation to fix build breaks
Copilot Dec 31, 2025
e15ca0e
Move Buffer and Interlocked QCall declarations to shared files, creat…
Copilot Dec 31, 2025
1de4b1d
Rename __cpuidex to CpuId in Mono native implementation
Copilot Dec 31, 2025
cb47710
Update src/coreclr/nativeaot/Runtime/common.h
jkotas Dec 31, 2025
cc3eb7f
Update src/coreclr/runtime/MiscNativeHelpers.cpp
jkotas Dec 31, 2025
310ed51
Revert changes to src/coreclr/gc/env/common.h
Copilot Dec 31, 2025
5e235e8
Delete INLINE macro definition from CommonMacros.h
Copilot Dec 31, 2025
4330c10
Move MemmoveInternal and ZeroMemoryInternal to SpanHelpers.ByteMemOps.cs
Copilot Dec 31, 2025
716a47f
Replace Buffer QCalls with direct memset/memmove calls and fix ZeroMe…
Copilot Dec 31, 2025
4e3f3d4
Update src/coreclr/vm/comutilnative.cpp
jkotas Dec 31, 2025
d3c3f37
Apply suggestions from code review
jkotas Dec 31, 2025
e9fa3b9
Apply suggestions from code review
jkotas Dec 31, 2025
d4f3574
Rename ZeroMemoryInternal to ZeroMemoryNative and MemmoveInternal to …
Copilot Dec 31, 2025
0fdae71
Update ZeroMemoryNative to use Unsafe.WriteUnaligned and Block16
Copilot Dec 31, 2025
f576817
Fix Mono icall mappings and suppress CS3016 warnings
Copilot Dec 31, 2025
ad1c3b9
Apply suggestions from code review
jkotas Dec 31, 2025
562069e
Apply suggestions from code review
jkotas Dec 31, 2025
72bcb60
Update src/libraries/System.Private.CoreLib/src/System/SpanHelpers.By…
jkotas Dec 31, 2025
4a9e0d4
Delete ZeroMemoryNative and MemmoveNative from Mono Buffer.Mono.cs
Copilot Dec 31, 2025
15377c0
Add Mono-specific memmove/memset/CpuId implementations and consolidat…
Copilot Dec 31, 2025
b2cfc82
Update src/libraries/System.Private.CoreLib/src/System/SpanHelpers.By…
jkotas Dec 31, 2025
b9c1c56
Update src/libraries/System.Private.CoreLib/src/System/SpanHelpers.By…
jkotas Dec 31, 2025
e5f973e
Update src/libraries/System.Private.CoreLib/src/System/SpanHelpers.By…
jkotas Dec 31, 2025
0e99b23
Apply suggestions from code review
jkotas Dec 31, 2025
44a4fb5
Rename Mono icalls to ves_icall_System_SpanHelpers_* and update signa…
Copilot Dec 31, 2025
9c583d7
Change Mono memmove/memset pointer arguments to void* to match native…
Copilot Dec 31, 2025
5050a71
Change non-Mono memmove/memset pointer arguments to void*
Copilot Dec 31, 2025
bd73bcd
Fix NativeAOT build breaks in CommonMacros.h and PalUnix.cpp
Copilot Dec 31, 2025
ef6c987
Delete OS_PAGE_SIZE and related page size functions
Copilot Dec 31, 2025
5678d00
Add common.h as first include to fix NativeAOT build breaks
Copilot Dec 31, 2025
c5f307d
Delete Range.h and AllocHeap::Contains method
Copilot Dec 31, 2025
1900ee3
Update src/coreclr/nativeaot/Runtime/allocheap.h
jkotas Dec 31, 2025
2c28119
Update src/coreclr/nativeaot/Runtime/common.h
jkotas Dec 31, 2025
688fe09
Update src/coreclr/nativeaot/Runtime/common.h
jkotas Dec 31, 2025
ffa12dc
Fix THUNKS_MAP_SIZE macro to cast OS_PAGE_SIZE to int
Copilot Dec 31, 2025
b7f7f50
Update src/coreclr/nativeaot/Runtime/ThunksMapping.cpp
jkotas Dec 31, 2025
092c67b
Add int casts to RhpGetNumThunkBlocksPerMapping and RhpGetNumThunksPe…
Copilot Dec 31, 2025
691b295
Cache THUNKS_MAP_SIZE in local variable to avoid recomputation
Copilot Jan 1, 2026
24d7355
Add type casts to fix size_t conversion warnings in ThunksMapping.cpp
Copilot Jan 1, 2026
7a0e6b9
Move System.SpanHelpers ICALL_TYPE to correct alphabetical position
Copilot Jan 1, 2026
919ebb9
Add uint32_t cast to fix conversion warning at line 236
Copilot Jan 1, 2026
d181eaa
Update src/libraries/System.Private.CoreLib/src/System/SpanHelpers.By…
jkotas Jan 1, 2026
4d5e421
Update src/libraries/System.Private.CoreLib/src/System/SpanHelpers.By…
jkotas Jan 1, 2026
c54f824
Fix alignment mask calculations and remove int32_t cast
Copilot Jan 1, 2026
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 @@ -224,7 +224,6 @@
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\MemoryMarshal.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\NativeLibrary.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\Java\JavaMarshal.CoreCLR.cs" Condition="'$(FeatureJavaMarshal)' == 'true'" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\Intrinsics\X86\X86Base.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\Loader\AssemblyLoadContext.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\RuntimeArgumentHandle.cs" />
<Compile Include="$(BclSourcesRoot)\System\RuntimeHandles.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ namespace System
{
public partial class Buffer
{
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Buffer_Clear")]
private static unsafe partial void ZeroMemoryInternal(void* b, nuint byteLength);

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Buffer_MemMove")]
private static unsafe partial void MemmoveInternal(byte* dest, byte* src, nuint len);

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void BulkMoveWithWriteBarrierInternal(ref byte destination, ref byte source, nuint byteCount);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,5 @@ private static long ExchangeAdd(ref long location1, long value)
public static long Read(ref readonly long location) =>
CompareExchange(ref Unsafe.AsRef(in location), 0, 0);
#endregion

#region MemoryBarrierProcessWide
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Interlocked_MemoryBarrierProcessWide")]
private static partial void _MemoryBarrierProcessWide();

/// <summary>Provides a process-wide memory barrier that ensures that reads and writes from any CPU cannot move across the barrier.</summary>
public static void MemoryBarrierProcessWide() => _MemoryBarrierProcessWide();
#endregion
}
}
1 change: 1 addition & 0 deletions src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(COMMON_RUNTIME_SOURCES
rhassert.cpp
${RUNTIME_DIR}/CachedInterfaceDispatch.cpp
CachedInterfaceDispatch_Aot.cpp
${RUNTIME_DIR}/MiscNativeHelpers.cpp
Crst.cpp
DebugHeader.cpp
MethodTable.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "Crst.h"
#include "TargetPtrs.h"
#include "MethodTable.h"
#include "Range.h"

#include "allocheap.h"
#include "rhbinder.h"
#include "ObjectLayout.h"
Expand Down
10 changes: 1 addition & 9 deletions src/coreclr/nativeaot/Runtime/CommonMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ inline bool IS_ALIGNED(T* val, uintptr_t alignment);
#ifndef DACCESS_COMPILE

#ifndef ZeroMemory
#define ZeroMemory(_dst, _size) memset((_dst), 0, (_size))
#define ZeroMemory(Destination,Length) memset((Destination),0,(Length))
#endif

#endif // !DACCESS_COMPILE
Expand All @@ -83,12 +83,6 @@ inline bool IS_ALIGNED(T* val, uintptr_t alignment);

#endif // HOST_64BIT

#ifndef __GCENV_BASE_INCLUDED__

#define OS_PAGE_SIZE PalOsPageSize()

#endif // __GCENV_BASE_INCLUDED__

#if defined(TARGET_ARM)
#define THUMB_CODE 1
#endif
Expand Down Expand Up @@ -264,8 +258,6 @@ typedef int32_t FC_BOOL_ARG;
#define NOT_IN_DAC(x)
#endif

#define INLINE inline

enum STARTUP_TIMELINE_EVENT_ID
{
PROCESS_ATTACH_BEGIN = 0,
Expand Down
16 changes: 0 additions & 16 deletions src/coreclr/nativeaot/Runtime/MiscHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ EXTERN_C UInt32_BOOL QCALLTYPE RhYield()
return PalSwitchToThread();
}

EXTERN_C void QCALLTYPE RhFlushProcessWriteBuffers()
{
// This must be called via p/invoke -- it's a wait operation and we don't want to block thread suspension on this.
ASSERT_MSG(!ThreadStore::GetCurrentThread()->IsCurrentThreadInCooperativeMode(),
"You must p/invoke to RhFlushProcessWriteBuffers");

minipal_memory_barrier_process_wide();
}

// Get the list of currently loaded NativeAOT modules (as OS HMODULE handles). The caller provides a reference
// to an array of pointer-sized elements and we return the total number of modules currently loaded (whether
// that is less than, equal to or greater than the number of elements in the array). If there are more modules
Expand Down Expand Up @@ -486,13 +477,6 @@ FCIMPL2(uint32_t, RhGetKnobValues, char *** pResultKeys, char *** pResultValues)
}
FCIMPLEND

#if defined(TARGET_X86) || defined(TARGET_AMD64)
EXTERN_C void QCALLTYPE RhCpuIdEx(int* cpuInfo, int functionId, int subFunctionId)
{
__cpuidex(cpuInfo, functionId, subFunctionId);
}
#endif

FCIMPL3(int32_t, RhpLockCmpXchg32, int32_t * location, int32_t value, int32_t comparand)
{
return PalInterlockedCompareExchange(location, value, comparand);
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/nativeaot/Runtime/Pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ HANDLE PalCreateEventW(_In_opt_ LPSECURITY_ATTRIBUTES pEventAttributes, UInt32_B
HANDLE PalGetModuleHandleFromPointer(_In_ void* pointer);

#ifdef TARGET_UNIX
uint32_t PalGetOsPageSize();
typedef int32_t (*PHARDWARE_EXCEPTION_HANDLER)(uintptr_t faultCode, uintptr_t faultAddress, PAL_LIMITED_CONTEXT* palContext, uintptr_t* arg0Reg, uintptr_t* arg1Reg);
void PalSetHardwareExceptionHandler(PHARDWARE_EXCEPTION_HANDLER handler);
#endif
Expand Down
137 changes: 0 additions & 137 deletions src/coreclr/nativeaot/Runtime/Range.h

This file was deleted.

32 changes: 17 additions & 15 deletions src/coreclr/nativeaot/Runtime/ThunksMapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
static_assert((THUNK_SIZE % 4) == 0, "Thunk stubs size not aligned correctly. This will cause runtime failures.");

// 32 K or OS page
#define THUNKS_MAP_SIZE (max(0x8000, OS_PAGE_SIZE))
#define THUNKS_MAP_SIZE (max((size_t)0x8000, OS_PAGE_SIZE))

#ifdef TARGET_ARM
//*****************************************************************************
Expand Down Expand Up @@ -63,13 +63,13 @@ FCIMPL0(int, RhpGetNumThunkBlocksPerMapping)
{
ASSERT_MSG((THUNKS_MAP_SIZE % OS_PAGE_SIZE) == 0, "Thunks map size should be in multiples of pages");

return THUNKS_MAP_SIZE / OS_PAGE_SIZE;
return (int)(THUNKS_MAP_SIZE / OS_PAGE_SIZE);
}
FCIMPLEND

FCIMPL0(int, RhpGetNumThunksPerBlock)
{
return min(
return (int)min(
OS_PAGE_SIZE / THUNK_SIZE, // Number of thunks that can fit in a page
(OS_PAGE_SIZE - POINTER_SIZE) / (POINTER_SIZE * 2) // Number of pointer pairs, minus the jump stub cell, that can fit in a page
);
Expand All @@ -96,22 +96,24 @@ FCIMPLEND

FCIMPL0(int, RhpGetThunkBlockSize)
{
return OS_PAGE_SIZE;
return (int)OS_PAGE_SIZE;
}
FCIMPLEND

EXTERN_C HRESULT QCALLTYPE RhAllocateThunksMapping(void** ppThunksSection)
{
size_t thunksMapSize = THUNKS_MAP_SIZE;

#ifdef WIN32

void * pNewMapping = PalVirtualAlloc(THUNKS_MAP_SIZE * 2, PAGE_READWRITE);
void * pNewMapping = PalVirtualAlloc(thunksMapSize * 2, PAGE_READWRITE);
if (pNewMapping == NULL)
{
return E_OUTOFMEMORY;
}

void * pThunksSection = pNewMapping;
void * pDataSection = (uint8_t*)pNewMapping + THUNKS_MAP_SIZE;
void * pDataSection = (uint8_t*)pNewMapping + thunksMapSize;

#else

Expand All @@ -120,17 +122,17 @@ EXTERN_C HRESULT QCALLTYPE RhAllocateThunksMapping(void** ppThunksSection)
// reduce it to RW for the data section. For the stubs section we need to increase to RWX to generate the stubs
// instructions. After this we go back to RX for the stubs section before the stubs are used and should not be
// changed anymore.
void * pNewMapping = PalVirtualAlloc(THUNKS_MAP_SIZE * 2, PAGE_EXECUTE_READ);
void * pNewMapping = PalVirtualAlloc(thunksMapSize * 2, PAGE_EXECUTE_READ);
if (pNewMapping == NULL)
{
return E_OUTOFMEMORY;
}

void * pThunksSection = pNewMapping;
void * pDataSection = (uint8_t*)pNewMapping + THUNKS_MAP_SIZE;
void * pDataSection = (uint8_t*)pNewMapping + thunksMapSize;

if (!PalVirtualProtect(pDataSection, THUNKS_MAP_SIZE, PAGE_READWRITE) ||
!PalVirtualProtect(pThunksSection, THUNKS_MAP_SIZE, PAGE_EXECUTE_READWRITE))
if (!PalVirtualProtect(pDataSection, thunksMapSize, PAGE_READWRITE) ||
!PalVirtualProtect(pThunksSection, thunksMapSize, PAGE_EXECUTE_READWRITE))
{
PalVirtualFree(pNewMapping, THUNKS_MAP_SIZE * 2);
return E_FAIL;
Expand Down Expand Up @@ -172,7 +174,7 @@ EXTERN_C HRESULT QCALLTYPE RhAllocateThunksMapping(void** ppThunksSection)

*((uint32_t*)pCurrentThunkAddress) = 0x00a2ff41;
pCurrentThunkAddress += 3;
*((uint32_t*)pCurrentThunkAddress) = OS_PAGE_SIZE - POINTER_SIZE - (i * POINTER_SIZE * 2);
*((uint32_t*)pCurrentThunkAddress) = (uint32_t)(OS_PAGE_SIZE - POINTER_SIZE - (i * POINTER_SIZE * 2));
pCurrentThunkAddress += 4;

// nops for alignment
Expand Down Expand Up @@ -231,7 +233,7 @@ EXTERN_C HRESULT QCALLTYPE RhAllocateThunksMapping(void** ppThunksSection)
*((uint32_t*)pCurrentThunkAddress) = 0x10000010 | (((delta & 0x03) << 29) | (((delta & 0x1FFFFC) >> 2) << 5));
pCurrentThunkAddress += 4;

*((uint32_t*)pCurrentThunkAddress) = 0xF9400211 | (((OS_PAGE_SIZE - POINTER_SIZE - (i * POINTER_SIZE * 2)) / 8) << 10);
*((uint32_t*)pCurrentThunkAddress) = 0xF9400211 | (((uint32_t)((OS_PAGE_SIZE - POINTER_SIZE - (i * POINTER_SIZE * 2)) / 8) << 10));
pCurrentThunkAddress += 4;

*((uint32_t*)pCurrentThunkAddress) = 0xD61F0220;
Expand Down Expand Up @@ -307,14 +309,14 @@ EXTERN_C HRESULT QCALLTYPE RhAllocateThunksMapping(void** ppThunksSection)
#error "Unknown OS"
#endif
#else
if (!PalVirtualProtect(pThunksSection, THUNKS_MAP_SIZE, PAGE_EXECUTE_READ))
if (!PalVirtualProtect(pThunksSection, thunksMapSize, PAGE_EXECUTE_READ))
{
PalVirtualFree(pNewMapping, THUNKS_MAP_SIZE * 2);
PalVirtualFree(pNewMapping, thunksMapSize * 2);
return E_FAIL;
}
#endif

PalFlushInstructionCache(pThunksSection, THUNKS_MAP_SIZE);
PalFlushInstructionCache(pThunksSection, thunksMapSize);

*ppThunksSection = pThunksSection;
return S_OK;
Expand Down
Loading
Loading