nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <sys/mman.h> |
| 3 | #include <stdio.h> |
| 4 | |
| 5 | int main(void) |
| 6 | { |
| 7 | void *p; |
| 8 | |
| 9 | int size = 2 * 1023 * 1024 * 1024; // just under 2^31 (2GB) |
| 10 | |
| 11 | fprintf(stderr, "Attempting too-big malloc()...\n"); |
| 12 | p = malloc(size); // way too big! |
| 13 | if (p) |
| 14 | fprintf(stderr, "huge malloc() succeeded??\n"); |
| 15 | |
| 16 | fprintf(stderr, "Attempting too-big mmap()...\n"); |
| 17 | p = mmap( 0, size, PROT_READ|PROT_WRITE|PROT_EXEC, |
| 18 | MAP_PRIVATE|MAP_ANON, -1, 0 ); |
| 19 | if (-1 != (int)p) |
| 20 | fprintf(stderr, "huge mmap() succeeded??\n"); |
| 21 | |
| 22 | return 0; |
| 23 | } |