Skip to content

Commit

Permalink
[NativeAOT] Missing memory fence before bulk move of objects (dotnet#…
Browse files Browse the repository at this point in the history
…90890)

* Memory fence before bulk move of objects

* deleted GCMemoryHelpers.h

* Introduced a GCHeapMemoryBarrier helper.
  • Loading branch information
VSadov authored Aug 22, 2023
1 parent 5fea131 commit 3bda6e0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
21 changes: 15 additions & 6 deletions src/coreclr/nativeaot/Runtime/GCMemoryHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "PalRedhawkCommon.h"
#include "CommonMacros.inl"

#include "GCMemoryHelpers.h"
#include "GCMemoryHelpers.inl"

// This function clears a piece of memory in a GC safe way.
Expand All @@ -31,20 +30,30 @@ COOP_PINVOKE_CDECL_HELPER(void *, RhpGcSafeZeroMemory, (void * mem, size_t size)
return mem;
}

#if defined(TARGET_X86) || defined(TARGET_AMD64)
//
// Memory writes are already ordered
//
#define GCHeapMemoryBarrier()
#else
#define GCHeapMemoryBarrier() MemoryBarrier()
#endif

// Move memory, in a way that is compatible with a move onto the heap, but
// does not require the destination pointer to be on the heap.

COOP_PINVOKE_HELPER(void, RhBulkMoveWithWriteBarrier, (uint8_t* pDest, uint8_t* pSrc, size_t cbDest))
{
// It is possible that the bulk write is publishing object references accessible so far only
// by the current thread to shared memory.
// The memory model requires that writes performed by current thread are observable no later
// than the writes that will actually publish the references.
GCHeapMemoryBarrier();

if (pDest <= pSrc || pSrc + cbDest <= pDest)
InlineForwardGCSafeCopy(pDest, pSrc, cbDest);
else
InlineBackwardGCSafeCopy(pDest, pSrc, cbDest);

InlinedBulkWriteBarrier(pDest, cbDest);
}

void REDHAWK_CALLCONV RhpBulkWriteBarrier(void* pMemStart, uint32_t cbMemSize)
{
InlinedBulkWriteBarrier(pMemStart, cbMemSize);
}
8 changes: 0 additions & 8 deletions src/coreclr/nativeaot/Runtime/GCMemoryHelpers.h

This file was deleted.

1 change: 0 additions & 1 deletion src/coreclr/nativeaot/Runtime/MiscHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "MethodTable.inl"
#include "CommonMacros.inl"
#include "volatile.h"
#include "GCMemoryHelpers.h"
#include "GCMemoryHelpers.inl"
#include "yieldprocessornormalized.h"
#include "RhConfig.h"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/nativeaot/Runtime/gcrhenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

#include "daccess.h"

#include "GCMemoryHelpers.h"
#include "interoplibinterface.h"

#include "holder.h"
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/nativeaot/Runtime/portable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "MethodTable.inl"
#include "ObjectLayout.h"

#include "GCMemoryHelpers.h"
#include "GCMemoryHelpers.inl"

#if defined(USE_PORTABLE_HELPERS)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/nativeaot/Runtime/threadstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "yieldprocessornormalized.h"

#include "slist.inl"
#include "GCMemoryHelpers.h"

EXTERN_C volatile uint32_t RhpTrapThreads;
volatile uint32_t RhpTrapThreads = (uint32_t)TrapThreadsFlags::None;
Expand Down

0 comments on commit 3bda6e0

Please sign in to comment.