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 | |
njn | 2a513bf | 2005-06-30 02:34:32 +0000 | [diff] [blame] | 9 | // This is the biggest word-sized signed number. We use a signed number, |
| 10 | // even though malloc takes an unsigned SizeT, because the "silly malloc |
| 11 | // arg" checking done by memcheck treats the arg like a signed int in |
| 12 | // order to detect the passing of a silly size arg like -1. |
| 13 | unsigned long size = (~(0UL)) >> 1; |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 14 | |
| 15 | fprintf(stderr, "Attempting too-big malloc()...\n"); |
| 16 | p = malloc(size); // way too big! |
| 17 | if (p) |
| 18 | fprintf(stderr, "huge malloc() succeeded??\n"); |
| 19 | |
| 20 | fprintf(stderr, "Attempting too-big mmap()...\n"); |
| 21 | p = mmap( 0, size, PROT_READ|PROT_WRITE|PROT_EXEC, |
| 22 | MAP_PRIVATE|MAP_ANON, -1, 0 ); |
sewardj | 90527e3 | 2006-10-17 11:09:03 +0000 | [diff] [blame] | 23 | if (-1 != (long)p) |
nethercote | 57e36b3 | 2004-07-10 14:56:28 +0000 | [diff] [blame] | 24 | fprintf(stderr, "huge mmap() succeeded??\n"); |
| 25 | |
| 26 | return 0; |
| 27 | } |