Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // Test max_redzone runtime option. |
| 2 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 3 | // RUN: %clangxx_asan -O0 %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:max_redzone=16 %run %t 0 2>&1 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 4 | // RUN: %clangxx_asan -O0 %s -o %t && %run %t 1 2>&1 |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 5 | // RUN: %clangxx_asan -O3 %s -o %t && env ASAN_OPTIONS=$ASAN_OPTIONS:max_redzone=16 %run %t 0 2>&1 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 6 | // RUN: %clangxx_asan -O3 %s -o %t && %run %t 1 2>&1 |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | #include <stdint.h> |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 11 | #include <sanitizer/allocator_interface.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 12 | |
| 13 | int main(int argc, char **argv) { |
| 14 | if (argc < 2) |
| 15 | return 1; |
| 16 | bool large_redzone = atoi(argv[1]); |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 17 | size_t before = __sanitizer_get_heap_size(); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 18 | void *pp[10000]; |
| 19 | for (int i = 0; i < 10000; ++i) |
| 20 | pp[i] = malloc(4096 - 64); |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 21 | size_t after = __sanitizer_get_heap_size(); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 22 | for (int i = 0; i < 10000; ++i) |
| 23 | free(pp[i]); |
| 24 | size_t diff = after - before; |
| 25 | return !(large_redzone ? diff > 46000000 : diff < 46000000); |
| 26 | } |