Partial revert "Fix problem with virtual memory commit in OOM scenario on Linux ...
authorJan Kotas <jkotas@microsoft.com>
Sun, 12 Jun 2016 14:18:22 +0000 (07:18 -0700)
committerGitHub <noreply@github.com>
Sun, 12 Jun 2016 14:18:22 +0000 (07:18 -0700)
#5609 is suspect to cause intermittent crashes on OS X. Keep the fix for Linux, but revert to using the original code on OS X.

src/pal/src/map/virtual.cpp

index 9e1b4ae..0d7310c 100644 (file)
@@ -1114,7 +1114,17 @@ 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;