ReactOS 0.4.16-dev-257-g6aa11ac
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 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_calloc (void)
 
 START_TEST (heap)
 

Function Documentation

◆ 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

◆ START_TEST()

START_TEST ( heap  )

Definition at line 492 of file heap.c.

493{
494 void *mem;
495
496 mem = malloc(0);
497 ok(mem != NULL, "memory not allocated for size 0\n");
498 free(mem);
499
500 mem = realloc(NULL, 10);
501 ok(mem != NULL, "memory not allocated\n");
502
503 mem = realloc(mem, 20);
504 ok(mem != NULL, "memory not reallocated\n");
505
506 mem = realloc(mem, 0);
507 ok(mem == NULL, "memory not freed\n");
508
509 mem = realloc(NULL, 0);
510 ok(mem != NULL, "memory not (re)allocated for size 0\n");
511
512 free(mem);
513
514 test_aligned();
515 test_sbheap();
516 test_calloc();
517}
#define ok(value,...)
Definition: atltest.h:57
#define realloc
Definition: debug_ros.c:6
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
static void test_calloc(void)
Definition: heap.c:465
static void test_aligned(void)
Definition: heap.c:240
static void test_sbheap(void)
Definition: heap.c:422
Definition: mem.c:349

◆ test_aligned()

static void test_aligned ( void  )
static

Definition at line 240 of file heap.c.

