diff options
Diffstat (limited to 'src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory')
7 files changed, 256 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/CMakeLists.txt new file mode 100644 index 0000000000..c6eddf74e8 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(ProbeMemory_neg1) +add_subdirectory(test1) + diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/CMakeLists.txt new file mode 100644 index 0000000000..e96c92e2ae --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + ProbeMemory_neg.cpp +) + +add_executable(paltest_probememory_probememory_neg1 + ${SOURCES} +) + +add_dependencies(paltest_probememory_probememory_neg1 coreclrpal) + +target_link_libraries(paltest_probememory_probememory_neg1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/ProbeMemory_neg.cpp b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/ProbeMemory_neg.cpp new file mode 100644 index 0000000000..80de809e14 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/ProbeMemory_neg.cpp @@ -0,0 +1,95 @@ +// 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: ReadProcessMemory_neg.c +** +** Purpose: Negative test the ReadProcessMemory API. +** Call ReadProcessMemory to read unreadabel memory area +** +** +**============================================================*/ +#include <palsuite.h> + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + BOOL bResult; + LPVOID lpProcessAddress = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*allocate the virtual memory*/ + lpProcessAddress = VirtualAlloc( + NULL, /*system determine where to allocate the region*/ + REGIONSIZE, /*specify the size*/ + MEM_RESERVE, /*allocation type*/ + PAGE_READONLY); /*access protection*/ + + if(NULL == lpProcessAddress) + { + Fail("\nFailed to call VirtualAlloc API to allocate " + "virtual memory, error code=%u\n", GetLastError()); + } + + /*try to probe the unreadable memory area*/ + bResult = PAL_ProbeMemory( + lpProcessAddress, /*base of memory area*/ + REGIONSIZE, /*buffer length in bytes*/ + FALSE); /*read access*/ + + /*check the return value*/ + if(bResult) + { + Trace("\nProbeMemory for read didn't FAILED\n"); + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + Fail(""); + } + + /*try to probe the unwriteable memory area*/ + bResult = PAL_ProbeMemory( + lpProcessAddress, /*base of memory area*/ + REGIONSIZE, /*buffer length in bytes*/ + FALSE); /*write access */ + + /*check the return value*/ + if(bResult) + { + Trace("\nProbeMemory for write didn't FAILED\n"); + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + Fail(""); + } + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/testinfo.dat new file mode 100644 index 0000000000..4d11a71bdb --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/ProbeMemory_neg1/testinfo.dat @@ -0,0 +1,12 @@ +# 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 = PAL_ProbeMemory +Name = Negative test PAL_ProbeMemory API to read unreadable memory area +TYPE = DEFAULT +EXE1 = probememory_neg +Description +=Test the PAL_ProbeMemory to read unreadable memory area diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/CMakeLists.txt b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/CMakeLists.txt new file mode 100644 index 0000000000..739ba62284 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + ProbeMemory.cpp +) + +add_executable(paltest_probememory_test1 + ${SOURCES} +) + +add_dependencies(paltest_probememory_test1 coreclrpal) + +target_link_libraries(paltest_probememory_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/ProbeMemory.cpp b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/ProbeMemory.cpp new file mode 100644 index 0000000000..30b358d315 --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/ProbeMemory.cpp @@ -0,0 +1,94 @@ +// 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: ReadProcessMemory.c +** +** Purpose: Positive test the ReadProcessMemory API. +** Call ReadProcessMemory to read memory contents +** inside current process. +** +** +**============================================================*/ +#include <palsuite.h> + +#define REGIONSIZE 1024 + +int __cdecl main(int argc, char *argv[]) +{ + int err; + BOOL bResult; + LPVOID lpProcessAddress = NULL; + + /*Initialize the PAL environment*/ + err = PAL_Initialize(argc, argv); + if(0 != err) + { + return FAIL; + } + + /*allocate the virtual memory*/ + lpProcessAddress = VirtualAlloc( + NULL, /*system determine where to allocate the region*/ + REGIONSIZE, /*specify the size*/ + MEM_COMMIT, /*allocation type*/ + PAGE_READWRITE); /*access protection*/ + + if(NULL == lpProcessAddress) + { + Fail("\nFailed to call VirtualAlloc API to allocate " + "virtual memory, error code=%u!\n", GetLastError()); + } + + /*probe the memory for read*/ + bResult = PAL_ProbeMemory( + lpProcessAddress, /*base of memory area*/ + REGIONSIZE, /*buffer length in bytes*/ + FALSE); /*read access*/ + + if(!bResult) + { + Trace("\nProbeMemory for read access FAILED\n"); + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + Fail(""); + } + + /*probe the memory for write */ + bResult = PAL_ProbeMemory( + lpProcessAddress, /*base of memory area*/ + REGIONSIZE, /*buffer length in bytes*/ + TRUE); /*write access*/ + + if(!bResult) + { + Trace("\nProbeMemory for write access FAILED\n"); + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + Fail(""); + } + + /*decommit the specified region*/ + err = VirtualFree(lpProcessAddress, REGIONSIZE, MEM_DECOMMIT); + if(0 == err) + { + Fail("\nFailed to call VirtualFree API, error code=%u\n", GetLastError()); + } + + PAL_Terminate(); + return PASS; +} diff --git a/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/testinfo.dat b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/testinfo.dat new file mode 100644 index 0000000000..512b945c4a --- /dev/null +++ b/src/pal/tests/palsuite/filemapping_memmgt/ProbeMemory/test1/testinfo.dat @@ -0,0 +1,12 @@ +# 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 = PAL_ProbeMemory +Name = Positive test for PAL_ProbeMemory API to probe for read/write +TYPE = DEFAULT +EXE1 = probememory +Description +=Test the PAL_ProbeMemory to probe for read and write |