ReactOS 0.4.16-dev-927-g467dec4
heap.c File Reference
#include <stdlib.h>
#include <malloc.h>
#include <errno.h>
#include "wine/test.h"
Include dependency graph for heap.c:

Go to the source code of this file.

Functions

static void (__cdecl *p_aligned_free)(void *)
 
static void *__cdeclp_aligned_malloc (size_t, size_t)
 
static void *__cdeclp_aligned_offset_malloc (size_t, size_t, size_t)
 
static void *__cdeclp_aligned_realloc (void *, size_t, size_t)
 
static void *__cdeclp_aligned_offset_realloc (void *, size_t, size_t, size_t)
 
static int (__cdecl *p__set_sbh_threshold)(size_t)
 
static size_t (__cdecl *p__get_sbh_threshold)(void)
 
static void test_aligned_malloc (unsigned int size, unsigned int alignment)
 
static void test_aligned_offset_malloc (unsigned int size, unsigned int alignment, unsigned int offset)
 
static void test_aligned_realloc (unsigned int size1, unsigned int size2, unsigned int alignment)
 
static void test_aligned_offset_realloc (unsigned int size1, unsigned int size2, unsigned int alignment, unsigned int offset)
 
static void test_aligned (void)
 
static void test_sbheap (void)
 
static void test_malloc (void)
 
static void test_calloc (void)
 
static void test__get_heap_handle (void)
 
 START_TEST (heap)
 

Function Documentation

◆ int()

static int ( __cdecl p__set_sbh_threshold)
static

◆ p_aligned_malloc()

static void *__cdecl * p_aligned_malloc ( size_t  ,
size_t   
)
static

◆ p_aligned_offset_malloc()

static void *__cdecl * p_aligned_offset_malloc ( size_t  ,
size_t  ,
size_t   
)
static

◆ p_aligned_offset_realloc()

static void *__cdecl * p_aligned_offset_realloc ( void ,
size_t  ,
size_t  ,
size_t   
)
static

◆ p_aligned_realloc()

static void *__cdecl * p_aligned_realloc ( void ,
size_t  ,
size_t   
)
static

◆ size_t()

static size_t ( __cdecl p__get_sbh_threshold)
static

◆ START_TEST()

START_TEST ( heap  )

Definition at line 531 of file heap.c.

532{
533 test_aligned();
534 test_sbheap();
535 test_malloc();
536 test_calloc();
538}
static void test_calloc(void)
Definition: heap.c:499
static void test_aligned(void)
Definition: heap.c:236
static void test_sbheap(void)
Definition: heap.c:418
static void test_malloc(void)
Definition: heap.c:470
static void test__get_heap_handle(void)
Definition: heap.c:526

◆ test__get_heap_handle()

static void test__get_heap_handle ( void  )
static

Definition at line 526 of file heap.c.

527{
528 ok((HANDLE)_get_heap_handle() != GetProcessHeap(), "Expected _get_heap_handle() not to return GetProcessHeap()\n");
529}
#define ok(value,...)
Definition: atltest.h:57
_CRTIMP intptr_t __cdecl _get_heap_handle(void)
Definition: heap.c:367
#define GetProcessHeap()
Definition: compat.h:736

Referenced by START_TEST().

◆ test_aligned()

static void test_aligned ( void  )
static

Definition at line 236 of file heap.c.

