4 #include "tests/malloc.h"
6 #include "../../../config.h"
10 // Nb: assuming VG_MIN_MALLOC_SZB is 8 or more...
13 assert(sizeof(long int) == sizeof(void*));
15 #if !defined(MUSL_LIBC)
16 // Check behaviour of memalign/free for big alignment.
17 // In particular, the below aims at checking that a
18 // superblock with a big size is not marked as reclaimable
19 // if the superblock is used to provide a big aligned block
20 // (see bug 250101, comment #14).
21 // Valgrind m_mallocfree.c will allocate a big superblock for the memalign
22 // call and will split it in two. This split superblock was
23 // wrongly marked as reclaimable, which was then causing
24 // assert failures (as reclaimable blocks cannot be split).
25 p
= memalign(1024 * 1024, 4 * 1024 * 1024 + 1);
26 assert(p
&& (0 == (long)p
% (1024 * 1024)));
27 // We allocate (and then free) a piece of memory smaller than
28 // the hole created in the big superblock.
29 // If the superblock is marked as reclaimable, the below free(s) will cause
30 // an assert. Note that the test has to be run with a --free-list-vol
31 // parameter smaller than the released blocks size to ensure the free is directly
32 // executed (otherwise memcheck does not really release the memory and so
33 // the bug is not properly tested).
34 piece
= malloc(1024 * 1000);
39 // Same as above but do the free in the reverse order.
40 p
= memalign(1024 * 1024, 4 * 1024 * 1024 + 1);
41 assert(p
&& (0 == (long)p
% (1024 * 1024)));
42 piece
= malloc(1024 * 100);
48 assert(p
&& (0 == (long)p
% 8));
50 assert(p
&& (0 == (long)p
% 8));
52 assert(p
&& (0 == (long)p
% 8));
54 assert(p
&& (0 == (long)p
% 8));
56 assert(p
&& (0 == (long)p
% 8));
58 assert(p
&& (0 == (long)p
% 8));
61 assert(p
&& (0 == (long)p
% 8));
63 assert(p
&& (0 == (long)p
% 8));
65 assert(p
&& (0 == (long)p
% 16));
67 p
= memalign(31, 100);
68 assert(p
&& (0 == (long)p
% 32));
69 p
= memalign(32, 100);
70 assert(p
&& (0 == (long)p
% 32));
71 p
= memalign(33, 100);
72 assert(p
&& (0 == (long)p
% 64));
74 p
= memalign(4095, 100);
75 assert(p
&& (0 == (long)p
% 4096));
76 p
= memalign(4096, 100);
77 assert(p
&& (0 == (long)p
% 4096));
78 p
= memalign(4097, 100);
79 assert(p
&& (0 == (long)p
% 8192));
81 p
= memalign(4 * 1024 * 1024, 100);
82 assert(p
&& (0 == (long)p
% (4 * 1024 * 1024)));
83 p
= memalign(16 * 1024 * 1024, 100);
84 assert(p
&& (0 == (long)p
% (16 * 1024 * 1024)));
88 assert(p
&& (0 == (long)p
% 256));
90 p
= memalign(1024 * 1024, 4 * 1024 * 1024 + 1);
91 assert(p
&& (0 == (long)p
% (1024 * 1024)));
92 piece
= malloc(1024 * 1000); assert (piece
);
95 p
= memalign(1024 * 1024, 4 * 1024 * 1024 + 1);
96 assert(p
&& (0 == (long)p
% (1024 * 1024)));
97 piece
= malloc(1024 * 100);
103 p
= memalign(0, 100);
104 assert(p
&& (0 == (long)p
% 8));
105 p
= memalign(1, 100);
106 assert(p
&& (0 == (long)p
% 8));
107 p
= memalign(2, 100);
108 assert(p
&& (0 == (long)p
% 8));
109 p
= memalign(3, 100);
111 //assert(errno == EINVAL);
113 p
= memalign(4, 100);
114 assert(p
&& 0 == (long)p
% 8);
115 p
= memalign(5, 100);
117 //assert(errno == EINVAL);
119 p
= memalign(7, 100);
121 //assert(errno == EINVAL);
123 p
= memalign(8, 100);
124 assert(p
&& (0 == (long)p
% 8));
125 p
= memalign(9, 100);
127 //assert(errno == EINVAL);
129 p
= memalign(31, 100);
131 //assert(errno == EINVAL);
132 p
= memalign(32, 100);
133 assert(p
&& (0 == (long)p
% 32));
135 p
= memalign(33, 100);
137 //assert(errno == EINVAL);
139 p
= memalign(4095, 100);
141 //assert(errno == EINVAL);
142 p
= memalign(4096, 100);
143 assert(p
&& (0 == (long)p
% 4096));
145 p
= memalign(4097, 100);
147 //assert(errno == EINVAL);
149 p
= memalign(4 * 1024 * 1024, 100);
150 assert(p
&& (0 == (long)p
% (4 * 1024 * 1024)));
151 p
= memalign(16 * 1024 * 1024, 100);
152 assert(p
&& (0 == (long)p
% (16 * 1024 * 1024)));
155 p
= memalign(256, 0);
156 assert(p
&& (0 == (long)p
% 256));