From a8f5b292c32ff3cedb6325fc72a098b5a8cbd33a Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 9 Jan 2024 19:39:38 +0100 Subject: [PATCH] ntdll/tests: Add some tests for creating custom heaps. --- dlls/ntdll/tests/rtl.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c index 442ad729540..03c31d7bf6b 100644 --- a/dlls/ntdll/tests/rtl.c +++ b/dlls/ntdll/tests/rtl.c @@ -3565,6 +3565,77 @@ static void test_RtlDestroyHeap(void) RtlRemoveVectoredExceptionHandler( handler ); } +struct commit_routine_context +{ + void *base; + SIZE_T size; +}; + +static struct commit_routine_context commit_context; + +static NTSTATUS NTAPI test_commit_routine(void *base, void **address, SIZE_T *size) +{ + commit_context.base = base; + commit_context.size = *size; + + return VirtualAlloc(*address, *size, MEM_COMMIT, PAGE_READWRITE) ? 0 : STATUS_ASSERTION_FAILURE; +} + +static void test_RtlCreateHeap(void) +{ + void *ptr, *base, *reserve; + RTL_HEAP_PARAMETERS params; + HANDLE heap; + BOOL ret; + + heap = RtlCreateHeap(0, NULL, 0, 0, NULL, NULL); + ok(!!heap, "Failed to create a heap.\n"); + RtlDestroyHeap(heap); + + memset(¶ms, 0, sizeof(params)); + heap = RtlCreateHeap(0, NULL, 0, 0, NULL, ¶ms); + ok(!!heap, "Failed to create a heap.\n"); + RtlDestroyHeap(heap); + + params.Length = 1; + heap = RtlCreateHeap(0, NULL, 0, 0, NULL, ¶ms); + ok(!!heap, "Failed to create a heap.\n"); + RtlDestroyHeap(heap); + + params.Length = sizeof(params); + params.CommitRoutine = test_commit_routine; + params.InitialCommit = 0x1000; + params.InitialReserve = 0x10000; + + heap = RtlCreateHeap(0, NULL, 0, 0, NULL, ¶ms); + todo_wine + ok(!heap, "Unexpected heap.\n"); + if (heap) + RtlDestroyHeap(heap); + + reserve = VirtualAlloc(NULL, 0x10000, MEM_RESERVE, PAGE_READWRITE); + base = VirtualAlloc(reserve, 0x1000, MEM_COMMIT, PAGE_READWRITE); + ok(!!base, "Unexpected pointer.\n"); + + heap = RtlCreateHeap(0, base, 0, 0, NULL, ¶ms); + ok(!!heap, "Unexpected heap.\n"); + + /* Using block size above initially committed size to trigger + new allocation via user callback. */ + ptr = RtlAllocateHeap(heap, 0, 0x4000); + ok(!!ptr, "Failed to allocate a block.\n"); + todo_wine + ok(commit_context.base == base, "Unexpected base %p.\n", commit_context.base); + todo_wine + ok(!!commit_context.size, "Unexpected allocation size.\n"); + RtlFreeHeap(heap, 0, ptr); + RtlDestroyHeap(heap); + + ret = VirtualFree(reserve, 0, MEM_RELEASE); + todo_wine + ok(ret, "Unexpected return value.\n"); +} + static void test_RtlFirstFreeAce(void) { PACL acl; @@ -3711,6 +3782,7 @@ START_TEST(rtl) test_LdrRegisterDllNotification(); test_DbgPrint(); test_RtlDestroyHeap(); + test_RtlCreateHeap(); test_RtlFirstFreeAce(); test_RtlInitializeSid(); test_RtlValidSecurityDescriptor(); -- 2.11.4.GIT