241{
242 HMODULE msvcrt = GetModuleHandleA("msvcrt.dll");
243
244 if (msvcrt == NULL)
245 return;
246
247 p_aligned_free = (void*)GetProcAddress(msvcrt, "_aligned_free");
248 p_aligned_malloc = (void*)GetProcAddress(msvcrt, "_aligned_malloc");
249 p_aligned_offset_malloc = (void*)GetProcAddress(msvcrt, "_aligned_offset_malloc");
250 p_aligned_realloc = (void*)GetProcAddress(msvcrt, "_aligned_realloc");
251 p_aligned_offset_realloc = (void*)GetProcAddress(msvcrt, "_aligned_offset_realloc");
252
254 {
255 skip("aligned memory tests skipped\n");
256 return;
257 }
258
259 test_aligned_malloc(256, 0);
260 test_aligned_malloc(256, 1);
261 test_aligned_malloc(256, 2);
262 test_aligned_malloc(256, 3);
263 test_aligned_malloc(256, 4);
264 test_aligned_malloc(256, 8);
265 test_aligned_malloc(256, 16);
266 test_aligned_malloc(256, 32);
267 test_aligned_malloc(256, 64);
268 test_aligned_malloc(256, 127);
269 test_aligned_malloc(256, 128);
270
277 test_aligned_offset_malloc(256, 16, 0);
278 test_aligned_offset_malloc(256, 32, 0);
279 test_aligned_offset_malloc(256, 64, 0);
280 test_aligned_offset_malloc(256, 127, 0);
281 test_aligned_offset_malloc(256, 128, 0);
282
289 test_aligned_offset_malloc(256, 16, 4);
290 test_aligned_offset_malloc(256, 32, 4);
291 test_aligned_offset_malloc(256, 64, 4);
292 test_aligned_offset_malloc(256, 127, 4);
293 test_aligned_offset_malloc(256, 128, 4);
294
297 test_aligned_offset_malloc(256, 8, 16);
298 test_aligned_offset_malloc(256, 8, 17);
299 test_aligned_offset_malloc(256, 8, 254);
300 test_aligned_offset_malloc(256, 8, 255);
301 test_aligned_offset_malloc(256, 8, 256);
302 test_aligned_offset_malloc(256, 8, 512);
303
304 test_aligned_realloc(256, 512, 0);
305 test_aligned_realloc(256, 128, 0);
306 test_aligned_realloc(256, 512, 4);
307 test_aligned_realloc(256, 128, 4);
308 test_aligned_realloc(256, 512, 8);
309 test_aligned_realloc(256, 128, 8);
310 test_aligned_realloc(256, 512, 16);
311 test_aligned_realloc(256, 128, 16);
312 test_aligned_realloc(256, 512, 32);
313 test_aligned_realloc(256, 128, 32);
314 test_aligned_realloc(256, 512, 64);
315 test_aligned_realloc(256, 128, 64);
316
317 test_aligned_offset_realloc(256, 512, 0, 0);
318 test_aligned_offset_realloc(256, 128, 0, 0);
319 test_aligned_offset_realloc(256, 512, 4, 0);
320 test_aligned_offset_realloc(256, 128, 4, 0);
321 test_aligned_offset_realloc(256, 512, 8, 0);
322 test_aligned_offset_realloc(256, 128, 8, 0);
323 test_aligned_offset_realloc(256, 512, 16, 0);
324 test_aligned_offset_realloc(256, 128, 16, 0);
325 test_aligned_offset_realloc(256, 512, 32, 0);
326 test_aligned_offset_realloc(256, 128, 32, 0);
327 test_aligned_offset_realloc(256, 512, 64, 0);
328 test_aligned_offset_realloc(256, 128, 64, 0);
329
330 test_aligned_offset_realloc(256, 512, 0, 4);
331 test_aligned_offset_realloc(256, 128, 0, 4);
332 test_aligned_offset_realloc(256, 512, 4, 4);
333 test_aligned_offset_realloc(256, 128, 4, 4);
334 test_aligned_offset_realloc(256, 512, 8, 4);
335 test_aligned_offset_realloc(256, 128, 8, 4);
336 test_aligned_offset_realloc(256, 512, 16, 4);
337 test_aligned_offset_realloc(256, 128, 16, 4);
338 test_aligned_offset_realloc(256, 512, 32, 4);
339 test_aligned_offset_realloc(256, 128, 32, 4);
340 test_aligned_offset_realloc(256, 512, 64, 4);
341 test_aligned_offset_realloc(256, 128, 64, 4);
342
343 test_aligned_offset_realloc(256, 512, 0, 8);
344 test_aligned_offset_realloc(256, 128, 0, 8);
345 test_aligned_offset_realloc(256, 512, 4, 8);
346 test_aligned_offset_realloc(256, 128, 4, 8);
347 test_aligned_offset_realloc(256, 512, 8, 8);
348 test_aligned_offset_realloc(256, 128, 8, 8);
349 test_aligned_offset_realloc(256, 512, 16, 8);
350 test_aligned_offset_realloc(256, 128, 16, 8);
351 test_aligned_offset_realloc(256, 512, 32, 8);
352 test_aligned_offset_realloc(256, 128, 32, 8);
353 test_aligned_offset_realloc(256, 512, 64, 8);
354 test_aligned_offset_realloc(256, 128, 64, 8);
355
356 test_aligned_offset_realloc(256, 512, 0, 16);
357 test_aligned_offset_realloc(256, 128, 0, 16);
358 test_aligned_offset_realloc(256, 512, 4, 16);
359 test_aligned_offset_realloc(256, 128, 4, 16);
360 test_aligned_offset_realloc(256, 512, 8, 16);
361 test_aligned_offset_realloc(256, 128, 8, 16);
362 test_aligned_offset_realloc(256, 512, 16, 16);
363 test_aligned_offset_realloc(256, 128, 16, 16);
364 test_aligned_offset_realloc(256, 512, 32, 16);
365 test_aligned_offset_realloc(256, 128, 32, 16);
366 test_aligned_offset_realloc(256, 512, 64, 16);
367 test_aligned_offset_realloc(256, 128, 64, 16);
368
369 test_aligned_offset_realloc(256, 512, 0, 32);
370 test_aligned_offset_realloc(256, 128, 0, 32);
371 test_aligned_offset_realloc(256, 512, 4, 32);
372 test_aligned_offset_realloc(256, 128, 4, 32);
373 test_aligned_offset_realloc(256, 512, 8, 32);
374 test_aligned_offset_realloc(256, 128, 8, 32);
375 test_aligned_offset_realloc(256, 512, 16, 32);
376 test_aligned_offset_realloc(256, 128, 16, 32);
377 test_aligned_offset_realloc(256, 512, 32, 32);
378 test_aligned_offset_realloc(256, 128, 32, 32);
379 test_aligned_offset_realloc(256, 512, 64, 32);
380 test_aligned_offset_realloc(256, 128, 64, 32);
381
382 test_aligned_offset_realloc(256, 512, 0, 64);
383 test_aligned_offset_realloc(256, 128, 0, 64);
384 test_aligned_offset_realloc(256, 512, 4, 64);
385 test_aligned_offset_realloc(256, 128, 4, 64);
386 test_aligned_offset_realloc(256, 512, 8, 64);
387 test_aligned_offset_realloc(256, 128, 8, 64);
388 test_aligned_offset_realloc(256, 512, 16, 64);
389 test_aligned_offset_realloc(256, 128, 16, 64);
390 test_aligned_offset_realloc(256, 512, 32, 64);
391 test_aligned_offset_realloc(256, 128, 32, 64);
392 test_aligned_offset_realloc(256, 512, 64, 64);
393 test_aligned_offset_realloc(256, 128, 64, 64);
394
395 test_aligned_offset_realloc(256, 512, 0, 96);
396 test_aligned_offset_realloc(256, 128, 0, 96);
397 test_aligned_offset_realloc(256, 512, 4, 96);
398 test_aligned_offset_realloc(256, 128, 4, 96);
399 test_aligned_offset_realloc(256, 512, 8, 96);
400 test_aligned_offset_realloc(256, 128, 8, 96);
401 test_aligned_offset_realloc(256, 512, 16, 96);
402 test_aligned_offset_realloc(256, 128, 16, 96);
403 test_aligned_offset_realloc(256, 512, 32, 96);
404 test_aligned_offset_realloc(256, 128, 32, 96);
405 test_aligned_offset_realloc(256, 512, 64, 96);
406 test_aligned_offset_realloc(256, 128, 64, 96);
407
408 test_aligned_offset_realloc(256, 512, 0, 112);
409 test_aligned_offset_realloc(256, 128, 0, 112);
410 test_aligned_offset_realloc(256, 512, 4, 112);
411 test_aligned_offset_realloc(256, 128, 4, 112);
412 test_aligned_offset_realloc(256, 512, 8, 112);
413 test_aligned_offset_realloc(256, 128, 8, 112);
414 test_aligned_offset_realloc(256, 512, 16, 112);
415 test_aligned_offset_realloc(256, 128, 16, 112);
416 test_aligned_offset_realloc(256, 512, 32, 112);
417 test_aligned_offset_realloc(256, 128, 32, 112);
418 test_aligned_offset_realloc(256, 512, 64, 112);
419 test_aligned_offset_realloc(256, 128, 64, 112);
420}
#define skip(...)
Definition: atltest.h:64
#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:38
static void test_aligned_offset_realloc(unsigned int size1, unsigned int size2, unsigned int alignment, unsigned int offset)
Definition: heap.c:167
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:96
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:65

