blob: f86e0304503698ac2a99b006f90ae92c8f3ead5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#define CHUNK_SIZE_FROM_INDEX(i) ((1 << ((i) + 5)))
#include <printf.h>
#include <heap.h>
#include <libc.h>
#include <random.h>
#include <smp.h>
#include <paging.h>
//will delete later
static uint8_t lockeroni = 0;
void test_malloc(unsigned int cnt) {
void *testchunks[cnt];
unsigned int rindex[cnt], testchunk_size, i, x;
bzero(rindex, cnt * sizeof(unsigned int));
for(x = 0; x < cnt; x++) {
testchunk_size = (CHUNK_SIZE_FROM_INDEX(randint() % 7) - 24);
testchunks[x] = malloc(testchunk_size);
printf("ALLOCATING CHUNK %p SIZE %i\n", (void *)testchunks[x] - 24, testchunk_size);
}
for(x = 0; x < cnt;) {
i = randint() % cnt;
if(rindex[i]) continue;
rindex[i] = x;
x++;
}
for(x = 0; x < cnt; x++) {
//printf("FREEING CHUNK %p\n", (void *)testchunks[rindex[x]]);
free(testchunks[rindex[x]]);
}
printf("\nmalloc tester:\n");
printf("THIS NEEDS TO BE EMPTY______________\n");
debug_heap();
printf("____________________________________\n");
unlock(&lockeroni);
}
uint8_t cores_waiting = 4;
void sync_malloc() {
void *mtest;
asm("lock decb [%0]\n"
"spinlock:\n"
"cmpb [%0], 0\n"
"jnz spinlock\n"
::"m"(cores_waiting));
mtest = palloc(0x1000);
printf("Make sure none of these match -> %lx\n", mtest);
}
|