237{
238 HMODULE msvcrt = GetModuleHandleA("msvcrt.dll");
239
240 if (msvcrt == NULL)
241 return;
242
243 p_aligned_free = (void*)GetProcAddress(msvcrt, "_aligned_free");
244 p_aligned_malloc = (void*)GetProcAddress(msvcrt, "_aligned_malloc");
245 p_aligned_offset_malloc = (void*)GetProcAddress(msvcrt, "_aligned_offset_malloc");
246 p_aligned_realloc = (void*)GetProcAddress(msvcrt, "_aligned_realloc");
247 p_aligned_offset_realloc = (void*)GetProcAddress(msvcrt, "_aligned_offset_realloc");
248
250 {
251 skip("aligned memory tests skipped\n");
252 return;
253 }
254
255 test_aligned_malloc(256, 0);
256 test_aligned_malloc(256, 1);
257 test_aligned_malloc(256, 2);
258 test_aligned_malloc(256, 3);
259 test_aligned_malloc(256, 4);
260 test_aligned_malloc(256, 8);
261 test_aligned_malloc(256, 16);
262 test_aligned_malloc(256, 32);
263 test_aligned_malloc(256, 64);
264 test_aligned_malloc(256, 127);
265 test_aligned_malloc(256, 128);
266
273 test_aligned_offset_malloc(256, 16, 0);
274 test_aligned_offset_malloc(256, 32, 0);
275 test_aligned_offset_malloc(256, 64, 0);
276 test_aligned_offset_malloc(256, 127, 0);
277 test_aligned_offset_malloc(256, 128, 0);
278
285 test_aligned_offset_malloc(256, 16, 4);
286 test_aligned_offset_malloc(256, 32, 4);
287 test_aligned_offset_malloc(256, 64, 4);
288 test_aligned_offset_malloc(256, 127, 4);
289 test_aligned_offset_malloc(256, 128, 4);
290
293 test_aligned_offset_malloc(256, 8, 16);
294 test_aligned_offset_malloc(256, 8, 17);
295 test_aligned_offset_malloc(256, 8, 254);
296 test_aligned_offset_malloc(256, 8, 255);
297 test_aligned_offset_malloc(256, 8, 256);
298 test_aligned_offset_malloc(256, 8, 512);
299
300 test_aligned_realloc(256, 512, 0);
301 test_aligned_realloc(256, 128, 0);
302 test_aligned_realloc(256, 512, 4);
303 test_aligned_realloc(256, 128, 4);
304 test_aligned_realloc(256, 512, 8);
305 test_aligned_realloc(256, 128, 8);
306 test_aligned_realloc(256, 512, 16);
307 test_aligned_realloc(256, 128, 16);
308 test_aligned_realloc(256, 512, 32);
309 test_aligned_realloc(256, 128, 32);
310 test_aligned_realloc(256, 512, 64);
311 test_aligned_realloc(256, 128, 64);
312
313 test_aligned_offset_realloc(256, 512, 0, 0);
314 test_aligned_offset_realloc(256, 128, 0, 0);
315 test_aligned_offset_realloc(256, 512, 4, 0);
316 test_aligned_offset_realloc(256, 128, 4, 0);
317 test_aligned_offset_realloc(256, 512, 8, 0);
318 test_aligned_offset_realloc(256, 128, 8, 0);
319 test_aligned_offset_realloc(256, 512, 16, 0);
320 test_aligned_offset_realloc(256, 128, 16, 0);
321 test_aligned_offset_realloc(256, 512, 32, 0);
322 test_aligned_offset_realloc(256, 128, 32, 0);
323 test_aligned_offset_realloc(256, 512, 64, 0);
324 test_aligned_offset_realloc(256, 128, 64, 0);
325
326 test_aligned_offset_realloc(256, 512, 0, 4);
327 test_aligned_offset_realloc(256, 128, 0, 4);
328 test_aligned_offset_realloc(256, 512, 4, 4);
329 test_aligned_offset_realloc(256, 128, 4, 4);
330 test_aligned_offset_realloc(256, 512, 8, 4);
331 test_aligned_offset_realloc(256, 128, 8, 4);
332 test_aligned_offset_realloc(256, 512, 16, 4);
333 test_aligned_offset_realloc(256, 128, 16, 4);
334 test_aligned_offset_realloc(256, 512, 32, 4);
335 test_aligned_offset_realloc(256, 128, 32, 4);
336 test_aligned_offset_realloc(256, 512, 64, 4);
337 test_aligned_offset_realloc(256, 128, 64, 4);
338
339 test_aligned_offset_realloc(256, 512, 0, 8);
340 test_aligned_offset_realloc(256, 128, 0, 8);
341 test_aligned_offset_realloc(256, 512, 4, 8);
342 test_aligned_offset_realloc(256, 128, 4, 8);
343 test_aligned_offset_realloc(256, 512, 8, 8);
344 test_aligned_offset_realloc(256, 128, 8, 8);
345 test_aligned_offset_realloc(256, 512, 16, 8);
346 test_aligned_offset_realloc(256, 128, 16, 8);
347 test_aligned_offset_realloc(256, 512, 32, 8);
348 test_aligned_offset_realloc(256, 128, 32, 8);
349 test_aligned_offset_realloc(256, 512, 64, 8);
350 test_aligned_offset_realloc(256, 128, 64, 8);
351
352 test_aligned_offset_realloc(256, 512, 0, 16);
353 test_aligned_offset_realloc(256, 128, 0, 16);
354 test_aligned_offset_realloc(256, 512, 4, 16);
355 test_aligned_offset_realloc(256, 128, 4, 16);
356 test_aligned_offset_realloc(256, 512, 8, 16);
357 test_aligned_offset_realloc(256, 128, 8, 16);
358 test_aligned_offset_realloc(256, 512, 16, 16);
359 test_aligned_offset_realloc(256, 128, 16, 16);
360 test_aligned_offset_realloc(256, 512, 32, 16);
361 test_aligned_offset_realloc(256, 128, 32, 16);
362 test_aligned_offset_realloc(256, 512, 64, 16);
363 test_aligned_offset_realloc(256, 128, 64, 16);
364
365 test_aligned_offset_realloc(256, 512, 0, 32);
366 test_aligned_offset_realloc(256, 128, 0, 32);
367 test_aligned_offset_realloc(256, 512, 4, 32);
368 test_aligned_offset_realloc(256, 128, 4, 32);
369 test_aligned_offset_realloc(256, 512, 8, 32);
370 test_aligned_offset_realloc(256, 128, 8, 32);
371 test_aligned_offset_realloc(256, 512, 16, 32);
372 test_aligned_offset_realloc(256, 128, 16, 32);
373 test_aligned_offset_realloc(256, 512, 32, 32);
374 test_aligned_offset_realloc(256, 128, 32, 32);
375 test_aligned_offset_realloc(256, 512, 64, 32);
376 test_aligned_offset_realloc(256, 128, 64, 32);
377
378 test_aligned_offset_realloc(256, 512, 0, 64);
379 test_aligned_offset_realloc(256, 128, 0, 64);
380 test_aligned_offset_realloc(256, 512, 4, 64);
381 test_aligned_offset_realloc(256, 128, 4, 64);
382 test_aligned_offset_realloc(256, 512, 8, 64);
383 test_aligned_offset_realloc(256, 128, 8, 64);
384 test_aligned_offset_realloc(256, 512, 16, 64);
385 test_aligned_offset_realloc(256, 128, 16, 64);
386 test_aligned_offset_realloc(256, 512, 32, 64);
387 test_aligned_offset_realloc(256, 128, 32, 64);
388 test_aligned_offset_realloc(256, 512, 64, 64);
389 test_aligned_offset_realloc(256, 128, 64, 64);
390
391 test_aligned_offset_realloc(256, 512, 0, 96);
392 test_aligned_offset_realloc(256, 128, 0, 96);
393 test_aligned_offset_realloc(256, 512, 4, 96);
394 test_aligned_offset_realloc(256, 128, 4, 96);
395 test_aligned_offset_realloc(256, 512, 8, 96);
396 test_aligned_offset_realloc(256, 128, 8, 96);
397 test_aligned_offset_realloc(256, 512, 16, 96);
398 test_aligned_offset_realloc(256, 128, 16, 96);
399 test_aligned_offset_realloc(256, 512, 32, 96);
400 test_aligned_offset_realloc(256, 128, 32, 96);
401 test_aligned_offset_realloc(256, 512, 64, 96);
402 test_aligned_offset_realloc(256, 128, 64, 96);
403
404 test_aligned_offset_realloc(256, 512, 0, 112);
405 test_aligned_offset_realloc(256, 128, 0, 112);
406 test_aligned_offset_realloc(256, 512, 4, 112);
407 test_aligned_offset_realloc(256, 128, 4, 112);
408 test_aligned_offset_realloc(256, 512, 8, 112);
409 test_aligned_offset_realloc(256, 128, 8, 112);
410 test_aligned_offset_realloc(256, 512, 16, 112);
411 test_aligned_offset_realloc(256, 128, 16, 112);
412 test_aligned_offset_realloc(256, 512, 32, 112);
413 test_aligned_offset_realloc(256, 128, 32, 112);
414 test_aligned_offset_realloc(256, 512, 64, 112);
415 test_aligned_offset_realloc(256, 128, 64, 112);
416}
#define skip(...)
Definition: atltest.h:64
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
static void test_aligned_malloc(unsigned int size, unsigned int alignment)
Definition: heap.c:34
static void test_aligned_offset_realloc(unsigned int size1, unsigned int size2, unsigned int alignment, unsigned int offset)
Definition: heap.c:163
static void *__cdecl * p_aligned_offset_realloc(void *, size_t, size_t, size_t)
static void *__cdecl * p_aligned_offset_malloc(size_t, size_t, size_t)
static void *__cdecl * p_aligned_realloc(void *, size_t, size_t)
static void test_aligned_realloc(unsigned int size1, unsigned int size2, unsigned int alignment)
Definition: heap.c:92
static void *__cdecl * p_aligned_malloc(size_t, size_t)
static void test_aligned_offset_malloc(unsigned int size, unsigned int alignment, unsigned int offset)
Definition: heap.c:61