Referenced by START_TEST().

◆ test_aligned_malloc()

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

Definition at line 38 of file heap.c.

39{
40 void *mem;
41
42 mem = p_aligned_malloc(size, alignment);
43
44 if ((alignment & (alignment - 1)) == 0)
45 ok(mem != NULL, "_aligned_malloc(%d, %d) failed\n", size, alignment);
46 else
47 ok(mem == NULL, "_aligned_malloc(%d, %d) should have failed\n", size, alignment);
48
49 if (mem)
50 {
51 ok(((DWORD_PTR)mem & (alignment ? alignment - 1 : 0)) == 0,
52 "_aligned_malloc(%d, %d) not aligned: %p\n", size, alignment, mem);
53 if (winetest_debug > 1)
54 {
55 void *saved;
56 saved = *(void **)((DWORD_PTR)((char *)mem - sizeof(void *)) & ~(sizeof(void *) - 1));
57 trace("_aligned_malloc(%3d, %3d) returns %p, saved = %p\n", size, alignment, mem, saved );
58 }
59 p_aligned_free(mem);
60 }
61 else
62 ok(errno == EINVAL, "_aligned_malloc(%d, %d) errno: %d != %d\n", size, alignment, errno, EINVAL);
63}
#define EINVAL
Definition: acclib.h:90
#define trace
Definition: atltest.h:70
GLsizeiptr size
Definition: glext.h:5919
#define errno
Definition: errno.h:18
int winetest_debug
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 65 of file heap.c.

