-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_driller.c
72 lines (59 loc) · 1.43 KB
/
test_driller.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* test_driller.c
*
* Copyright 2007 Jean-Marc Saffroy <[email protected]>
* This file is part of the Driller library.
* Driller is free software, distributed under the terms of the
* GNU Lesser General Public License version 2.1.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "driller.h"
#define HEAP_ALLOC_SIZE (1L<<24) /* 16MB */
#define HEAP_ALLOC_CHUNK 3210
#define HEAP_ALLOC_CHUNK_COUNT (HEAP_ALLOC_SIZE/HEAP_ALLOC_CHUNK)
void f(int n) {
char buf[1024];
memset(buf, 0, sizeof(buf));
if(n > 0)
f(n-1);
}
#ifndef NODRILL
static void map_invalidate(struct map_rec *map) {
printf("map invalidate: %p-%p\n", map->start, map->end);
}
#endif
int main(int argc, char**argv) {
int i;
void **a;
void *b;
#ifndef NODRILL
driller_init();
driller_register_map_invalidate_cb(map_invalidate);
#endif
/* test heap */
a = malloc(HEAP_ALLOC_CHUNK_COUNT * sizeof(void*));
for(i = 0; i < HEAP_ALLOC_CHUNK_COUNT; i++)
a[i] = malloc(HEAP_ALLOC_CHUNK);
for(i = 0; i < HEAP_ALLOC_CHUNK_COUNT; i++)
free(a[i]);
free(a);
/* have dlmalloc call mremap */
b = malloc(HEAP_ALLOC_SIZE);
b = realloc(b, HEAP_ALLOC_SIZE * 2);
b = realloc(b, HEAP_ALLOC_SIZE / 2);
free(b);
/* vfork/exec should work */
system("env echo system: foobar");
/* test stack */
printf("grow the stack a bit\n");
f(1000);
#if 0
printf("try to exceed the stack limit\n");
f(8000);
#endif
printf("SUCCESS! exiting\n");
return 0;
}