Referenced by START_TEST().

◆ test_aligned_malloc()

static void test_aligned_malloc ( unsigned int  size,
unsigned int  alignment 
)
static

Definition at line 34 of file heap.c.

35{
36 void *mem;
37
39
40 if ((alignment & (alignment - 1)) == 0)
41 ok(mem != NULL, "_aligned_malloc(%d, %d) failed\n", size, alignment);
42 else
43 ok(mem == NULL, "_aligned_malloc(%d, %d) should have failed\n", size, alignment);
44
45 if (mem)
46 {
47 ok(((DWORD_PTR)mem & (alignment ? alignment - 1 : 0)) == 0,
48 "_aligned_malloc(%d, %d) not aligned: %p\n", size, alignment, mem);
49 if (winetest_debug > 1)
50 {
51 void *saved;
52 saved = *(void **)((DWORD_PTR)((char *)mem - sizeof(void *)) & ~(sizeof(void *) - 1));
53 trace("_aligned_malloc(%3d, %3d) returns %p, saved = %p\n", size, alignment, mem, saved );
54 }
55 p_aligned_free(mem);
56 }
57 else
58 ok(errno == EINVAL, "_aligned_malloc(%d, %d) errno: %d != %d\n", size, alignment, errno, EINVAL);
59}
#define EINVAL
Definition: acclib.h:90
_Check_return_ _Ret_maybenull_ _In_ size_t alignment
Definition: align.cpp:48
#define trace
Definition: atltest.h:70
GLsizeiptr size
Definition: glext.h:5919
#define errno
Definition: errno.h:18
int winetest_debug
Definition: mem.c:349
uint32_t DWORD_PTR
Definition: typedefs.h:65

