ReactOS 0.4.15-dev-7942-gd23573b
RtlReAllocateHeap.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for RtlReAllocateHeap
5 * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8#include "precomp.h"
9
10static
16{
17 PUCHAR Array = Buffer;
18 SIZE_T i;
19
20 for (i = 0; i < Size; i++)
21 if (Array[i] != Value)
22 {
23 trace("Expected %x, found %x at offset %lu\n", Value, Array[i], (ULONG)i);
24 return FALSE;
25 }
26 return TRUE;
27}
28
29static
34 SIZE_T *OldSizePtr,
36{
37 PUCHAR NewBuffer;
38 SIZE_T OldSize = *OldSizePtr;
39
40 RtlFillMemory(*Buffer, OldSize, 0x7a);
41 NewBuffer = RtlReAllocateHeap(RtlGetProcessHeap(),
43 *Buffer,
44 Size);
45 if (!NewBuffer)
46 {
47 skip("RtlReAllocateHeap failed for size %lu (%s)\n", Size, Action);
48 return FALSE;
49 }
50 *Buffer = NewBuffer;
51 ok_hex(RtlSizeHeap(RtlGetProcessHeap(), 0, NewBuffer), Size);
52 if (OldSize < Size)
53 {
54 ok(CheckBuffer(NewBuffer, OldSize, 0x7a), "CheckBuffer failed at size 0x%lx -> 0x%lx\n", OldSize, Size);
55 ok(CheckBuffer(NewBuffer + OldSize, Size - OldSize, 0), "HEAP_ZERO_MEMORY not respected for 0x%lx -> 0x%lx\n", OldSize, Size);
56 }
57 else
58 {
59 ok(CheckBuffer(NewBuffer, Size, 0x7a), "CheckBuffer failed at size 0x%lx -> 0x%lx\n", OldSize, Size);
60 }
61 *OldSizePtr = Size;
62 return TRUE;
63}
64
66{
68 SIZE_T OldSize = 0;
70 BOOLEAN Continue = TRUE;
72 PVOID UserValue;
73 ULONG UserFlags;
74 PVOID Buffer2;
75
76 OldSize = 0x100;
77 Buffer = RtlReAllocateHeap(RtlGetProcessHeap(),
79 NULL,
80 OldSize);
81 ok(Buffer == NULL, "RtlReAllocateHeap succeeded for NULL\n");
82 if (Buffer)
83 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
84
85 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
87 OldSize);
88 if (!Buffer)
89 {
90 skip("RtlAllocateHeap failed for size %lu\n", OldSize);
91 return;
92 }
93 ok(CheckBuffer(Buffer, OldSize, 0), "HEAP_ZERO_MEMORY not respected for 0x%lx\n", OldSize);
94
95 for (Size = 0x78000; Size < 0x90000 && Continue; Size += 0x100)
96 {
97 Continue = ReAllocBuffer(&Buffer, Size, &OldSize, "growing");
98 }
99
100 /* and back again */
101 for (Size -= 0x100; Size >= 0x78000 && Continue; Size -= 0x100)
102 {
103 Continue = ReAllocBuffer(&Buffer, Size, &OldSize, "shrinking");
104 }
105 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
106
107 /* Now make sure user flags/values get preserved */
108 OldSize = 0x100;
109 Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
111 OldSize);
112 if (!Buffer)
113 {
114 skip("RtlAllocateHeap failed for size %lu\n", OldSize);
115 return;
116 }
117
118 UserValue = InvalidPointer;
119 UserFlags = 0x55555555;
120 Success = RtlGetUserInfoHeap(RtlGetProcessHeap(),
121 0,
122 Buffer,
123 &UserValue,
124 &UserFlags);
125 ok(Success == TRUE, "RtlGetUserInfoHeap returned %u\n", Success);
126 ok(UserValue == NULL, "UserValue = %p\n", UserValue);
127 ok(UserFlags == HEAP_SETTABLE_USER_FLAG2, "UserFlags = %lx\n", UserFlags);
128
129 Success = RtlSetUserFlagsHeap(RtlGetProcessHeap(),
130 0,
131 Buffer,
134 ok(Success == TRUE, "RtlSetUserFlagsHeap returned %u\n", Success);
135
136 Success = RtlSetUserValueHeap(RtlGetProcessHeap(),
137 0,
138 Buffer,
139 &UserValue);
140 ok(Success == TRUE, "RtlSetUserValueHeap returned %u\n", Success);
141
142 UserValue = InvalidPointer;
143 UserFlags = 0x55555555;
144 Success = RtlGetUserInfoHeap(RtlGetProcessHeap(),
145 0,
146 Buffer,
147 &UserValue,
148 &UserFlags);
149 ok(Success == TRUE, "RtlGetUserInfoHeap returned %u\n", Success);
150 ok(UserValue == &UserValue, "UserValue = %p, expected %p\n", UserValue, &UserValue);
151 ok(UserFlags == HEAP_SETTABLE_USER_FLAG3, "UserFlags = %lx\n", UserFlags);
152
153 /* shrink (preserves flags) */
154 Buffer2 = RtlReAllocateHeap(RtlGetProcessHeap(),
156 Buffer,
157 OldSize / 2);
158 ok(Buffer2 == Buffer, "New Buffer is %p, expected %p\n", Buffer2, Buffer);
159 if (Buffer2) Buffer = Buffer2;
160 UserValue = InvalidPointer;
161 UserFlags = 0x55555555;
162 Success = RtlGetUserInfoHeap(RtlGetProcessHeap(),
163 0,
164 Buffer,
165 &UserValue,
166 &UserFlags);
167 ok(Success == TRUE, "RtlGetUserInfoHeap returned %u\n", Success);
168 ok(UserValue == &UserValue, "UserValue = %p, expected %p\n", UserValue, &UserValue);
169 ok(UserFlags == HEAP_SETTABLE_USER_FLAG3, "UserFlags = %lx\n", UserFlags);
170
171 /* grow (overwrites flags) */
172 Buffer2 = RtlReAllocateHeap(RtlGetProcessHeap(),
174 Buffer,
175 OldSize / 4 * 3);
176 ok(Buffer2 == Buffer, "New Buffer is %p, expected %p\n", Buffer2, Buffer);
177 if (Buffer2) Buffer = Buffer2;
178 UserValue = InvalidPointer;
179 UserFlags = 0x55555555;
180 Success = RtlGetUserInfoHeap(RtlGetProcessHeap(),
181 0,
182 Buffer,
183 &UserValue,
184 &UserFlags);
185 ok(Success == TRUE, "RtlGetUserInfoHeap returned %u\n", Success);
186 ok(UserValue == &UserValue, "UserValue = %p, expected %p\n", UserValue, &UserValue);
187 ok(UserFlags == HEAP_SETTABLE_USER_FLAG1, "UserFlags = %lx\n", UserFlags);
188
189 RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
190}
unsigned char BOOLEAN
static BOOLEAN ReAllocBuffer(PUCHAR *Buffer, SIZE_T Size, SIZE_T *OldSizePtr, PCSTR Action)
static BOOLEAN CheckBuffer(PVOID Buffer, SIZE_T Size, UCHAR Value)
#define InvalidPointer
#define ok_hex(expression, result)
Definition: atltest.h:94
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
@ Success
Definition: eventcreate.c:712
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
NTSYSAPI PVOID WINAPI RtlReAllocateHeap(HANDLE, ULONG, PVOID, SIZE_T)
Definition: heap.c:2667
NTSYSAPI SIZE_T NTAPI RtlSizeHeap(_In_ PVOID HeapHandle, _In_ ULONG Flags, _In_ PVOID MemoryPointer)
#define HEAP_SETTABLE_USER_FLAG2
Definition: nt_native.h:1706
#define HEAP_SETTABLE_USER_FLAG1
Definition: nt_native.h:1705
#define HEAP_SETTABLE_USER_FLAG3
Definition: nt_native.h:1707
#define HEAP_SETTABLE_USER_VALUE
Definition: nt_native.h:1704
#define HEAP_REALLOC_IN_PLACE_ONLY
Definition: nt_native.h:1696
BOOLEAN NTAPI RtlGetUserInfoHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID BaseAddress, OUT PVOID *UserValue, OUT PULONG UserFlags)
Definition: heap.c:3915
BOOLEAN NTAPI RtlSetUserFlagsHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID BaseAddress, IN ULONG UserFlagsReset, IN ULONG UserFlagsSet)
Definition: heap.c:3860
BOOLEAN NTAPI RtlSetUserValueHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID BaseAddress, IN PVOID UserValue)
Definition: heap.c:3798
ULONG_PTR SIZE_T
Definition: typedefs.h:80
const char * PCSTR
Definition: typedefs.h:52
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
unsigned char UCHAR
Definition: xmlstorage.h:181