7
int main(int ac, char **av)
9
int NUM = ac > 1 ? atoi(av[1]) : 0;
10
int REPS = ac > 2 ? atoi(av[2]) : 0;
12
for (int x = 0; x < REPS; x++) {
13
char* allocations[NUM];
14
for (int i = 0; i < NUM/2; i++) {
15
allocations[i] = (char*)malloc((11*i)%1024 + x);
16
//printf("zz alloc: %d\n", (int)allocations[i]);
17
assert(allocations[i]);
18
if (i > 10 && i%4 == 1 && allocations[i-10]) {
19
//printf("zz free: %d\n", (int)allocations[i-10]);
20
free(allocations[i-10]);
21
allocations[i-10] = NULL;
24
for (int i = NUM/2; i < NUM; i++) {
25
allocations[i] = (char*)malloc(1024*(i+1));
26
//printf("zz alloc: %d\n", (int)allocations[i]);
27
assert(allocations[i]);
28
if (i > 10 && i%4 != 1 && allocations[i-10]) {
29
//printf("zz free: %d\n", (int)allocations[i-10]);
30
free(allocations[i-10]);
31
allocations[i-10] = NULL;
34
char* first = allocations[0];
35
for (int i = 0; i < NUM; i++) {
37
//printf("zz free: %d\n", (int)allocations[i]);
41
char *last = (char*)malloc(512); // should be identical, as we free'd it all
42
//printf("zz last: %d\n", (int)last);
43
char *newer = (char*)malloc(512); // should be different
44
//printf("zz newer: %d\n", (int)newer);
48
#else // On OSX, it's been detected that memory is not necessarily allocated linearly, so skip this check and simulate success.
52
printf("*%d,%d*\n", c1, c2);
55
/* Some debugging tools: Make JS and native code work exactly the same */
57
time_t time ( time_t * timer )
59
if (timer) *timer = 1;
63
long sysconf(int name)
65
printf("sysconf: %d (30 is page size)\n", name);
69
void *sbrk(intptr_t increment)
71
static char spaace[1024*1024*1];
72
static intptr_t where = 0;
73
printf("sbrk! spaace=%d (%d,%d)\n", (int)&spaace[0], where, increment); // copy the value printed at runtime here in native code into your js
74
void *ret = &spaace[where];