Referenced by test_aligned().

◆ test_aligned_offset_malloc()

static void test_aligned_offset_malloc ( unsigned int  size,
unsigned int  alignment,
unsigned int  offset 
)
static

Definition at line 61 of file heap.c.

62{
63 void *mem;
64
66
67 if ((alignment & (alignment - 1)) == 0)
68 if (offset < size)
69 ok(mem != NULL, "_aligned_offset_malloc(%d, %d, %d) failed\n", size, alignment, offset);
70 else
71 ok(errno == EINVAL, "_aligned_offset_malloc(%d, %d, %d) errno: %d != %d\n", size, alignment, offset, errno, EINVAL);
72 else
73 ok(mem == NULL, "_aligned_offset_malloc(%d, %d, %d) should have failed\n", size, alignment, offset);
74
75 if (mem)
76 {
77 ok(((DWORD_PTR)((char *)mem + offset) & (alignment ? alignment - 1 : 0)) == 0,
78 "_aligned_offset_malloc(%d, %d, %d) not aligned: %p\n", size, alignment, offset, mem);
79 if (winetest_debug > 1)
80 {
81 void *saved;
82 saved = *(void **)((DWORD_PTR)((char *)mem - sizeof(void *)) & ~(sizeof(void *) - 1));
83 trace("_aligned_offset_malloc(%3d, %3d, %3d) returns %p, saved = %p\n",
84 size, alignment, offset, mem, saved);
85 }
86 p_aligned_free(mem);
87 }
88 else
89 ok(errno == EINVAL, "_aligned_offset_malloc(%d, %d, %d) errno: %d != %d\n", size, alignment, offset, errno, EINVAL);
90}
GLintptr offset
Definition: glext.h:5920

