Making MemoryFailPoint functional on xplat
authorRama Krishnan Raghupathy <ramarag@microsoft.com>
Fri, 7 Oct 2016 23:55:19 +0000 (16:55 -0700)
committerDDCloud <ramarag@microsoft.com>
Tue, 25 Oct 2016 22:00:50 +0000 (15:00 -0700)
Expose GlobalMemoryStatusEx on Xplat

Commit migrated from https://github.com/dotnet/coreclr/commit/f2ac449d96ae21abf5b458645ff79ed328fe4ebc

src/coreclr/src/dlls/mscoree/mscorwks_unixexports.src
src/coreclr/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs
src/coreclr/src/pal/src/map/virtual.cpp
src/coreclr/src/pal/src/misc/sysinfo.cpp
src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt
src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt [new file with mode: 0644]
src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp [new file with mode: 0644]
src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat [new file with mode: 0644]

index 9c151a9..f7862d3 100644 (file)
@@ -98,6 +98,7 @@ UnlockFile
 UnmapViewOfFile
 VirtualAlloc
 VirtualFree
+GlobalMemoryStatusEx
 VirtualQuery
 WideCharToMultiByte
 WriteFile
index 6e35568..4ae6047 100644 (file)
@@ -324,6 +324,9 @@ namespace System.Runtime
         [System.Security.SecurityCritical]  // auto-generated
         private static unsafe bool CheckForFreeAddressSpace(ulong size, bool shouldThrow)
         {
+#if FEATURE_PAL // Remove this when GlobalMemoryStatusEx is able to provide legitimate estimates
+            return true;
+#endif
             // Start walking the address space at 0.  VirtualAlloc may wrap
             // around the address space.  We don't need to find the exact
             // pages that VirtualAlloc would return - we just need to
index 4b52096..316dfba 100644 (file)
@@ -1096,6 +1096,7 @@ VIRTUALCommitMemory(
         }
 
         StartBoundary = pInformation->startBoundary + runStart * VIRTUAL_PAGE_SIZE;
+        pRetVal = (void *)StartBoundary;
         MemSize = runLength * VIRTUAL_PAGE_SIZE;
 
         if (allocationType != MEM_COMMIT)
index 515ccf1..e7589e8 100644 (file)
@@ -172,7 +172,7 @@ GetSystemInfo(
 #ifdef VM_MAXUSER_ADDRESS
     lpSystemInfo->lpMaximumApplicationAddress = (PVOID) VM_MAXUSER_ADDRESS;
 #elif defined(__sun__) || defined(_AIX) || defined(__hppa__) || ( defined (_IA64_) && defined (_HPUX_) ) || defined(__linux__)
-    lpSystemInfo->lpMaximumApplicationAddress = (PVOID) -1;
+    lpSystemInfo->lpMaximumApplicationAddress = (PVOID) (1ull << 47);
 #elif defined(USERLIMIT)
     lpSystemInfo->lpMaximumApplicationAddress = (PVOID) USERLIMIT;
 #elif defined(_WIN64)
index eafaa66..b2cafde 100644 (file)
@@ -14,6 +14,7 @@ add_subdirectory(test19)
 add_subdirectory(test2)
 add_subdirectory(test20)
 add_subdirectory(test21)
+add_subdirectory(test22)
 add_subdirectory(test3)
 add_subdirectory(test4)
 add_subdirectory(test5)
diff --git a/src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt b/src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt
new file mode 100644 (file)
index 0000000..cdad2ca
--- /dev/null
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 2.8.12.2)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(SOURCES
+  VirtualAlloc.cpp
+)
+
+add_executable(paltest_virtualalloc_test22
+  ${SOURCES}
+)
+
+add_dependencies(paltest_virtualalloc_test22 coreclrpal)
+
+target_link_libraries(paltest_virtualalloc_test22
+  pthread
+  m
+  coreclrpal
+)
diff --git a/src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp b/src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp
new file mode 100644 (file)
index 0000000..489926f
--- /dev/null
@@ -0,0 +1,44 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+/*=============================================================
+**
+** Source:  virtualalloc.c
+**
+** Purpose: Negative test the VirtualAlloc API.
+**          Call VirtualAlloc with MEM_COMMIT allocation type
+**          and PAGE_READWRITE access protection
+
+**
+**============================================================*/
+#include <palsuite.h>
+
+int __cdecl main(int argc, char *argv[])
+{
+    int err;
+    LPVOID lpVirtualAddress;
+
+
+    //Initialize the PAL environment
+    err = PAL_Initialize(argc, argv);
+    if(0 != err)
+    {
+        ExitProcess(FAIL);
+    }
+
+    //Allocate the physical storage in memory or in the paging file on disk 
+    lpVirtualAddress = VirtualAlloc(NULL,//system determine where to allocate the region
+            (SIZE_T)(2147483647000000), //specify the size to be int32.maxvalue mega bytes
+            MEM_COMMIT,      //allocation type
+            PAGE_READWRITE);  //access protection
+    if(NULL != lpVirtualAddress)
+    {
+        Fail("\nWelcome to the Future, where Unlimited Memory is Available, disregard this test!\n");
+    }
+
+
+
+    PAL_Terminate();
+    return PASS;
+}
diff --git a/src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat b/src/coreclr/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat
new file mode 100644 (file)
index 0000000..3d5962c
--- /dev/null
@@ -0,0 +1,13 @@
+# Licensed to the .NET Foundation under one or more agreements.
+# The .NET Foundation licenses this file to you under the MIT license.
+# See the LICENSE file in the project root for more information.
+
+Version = 1.0
+Section = Filemapping_memmgt
+Function = VirtualAlloc
+Name = Negative test for VirtualAlloc API
+TYPE = DEFAULT
+EXE1 = virtualalloc
+Description
+=Test the VirtualAlloc with MEM_COMMIT allocation type
+=and PAGE_READWRITEaccess protection