Stop loading crossgen-ed binaries at preferred address on Unix (#11467)
authorJan Vorlicek <janvorli@microsoft.com>
Tue, 9 May 2017 18:30:59 +0000 (20:30 +0200)
committerGitHub <noreply@github.com>
Tue, 9 May 2017 18:30:59 +0000 (20:30 +0200)
This change removes attempt to load crossgen-ed binaries at preferred
address on Unix and uses whatever address the mmap returns instead.

src/pal/src/map/map.cpp

index f3172c3..f26293b 100644 (file)
@@ -2440,22 +2440,21 @@ void * MAPMapPEFile(HANDLE hFile)
     // We're going to start adding mappings to the mapping list, so take the critical section
     InternalEnterCriticalSection(pThread, &mapping_critsec);
 
-#if !defined(_AMD64_)
-    loadedBase = mmap((void*)preferredBase, virtualSize, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
-#else // defined(_AMD64_)    
+#ifdef BIT64
     // 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). Alignment to a 64 KB granularity should
     // not be necessary (alignment to page size should be sufficient), but see
     // ExecutableMemoryAllocator::AllocateMemory() for the reason why it is done.
     loadedBase = ReserveMemoryFromExecutableAllocator(pThread, ALIGN_UP(virtualSize, VIRTUAL_64KB));
+#endif // BIT64
+
     if (loadedBase == NULL)
     {
         // MAC64 requires we pass MAP_SHARED (or MAP_PRIVATE) flags - otherwise, the call is failed.
         // Refer to mmap documentation at http://www.manpagez.com/man/2/mmap/ for details.
-        loadedBase = mmap((void*)preferredBase, virtualSize, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
+        loadedBase = mmap(NULL, virtualSize, PROT_NONE, MAP_ANON|MAP_PRIVATE, -1, 0);
     }
-#endif // !defined(_AMD64_)
 
     if (MAP_FAILED == loadedBase)
     {