Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
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/pal/src/include/pal/virtual.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Function :
that is located close to the coreclr library. The memory comes from the virtual
address range that is managed by ExecutableMemoryAllocator.
--*/
void* ReserveMemoryFromExecutableAllocator(SIZE_T allocationSize);
void* ReserveMemoryFromExecutableAllocator(CorUnix::CPalThread* pthrCurrent, SIZE_T allocationSize);

#endif /* _PAL_VIRTUAL_H_ */

Expand Down
2 changes: 1 addition & 1 deletion src/pal/src/map/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ void * MAPMapPEFile(HANDLE hFile)
// First try to reserve virtual memory using ExecutableAllcator. This allows all PE images to be
// near each other and close to the coreclr library which also allows the runtime to generate
// more efficient code (by avoiding usage of jump stubs).
loadedBase = ReserveMemoryFromExecutableAllocator(virtualSize);
loadedBase = ReserveMemoryFromExecutableAllocator(pThread, virtualSize);
if (loadedBase == NULL)
{
// MAC64 requires we pass MAP_SHARED (or MAP_PRIVATE) flags - otherwise, the call is failed.
Expand Down
18 changes: 6 additions & 12 deletions src/pal/src/map/virtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,17 +1197,7 @@ static LPVOID VIRTUALCommitMemory(
if (allocationType != MEM_COMMIT)
{
// Commit the pages
void * pRet = MAP_FAILED;
#ifndef __APPLE__
if (mprotect((void *) StartBoundary, MemSize, PROT_WRITE | PROT_READ) == 0)
pRet = (void *)StartBoundary;
#else // __APPLE__
// Using mprotect above on MacOS is suspect to cause intermittent crashes
// https://github.com/dotnet/coreclr/issues/5672
pRet = mmap((void *) StartBoundary, MemSize, PROT_WRITE | PROT_READ,
MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0);
#endif // __APPLE__
if (pRet != MAP_FAILED)
{
#if MMAP_DOESNOT_ALLOW_REMAP
SIZE_T i;
Expand Down Expand Up @@ -2362,9 +2352,13 @@ Function :
that is located close to the coreclr library. The memory comes from the virtual
address range that is managed by ExecutableMemoryAllocator.
--*/
void* ReserveMemoryFromExecutableAllocator(SIZE_T allocationSize)
void* ReserveMemoryFromExecutableAllocator(CPalThread* pThread, SIZE_T allocationSize)
{
return g_executableMemoryAllocator.AllocateMemory(allocationSize);
InternalEnterCriticalSection(pThread, &virtual_critsec);
void* mem = g_executableMemoryAllocator.AllocateMemory(allocationSize);
InternalLeaveCriticalSection(pThread, &virtual_critsec);

return mem;
}

/*++
Expand Down