1 /*
2  * PROJECT:     ReactOS api tests
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Test for RTL_DEBUG_INFORMATION
5  * COPYRIGHT:   Copyright 2020 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
10 #ifndef _WIN64
11 C_ASSERT(sizeof(RTL_DEBUG_INFORMATION) == 0x68);
12 #endif
13 
14 static void Test_Buffersizes()
15 {
16     PRTL_DEBUG_INFORMATION Buffer;
17     NTSTATUS Status;
18 
19     Buffer = RtlCreateQueryDebugBuffer(0, FALSE);
20     ok(Buffer != NULL, "Unable to create default buffer\n");
21     if (!Buffer)
22         return;
23 
24     ok_ptr(Buffer->ViewBaseClient, Buffer);
25     ok_hex(Buffer->Flags, 0);
26     ok(Buffer->OffsetFree == sizeof(*Buffer) || Buffer->OffsetFree == 0x60, "Expected %u or %u, got %lu\n", sizeof(*Buffer), 0x60, Buffer->OffsetFree);
27     ok_hex(Buffer->CommitSize, 0x1000);
28     ok_hex(Buffer->ViewSize, 0x400000);
29 
30     Status = RtlDestroyQueryDebugBuffer(Buffer);
31     ok_hex(Status, STATUS_SUCCESS);
32 
33     Buffer = RtlCreateQueryDebugBuffer(1, FALSE);
34     ok(Buffer != NULL, "Unable to create default buffer\n");
35     if (!Buffer)
36         return;
37 
38     ok_ptr(Buffer->ViewBaseClient, Buffer);
39     ok_hex(Buffer->Flags, 0);
40     ok(Buffer->OffsetFree == sizeof(*Buffer) || Buffer->OffsetFree == 0x60, "Expected %u or %u, got %lu\n", sizeof(*Buffer), 0x60, Buffer->OffsetFree);
41     ok_hex(Buffer->CommitSize, 0x1000);
42     ok_hex(Buffer->ViewSize, 0x1000);
43 
44     Status = RtlDestroyQueryDebugBuffer(Buffer);
45     ok_hex(Status, STATUS_SUCCESS);
46 
47     Buffer = RtlCreateQueryDebugBuffer(0x1000, FALSE);
48     ok(Buffer != NULL, "Unable to create default buffer\n");
49     if (!Buffer)
50         return;
51 
52     ok_ptr(Buffer->ViewBaseClient, Buffer);
53     ok_hex(Buffer->Flags, 0);
54     ok(Buffer->OffsetFree == sizeof(*Buffer) || Buffer->OffsetFree == 0x60, "Expected %u or %u, got %lu\n", sizeof(*Buffer), 0x60, Buffer->OffsetFree);
55     ok_hex(Buffer->CommitSize, 0x1000);
56     ok_hex(Buffer->ViewSize, 0x1000);
57 
58     Status = RtlDestroyQueryDebugBuffer(Buffer);
59     ok_hex(Status, STATUS_SUCCESS);
60 
61     Buffer = RtlCreateQueryDebugBuffer(0x1001, FALSE);
62     ok(Buffer != NULL, "Unable to create default buffer\n");
63     if (!Buffer)
64         return;
65 
66     ok_ptr(Buffer->ViewBaseClient, Buffer);
67     ok_hex(Buffer->Flags, 0);
68     ok(Buffer->OffsetFree == sizeof(*Buffer) || Buffer->OffsetFree == 0x60, "Expected %u or %u, got %lu\n", sizeof(*Buffer), 0x60, Buffer->OffsetFree);
69     ok_hex(Buffer->CommitSize, 0x1000);
70     ok_hex(Buffer->ViewSize, 0x2000);
71 
72     Status = RtlDestroyQueryDebugBuffer(Buffer);
73     ok_hex(Status, STATUS_SUCCESS);
74 
75     Buffer = RtlCreateQueryDebugBuffer(0x7fffffff, FALSE);
76     ok(Buffer == NULL, "Got a valid thing?\n");
77     if (Buffer)
78     {
79         Status = RtlDestroyQueryDebugBuffer(Buffer);
80         ok_hex(Status, STATUS_SUCCESS);
81     }
82 }
83 
84 
85 static void Test_ProcessModules(void)
86 {
87     PRTL_DEBUG_INFORMATION Buffer;
88     NTSTATUS Status;
89     ULONG RequiredSize = 0;
90     PRTL_PROCESS_MODULES ExpectedModules;
91 
92     Buffer = RtlCreateQueryDebugBuffer(0, FALSE);
93     ok(Buffer != NULL, "Unable to create default buffer\n");
94     if (!Buffer)
95         return;
96 
97     Status = LdrQueryProcessModuleInformation(NULL, 0, &RequiredSize);
98     ok_hex(Status, STATUS_INFO_LENGTH_MISMATCH);
99 
100     RequiredSize;
101     ExpectedModules = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, RequiredSize);
102 
103     Status = LdrQueryProcessModuleInformation(ExpectedModules, RequiredSize, &RequiredSize);
104     ok_hex(Status, STATUS_SUCCESS);
105     if (NT_SUCCESS(Status))
106     {
107 
108         Status = RtlQueryProcessDebugInformation(GetCurrentProcessId(), RTL_DEBUG_QUERY_MODULES, Buffer);
109         ok_hex(Status, STATUS_SUCCESS);
110         if (SUCCEEDED(Status))
111         {
112             ok(!memcmp(ExpectedModules, Buffer->Modules, RequiredSize), "Unexpected difference!\n");
113         }
114     }
115     if (ExpectedModules)
116         HeapFree(GetProcessHeap(), 0, ExpectedModules);
117 
118     Status = RtlDestroyQueryDebugBuffer(Buffer);
119     ok_hex(Status, STATUS_SUCCESS);
120 }
121 
122 
123 START_TEST(RtlDebugInformation)
124 {
125     Test_Buffersizes();
126     Test_ProcessModules();
127 }
128