Referenced by test_aligned().

◆ test_aligned_offset_realloc()

static void test_aligned_offset_realloc ( unsigned int  size1,
unsigned int  size2,
unsigned int  alignment,
unsigned int  offset 
)
static

Definition at line 163 of file heap.c.

165{
166 void *mem, *mem1, *mem2;
167
169
170 if ((alignment & (alignment - 1)) == 0)
171 ok(mem != NULL, "_aligned_offset_malloc(%d, %d, %d) failed\n", size1, alignment, offset);
172 else
173 ok(mem == NULL, "_aligned_offset_malloc(%d, %d, %d) should have failed\n", size1, alignment, offset);
174
175 if (mem)
176 {
177 mem1 = malloc(size1);
178 if (mem1)
179 {
180 unsigned int i;
181 for (i = 0; i < size1; i++)
182 ((char *)mem)[i] = i + 1;
183 memcpy(mem1, mem, size1);
184 }
185
186 ok(((DWORD_PTR)((char *)mem + offset) & (alignment ? alignment - 1 : 0)) == 0,
187 "_aligned_offset_malloc(%d, %d, %d) not aligned: %p\n", size1, alignment, offset, mem);
188 if (winetest_debug > 1)
189 {
190 void *saved;
191 saved = *(void **)((DWORD_PTR)((char *)mem - sizeof(void *)) & ~(sizeof(void *) - 1));
192 trace("_aligned_offset_malloc(%3d, %3d, %3d) returns %p, saved = %p\n",
193 size1, alignment, offset, mem, saved);
194 }
195
197
198 ok(mem2 != NULL, "_aligned_offset_realloc(%p, %d, %d, %d) failed\n", mem, size2, alignment, offset);
199
200 if (mem2)
201 {
202 ok(((DWORD_PTR)((char *)mem + offset) & (alignment ? alignment - 1 : 0)) == 0,
203 "_aligned_offset_realloc(%p, %d, %d, %d) not aligned: %p\n", mem, size2, alignment, offset, mem2);
204 if (winetest_debug > 1)
205 {
206 void *saved;
207 saved = *(void **)((DWORD_PTR)((char *)mem2 - sizeof(void *)) & ~(sizeof(void *) - 1));
208 trace("_aligned_offset_realloc(%p, %3d, %3d, %3d) returns %p, saved = %p\n",
209 mem, size2, alignment, offset, mem2, saved);
210 }
211 if (mem1)
212 {
213 ok(memcmp(mem2, mem1, min(size1, size2))==0, "_aligned_offset_realloc(%p, %d, %d, %d) has different data\n", mem, size2, alignment, offset);
214 if (memcmp(mem2, mem1, min(size1, size2)) && winetest_debug > 1)
215 {
216 unsigned int i;
217 for (i = 0; i < min(size1, size2); i++)
218 {
219 if (((char *)mem2)[i] != ((char *)mem1)[i])
220 trace("%d: %02x != %02x\n", i, ((char *)mem2)[i] & 0xff, ((char *)mem1)[i] & 0xff);
221 }
222 }
223 }
224 p_aligned_free(mem2);
225 } else {
226 ok(errno == EINVAL, "_aligned_offset_realloc(%p, %d, %d, %d) errno: %d != %d\n", mem, size2, alignment, offset, errno, EINVAL);
227 p_aligned_free(mem);
228 }
229
230 free(mem1);
231 }
232 else
233 ok(errno == EINVAL, "_aligned_offset_malloc(%d, %d) errno: %d != %d\n", size1, alignment, errno, EINVAL);
234}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
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 memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55

