Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1ce30c0

Browse files
authored
Stop loading crossgen-ed binaries at preferred address on Unix (#11467)
This change removes attempt to load crossgen-ed binaries at preferred address on Unix and uses whatever address the mmap returns instead.
1 parent 4f6fe87 commit 1ce30c0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/pal/src/map/map.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,22 +2440,21 @@ void * MAPMapPEFile(HANDLE hFile)
24402440
// We're going to start adding mappings to the mapping list, so take the critical section
24412441
InternalEnterCriticalSection(pThread, &mapping_critsec);
24422442

2443-
#if !defined(_AMD64_)
2444-
loadedBase = mmap((void*)preferredBase, virtualSize, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
2445-
#else // defined(_AMD64_)
2443+
#ifdef BIT64
24462444
// First try to reserve virtual memory using ExecutableAllcator. This allows all PE images to be
24472445
// near each other and close to the coreclr library which also allows the runtime to generate
24482446
// more efficient code (by avoiding usage of jump stubs). Alignment to a 64 KB granularity should
24492447
// not be necessary (alignment to page size should be sufficient), but see
24502448
// ExecutableMemoryAllocator::AllocateMemory() for the reason why it is done.
24512449
loadedBase = ReserveMemoryFromExecutableAllocator(pThread, ALIGN_UP(virtualSize, VIRTUAL_64KB));
2450+
#endif // BIT64
2451+
24522452
if (loadedBase == NULL)
24532453
{
24542454
// MAC64 requires we pass MAP_SHARED (or MAP_PRIVATE) flags - otherwise, the call is failed.
24552455
// Refer to mmap documentation at http://www.manpagez.com/man/2/mmap/ for details.
2456-
loadedBase = mmap((void*)preferredBase, virtualSize, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
2456+
loadedBase = mmap(NULL, virtualSize, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
24572457
}
2458-
#endif // !defined(_AMD64_)
24592458

24602459
if (MAP_FAILED == loadedBase)
24612460
{

0 commit comments

Comments
 (0)