From f2ac449d96ae21abf5b458645ff79ed328fe4ebc Mon Sep 17 00:00:00 2001 From: Rama Krishnan Raghupathy Date: Fri, 7 Oct 2016 16:55:19 -0700 Subject: [PATCH] Making MemoryFailPoint functional on xplat Expose GlobalMemoryStatusEx on Xplat --- src/dlls/mscoree/mscorwks_unixexports.src | 1 + src/mscorlib/src/System/Runtime/MemoryFailPoint.cs | 3 ++ src/pal/src/map/virtual.cpp | 1 + src/pal/src/misc/sysinfo.cpp | 2 +- .../filemapping_memmgt/VirtualAlloc/CMakeLists.txt | 1 + .../VirtualAlloc/test22/CMakeLists.txt | 19 ++++++++++ .../VirtualAlloc/test22/VirtualAlloc.cpp | 44 ++++++++++++++++++++++ .../VirtualAlloc/test22/testinfo.dat | 13 +++++++ 8 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp create mode 100644 src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat diff --git a/src/dlls/mscoree/mscorwks_unixexports.src b/src/dlls/mscoree/mscorwks_unixexports.src index 9c151a9..f7862d3 100644 --- a/src/dlls/mscoree/mscorwks_unixexports.src +++ b/src/dlls/mscoree/mscorwks_unixexports.src @@ -98,6 +98,7 @@ UnlockFile UnmapViewOfFile VirtualAlloc VirtualFree +GlobalMemoryStatusEx VirtualQuery WideCharToMultiByte WriteFile diff --git a/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs b/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs index 6e35568..4ae6047 100644 --- a/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs +++ b/src/mscorlib/src/System/Runtime/MemoryFailPoint.cs @@ -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 diff --git a/src/pal/src/map/virtual.cpp b/src/pal/src/map/virtual.cpp index 4b52096..316dfba 100644 --- a/src/pal/src/map/virtual.cpp +++ b/src/pal/src/map/virtual.cpp @@ -1096,6 +1096,7 @@ VIRTUALCommitMemory( } StartBoundary = pInformation->startBoundary + runStart * VIRTUAL_PAGE_SIZE; + pRetVal = (void *)StartBoundary; MemSize = runLength * VIRTUAL_PAGE_SIZE; if (allocationType != MEM_COMMIT) diff --git a/src/pal/src/misc/sysinfo.cpp b/src/pal/src/misc/sysinfo.cpp index 515ccf1..e7589e8 100644 --- a/src/pal/src/misc/sysinfo.cpp +++ b/src/pal/src/misc/sysinfo.cpp @@ -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) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt index eafaa66..b2cafde 100644 --- a/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/CMakeLists.txt @@ -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/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt new file mode 100644 index 0000000..cdad2ca --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/CMakeLists.txt @@ -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/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp new file mode 100644 index 0000000..489926f --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/VirtualAlloc.cpp @@ -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 + +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/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat new file mode 100644 index 0000000..3d5962c --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/VirtualAlloc/test22/testinfo.dat @@ -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 -- 2.7.4