Referenced by test_aligned().

◆ test_aligned_realloc()

static void test_aligned_realloc ( unsigned int  size1,
unsigned int  size2,
unsigned int  alignment 
)
static

Definition at line 92 of file heap.c.

93{
94 void *mem, *mem1, *mem2;
95
97
98 if ((alignment & (alignment - 1)) == 0)
99 ok(mem != NULL, "_aligned_malloc(%d, %d) failed\n", size1, alignment);
100 else
101 ok(mem == NULL, "_aligned_malloc(%d, %d) should have failed\n", size1, alignment);
102
103 if (mem)
104 {
105 mem1 = malloc(size1);
106 if (mem1)
107 {
108 unsigned int i;
109 for (i = 0; i < size1; i++)
110 ((char *)mem)[i] = i + 1;
111 memcpy(mem1, mem, size1);
112 }
113
114 ok(((DWORD_PTR)mem & (alignment ? alignment - 1 : 0)) == 0,
115 "_aligned_malloc(%d, %d) not aligned: %p\n", size1, alignment, mem);
116 if (winetest_debug > 1)
117 {
118 void *saved;
119 saved = *(void **)((DWORD_PTR)((char *)mem - sizeof(void *)) & ~(sizeof(void *) - 1));
120 trace("_aligned_malloc(%3d, %3d) returns %p, saved = %p\n", size1, alignment, mem, saved);
121 }
122
123 mem2 = p_aligned_realloc(mem, size2, alignment);
124
125 ok(mem2 != NULL, "_aligned_realloc(%p, %d, %d) failed\n", mem, size2, alignment);
126
127 if (mem2)
128 {
129 ok(((DWORD_PTR)mem2 & (alignment ? alignment - 1 : 0)) == 0,
130 "_aligned_realloc(%p, %d, %d) not aligned: %p\n", mem, size2, alignment, mem2);
131 if (winetest_debug > 1)
132 {
133 void *saved;
134 saved = *(void **)((DWORD_PTR)((char *)mem2 - sizeof(void *)) & ~(sizeof(void *) - 1));
135 trace("_aligned_realloc(%p, %3d, %3d) returns %p, saved = %p\n",
136 mem, size2, alignment, mem2, saved);
137 }
138 if (mem1)
139 {
140 ok(memcmp(mem2, mem1, min(size1, size2))==0, "_aligned_realloc(%p, %d, %d) has different data\n", mem, size2, alignment);
141 if (memcmp(mem2, mem1, min(size1, size2)) && winetest_debug > 1)
142 {
143 unsigned int i;
144 for (i = 0; i < min(size1, size2); i++)
145 {
146 if (((char *)mem2)[i] != ((char *)mem1)[i])
147 trace("%d: %02x != %02x\n", i, ((char *)mem2)[i] & 0xff, ((char *)mem1)[i] & 0xff);
148 }
149 }
150 }
151 p_aligned_free(mem2);
152 } else {
153 ok(errno == EINVAL, "_aligned_realloc(%p, %d, %d) errno: %d != %d\n", mem, size2, alignment, errno, EINVAL);
154 p_aligned_free(mem);
155 }
156
157 free(mem1);
158 }
159 else
160 ok(errno == EINVAL, "_aligned_malloc(%d, %d) errno: %d != %d\n", size1, alignment, errno, EINVAL);
161}

Referenced by test_aligned().

◆ test_calloc()

static void test_calloc ( void  )
static

Definition at line 499 of file heap.c.

500{
501 /* use function pointer to bypass gcc builtin */
502 void *(__cdecl *p_calloc)(size_t, size_t);
503 void *ptr;
504
505 p_calloc = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "calloc");
506
507 ptr = p_calloc(1, 0);
508 ok(ptr != NULL, "got %p\n", ptr);
509 free(ptr);
510
511 ptr = p_calloc(0, 0);
512 ok(ptr != NULL, "got %p\n", ptr);
513 free(ptr);
514
515 ptr = p_calloc(0, 1);
516 ok(ptr != NULL, "got %p\n", ptr);
517 free(ptr);
518
519 errno = 0;
520 ptr = p_calloc(~(size_t)0 / 2, ~(size_t)0 / 2);
521 ok(ptr == NULL || broken(ptr != NULL) /* winxp sp0 */, "got %p\n", ptr);
522 ok(errno == ENOMEM || broken(errno == 0) /* winxp, win2k3 */, "got errno %d\n", errno);
523 free(ptr);
524}
#define ENOMEM
Definition: acclib.h:84
#define __cdecl
Definition: accygwin.h:79
#define broken(x)
Definition: atltest.h:178
static PVOID ptr
Definition: dispmode.c:27

