From c7d57b853badd3bc9f76fdedc442ae157d458780 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sun, 29 Mar 2015 14:07:00 +0000 Subject: [PATCH] [NTDLL_APITEST] - Add a test for RtlReAllocateHeap -- shows that it doesn't handle allocations larger than 0x7f000 correctly in ROS CORE-9441 svn path=/trunk/; revision=66958 --- rostests/apitests/ntdll/CMakeLists.txt | 1 + rostests/apitests/ntdll/RtlReAllocateHeap.c | 78 +++++++++++++++++++++ rostests/apitests/ntdll/testlist.c | 2 + 3 files changed, 81 insertions(+) create mode 100644 rostests/apitests/ntdll/RtlReAllocateHeap.c diff --git a/rostests/apitests/ntdll/CMakeLists.txt b/rostests/apitests/ntdll/CMakeLists.txt index a8247ed4e22..3313f4bcd80 100644 --- a/rostests/apitests/ntdll/CMakeLists.txt +++ b/rostests/apitests/ntdll/CMakeLists.txt @@ -27,6 +27,7 @@ list(APPEND SOURCE RtlGetLongestNtPathLength.c RtlInitializeBitMap.c RtlMemoryStream.c + RtlReAllocateHeap.c StackOverflow.c SystemInfo.c Timer.c diff --git a/rostests/apitests/ntdll/RtlReAllocateHeap.c b/rostests/apitests/ntdll/RtlReAllocateHeap.c new file mode 100644 index 00000000000..7a8a598f6cd --- /dev/null +++ b/rostests/apitests/ntdll/RtlReAllocateHeap.c @@ -0,0 +1,78 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory + * PURPOSE: Test for RtlReAllocateHeap + * PROGRAMMERS: Thomas Faber + */ + +#include + +#define WIN32_NO_STATUS +#include + +static +BOOLEAN +CheckBuffer( + PVOID Buffer, + SIZE_T Size, + UCHAR Value) +{ + PUCHAR Array = Buffer; + SIZE_T i; + + for (i = 0; i < Size; i++) + if (Array[i] != Value) + { + trace("Expected %x, found %x at offset %lu\n", Value, Array[i], (ULONG)i); + return FALSE; + } + return TRUE; +} + +START_TEST(RtlReAllocateHeap) +{ + PUCHAR Buffer = NULL; + PUCHAR NewBuffer; + SIZE_T OldSize = 0; + SIZE_T Size; + + OldSize = 0x100; + Buffer = RtlReAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + NULL, + OldSize); + ok(Buffer == NULL, "RtlReAllocateHeap succeeded for NULL\n"); + if (Buffer) + RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); + + Buffer = RtlAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + OldSize); + if (!Buffer) + { + skip("RtlAllocateHeap failed for size %lu\n", OldSize); + return; + } + ok(CheckBuffer(Buffer, OldSize, 0), "HEAP_ZERO_MEMORY not respected for 0x%lx\n", OldSize); + + for (Size = 0x78000; Size < 0x90000; Size += 0x100) + { + RtlFillMemory(Buffer, OldSize, 0x7a); + NewBuffer = RtlReAllocateHeap(RtlGetProcessHeap(), + HEAP_ZERO_MEMORY, + Buffer, + Size); + if (!NewBuffer) + { + skip("RtlReAllocateHeap failed for size %lu\n", Size); + break; + } + Buffer = NewBuffer; + ok_hex(RtlSizeHeap(RtlGetProcessHeap(), 0, Buffer), Size); + ok(CheckBuffer(Buffer, OldSize, 0x7a), "CheckBuffer failed at size 0x%lx -> 0x%lx\n", OldSize, Size); + ok(CheckBuffer(Buffer + OldSize, Size - OldSize, 0), "HEAP_ZERO_MEMORY not respected for 0x%lx -> 0x%lx\n", OldSize, Size); + OldSize = Size; + } + RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer); +} + diff --git a/rostests/apitests/ntdll/testlist.c b/rostests/apitests/ntdll/testlist.c index 7d27f30093a..8c2406981a5 100644 --- a/rostests/apitests/ntdll/testlist.c +++ b/rostests/apitests/ntdll/testlist.c @@ -31,6 +31,7 @@ extern void func_RtlGetLengthWithoutTrailingPathSeperators(void); extern void func_RtlGetLongestNtPathLength(void); extern void func_RtlInitializeBitMap(void); extern void func_RtlMemoryStream(void); +extern void func_RtlReAllocateHeap(void); extern void func_StackOverflow(void); extern void func_TimerResolution(void); @@ -64,6 +65,7 @@ const struct test winetest_testlist[] = { "RtlGetLongestNtPathLength", func_RtlGetLongestNtPathLength }, { "RtlInitializeBitMap", func_RtlInitializeBitMap }, { "RtlMemoryStream", func_RtlMemoryStream }, + { "RtlReAllocateHeap", func_RtlReAllocateHeap }, { "StackOverflow", func_StackOverflow }, { "TimerResolution", func_TimerResolution },