66{
67 void *mem;
68
70
71 if ((alignment & (alignment - 1)) == 0)
72 if (offset < size)
73 ok(mem != NULL, "_aligned_offset_malloc(%d, %d, %d) failed\n", size, alignment, offset);
74 else
75 ok(errno == EINVAL, "_aligned_offset_malloc(%d, %d, %d) errno: %d != %d\n", size, alignment, offset, errno, EINVAL);
76 else
77 ok(mem == NULL, "_aligned_offset_malloc(%d, %d, %d) should have failed\n", size, alignment, offset);
78
79 if (mem)
80 {
81 ok(((DWORD_PTR)((char *)mem + offset) & (alignment ? alignment - 1 : 0)) == 0,
82 "_aligned_offset_malloc(%d, %d, %d) not aligned: %p\n", size, alignment, offset, mem);
83 if (winetest_debug > 1)
84 {
85 void *saved;
86 saved = *(void **)((DWORD_PTR)((char *)mem - sizeof(void *)) & ~(sizeof(void *) - 1));
87 trace("_aligned_offset_malloc(%3d, %3d, %3d) returns %p, saved = %p\n",
88 size, alignment, offset, mem, saved);
89 }
90 p_aligned_free(mem);
91 }
92 else
93 ok(errno == EINVAL, "_aligned_offset_malloc(%d, %d, %d) errno: %d != %d\n", size, alignment, offset, errno, EINVAL);
94}
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 167 of file heap.c.

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

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

Referenced by test_aligned().

◆ test_calloc()

static void test_calloc ( void  )
static

Definition at line 465 of file heap.c.

466{
467 /* use function pointer to bypass gcc builtin */
468 void *(__cdecl *p_calloc)(size_t, size_t);
469 void *ptr;
470
471 p_calloc = (void *)GetProcAddress( GetModuleHandleA("msvcrt.dll"), "calloc");
472
473 ptr = p_calloc(1, 0);
474 ok(ptr != NULL, "got %p\n", ptr);
475 free(ptr);
476
477 ptr = p_calloc(0, 0);
478 ok(ptr != NULL, "got %p\n", ptr);
479 free(ptr);
480
481 ptr = p_calloc(0, 1);
482 ok(ptr != NULL, "got %p\n", ptr);
483 free(ptr);
484
485 errno = 0;
486 ptr = p_calloc(~(size_t)0 / 2, ~(size_t)0 / 2);
487 ok(ptr == NULL || broken(ptr != NULL) /* winxp sp0 */, "got %p\n", ptr);
488 ok(errno == ENOMEM || broken(errno == 0) /* winxp, win2k3 */, "got errno %d\n", errno);
489 free(ptr);
490}
#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_sbheap()

static void test_sbheap ( void  )
static

Definition at line 422 of file heap.c.

423{
424 void *mem;
425 int threshold;
426
427 if(sizeof(void*) == 8) {
428 ok(!_set_sbh_threshold(0), "_set_sbh_threshold succeeded\n");
429 ok(!_set_sbh_threshold(1000), "_set_sbh_threshold succeeded\n");
430 return;
431 }
432
433 mem = malloc(1);
434 ok(mem != NULL, "malloc failed\n");
435
436 ok(_set_sbh_threshold(1), "_set_sbh_threshold failed\n");
437 threshold = _get_sbh_threshold();
438 ok(threshold == 16, "threshold = %d\n", threshold);
439
440 ok(_set_sbh_threshold(8), "_set_sbh_threshold failed\n");
441 threshold = _get_sbh_threshold();
442 ok(threshold == 16, "threshold = %d\n", threshold);
443
444 ok(_set_sbh_threshold(1000), "_set_sbh_threshold failed\n");
445 threshold = _get_sbh_threshold();
446 ok(threshold == 1008, "threshold = %d\n", threshold);
447
448 free(mem);
449
450 mem = malloc(1);
451 ok(mem != NULL, "malloc failed\n");
452 ok(!((UINT_PTR)mem & 0xf), "incorrect alignment (%p)\n", mem);
453
454 mem = realloc(mem, 10);
455 ok(mem != NULL, "realloc failed\n");
456 ok(!((UINT_PTR)mem & 0xf), "incorrect alignment (%p)\n", mem);
457
458 ok(_set_sbh_threshold(0), "_set_sbh_threshold failed\n");
459 threshold = _get_sbh_threshold();
460 ok(threshold == 0, "threshold = %d\n", threshold);
461
462 free(mem);
463}
_CRTIMP int __cdecl _set_sbh_threshold(_In_ size_t _NewValue)
_Check_return_ _CRTIMP size_t __cdecl _get_sbh_threshold(void)
Definition: heap.c:542
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274

Referenced by START_TEST().

◆ void()

static void ( __cdecl p_aligned_free)
static