Referenced by START_TEST().

◆ test_malloc()

static void test_malloc ( void  )
static

Definition at line 470 of file heap.c.

471{
472 /* use function pointers to bypass gcc builtins */
473 void *(__cdecl *p_malloc)(size_t);
474 void *(__cdecl *p_realloc)(void *,size_t);
475 void *mem;
476
477 p_malloc = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "malloc");
478 p_realloc = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "realloc");
479
480 mem = p_malloc(0);
481 ok(mem != NULL, "memory not allocated for size 0\n");
482 free(mem);
483
484 mem = p_realloc(NULL, 10);
485 ok(mem != NULL, "memory not allocated\n");
486
487 mem = p_realloc(mem, 20);
488 ok(mem != NULL, "memory not reallocated\n");
489
490 mem = p_realloc(mem, 0);
491 ok(mem == NULL, "memory not freed\n");
492
493 mem = p_realloc(NULL, 0);
494 ok(mem != NULL, "memory not (re)allocated for size 0\n");
495
496 free(mem);
497}
static void *CDECL * p_malloc(size_t)

Referenced by START_TEST().

◆ test_sbheap()

static void test_sbheap ( void  )
static

Definition at line 418 of file heap.c.

419{
420 HMODULE msvcrt = GetModuleHandleA("msvcrt.dll");
421 void *mem;
422 int threshold;
423
424 p__set_sbh_threshold = (void*)GetProcAddress(msvcrt, "_set_sbh_threshold");
425 p__get_sbh_threshold = (void*)GetProcAddress(msvcrt, "_get_sbh_threshold");
426 if (!p__set_sbh_threshold || !p__get_sbh_threshold)
427 {
428 win_skip("_set_sbh_threshold not available\n");
429 return;
430 }
431
432 if(sizeof(void*) == 8) {
433 ok(!p__set_sbh_threshold(0), "_set_sbh_threshold succeeded\n");
434 ok(!p__set_sbh_threshold(1000), "_set_sbh_threshold succeeded\n");
435 return;
436 }
437
438 mem = malloc(1);
439 ok(mem != NULL, "malloc failed\n");
440
441 ok(p__set_sbh_threshold(1), "_set_sbh_threshold failed\n");
442 threshold = p__get_sbh_threshold();
443 ok(threshold == 16, "threshold = %d\n", threshold);
444
445 ok(p__set_sbh_threshold(8), "_set_sbh_threshold failed\n");
446 threshold = p__get_sbh_threshold();
447 ok(threshold == 16, "threshold = %d\n", threshold);
448
449 ok(p__set_sbh_threshold(1000), "_set_sbh_threshold failed\n");
450 threshold = p__get_sbh_threshold();
451 ok(threshold == 1008, "threshold = %d\n", threshold);
452
453 free(mem);
454
455 mem = malloc(1);
456 ok(mem != NULL, "malloc failed\n");
457 ok(!((UINT_PTR)mem & 0xf), "incorrect alignment (%p)\n", mem);
458
459 mem = realloc(mem, 10);
460 ok(mem != NULL, "realloc failed\n");
461 ok(!((UINT_PTR)mem & 0xf), "incorrect alignment (%p)\n", mem);
462
463 ok(p__set_sbh_threshold(0), "_set_sbh_threshold failed\n");
464 threshold = p__get_sbh_threshold();
465 ok(threshold == 0, "threshold = %d\n", threshold);
466
467 free(mem);
468}
#define realloc
Definition: debug_ros.c:6
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define win_skip
Definition: test.h:164

Referenced by START_TEST().

◆ void()

static void ( __cdecl p_aligned_free)
static