1
0
Fork 0
mirror of synced 2025-03-07 03:53:26 +01:00

ntdll/tests: Add some tests for creating custom heaps.

This commit is contained in:
Nikolay Sivov 2024-01-09 19:39:38 +01:00 committed by Alexandre Julliard
parent 73647adaef
commit a8f5b292c3

View file

@ -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(&params, 0, sizeof(params));
heap = RtlCreateHeap(0, NULL, 0, 0, NULL, &params);
ok(!!heap, "Failed to create a heap.\n");
RtlDestroyHeap(heap);
params.Length = 1;
heap = RtlCreateHeap(0, NULL, 0, 0, NULL, &params);
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, &params);
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, &params);
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();