njn | 7360f8e | 2003-09-04 20:57:51 +0000 | [diff] [blame] | 1 | #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 | |
| 9 | int main(void) |
| 10 | { |
| 11 | int i; |
| 12 | void* orig_ds = sbrk(0); |
| 13 | void* ds = orig_ds; |
| 14 | void* vals[10]; |
| 15 | void* res; |
nethercote | acac2fd | 2004-11-04 13:49:28 +0000 | [diff] [blame] | 16 | #define EOL ((void*)( ~(long)0 )) |
njn | 7360f8e | 2003-09-04 20:57:51 +0000 | [diff] [blame] | 17 | 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) |
nethercote | acac2fd | 2004-11-04 13:49:28 +0000 | [diff] [blame] | 26 | // vals[9] = EOL; |
| 27 | vals[8] = EOL; |
njn | 7360f8e | 2003-09-04 20:57:51 +0000 | [diff] [blame] | 28 | |
tom | 959a2b8 | 2005-05-24 07:21:22 +0000 | [diff] [blame] | 29 | for (i = 0; EOL != vals[i]; i++) { |
njn | 7360f8e | 2003-09-04 20:57:51 +0000 | [diff] [blame] | 30 | res = (void*)syscall(__NR_brk, vals[i]); |
| 31 | } |
| 32 | |
| 33 | assert( 0 == brk(orig_ds) ); // libc brk() |
| 34 | |
nethercote | acac2fd | 2004-11-04 13:49:28 +0000 | [diff] [blame] | 35 | for (i = 0; EOL != vals[i]; i++) { |
njn | 7360f8e | 2003-09-04 20:57:51 +0000 | [diff] [blame] | 36 | res = (void*)brk(vals[i]); |
| 37 | } |
| 38 | |
| 39 | return 0; |
| 40 | } |