blob: c578f97d556421a2799c6db78ef5dfd88a2d0770 [file] [log] [blame]
njn7360f8e2003-09-04 20:57:51 +00001#include <assert.h>
2#include <stdio.h>
3#include <sys/syscall.h>
4#include <sys/types.h>
5#include <unistd.h>
6
7// kernel brk() and libc brk() act quite differently...
8
9int main(void)
10{
11 int i;
12 void* orig_ds = sbrk(0);
13 void* ds = orig_ds;
14 void* vals[10];
15 void* res;
nethercoteacac2fd2004-11-04 13:49:28 +000016#define EOL ((void*)( ~(long)0 ))
njn7360f8e2003-09-04 20:57:51 +000017 vals[0] = (void*)0;
18 vals[1] = (void*)1;
19 vals[2] = ds - 0x1; // small shrink
20 vals[3] = ds;
21 vals[4] = ds + 0x1000; // small growth
22 vals[5] = ds + 0x40000000; // too-big growth
23 vals[6] = ds + 0x500; // shrink a little, but still above start size
24 vals[7] = ds - 0x1; // shrink below start size
25// vals[8] = ds - 0x1000; // shrink a lot below start size (into text)
nethercoteacac2fd2004-11-04 13:49:28 +000026// vals[9] = EOL;
27 vals[8] = EOL;
njn7360f8e2003-09-04 20:57:51 +000028
tom959a2b82005-05-24 07:21:22 +000029 for (i = 0; EOL != vals[i]; i++) {
njn7360f8e2003-09-04 20:57:51 +000030 res = (void*)syscall(__NR_brk, vals[i]);
31 }
32
33 assert( 0 == brk(orig_ds) ); // libc brk()
34
nethercoteacac2fd2004-11-04 13:49:28 +000035 for (i = 0; EOL != vals[i]; i++) {
njn7360f8e2003-09-04 20:57:51 +000036 res = (void*)brk(vals[i]);
37 }
38
39 return 0;
40}