1 | // RUN: %clangxx_asan %s -o %t |
2 | // RUN: not %run %t 0 2>&1 | FileCheck %s |
3 | // RUN: not %run %t n 2>&1 | FileCheck %s -check-prefix=CHECK -check-prefix=NON_EXEC |
4 | |
5 | // Not every OS lists every memory region in MemoryMappingLayout. |
6 | // This is limited to x86_64 because some architectures (e.g. the s390 before |
7 | // the z14) don't support NX mappings and others like PowerPC use function |
8 | // descriptors. |
9 | // REQUIRES: x86-target-arch && (linux || freebsd || netbsd) |
10 | |
11 | #include <assert.h> |
12 | |
13 | typedef void void_f(); |
14 | int main(int argc, char **argv) { |
15 | char *array = new char[42]; |
16 | void_f *func; |
17 | assert(argc > 1); |
18 | if (argv[1][0] == '0') { |
19 | func = (void_f *)0x04; |
20 | } else { |
21 | assert(argv[1][0] == 'n'); |
22 | func = (void_f *)array; |
23 | } |
24 | |
25 | func(); |
26 | // CHECK: DEADLYSIGNAL |
27 | // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) }} |
28 | // NON_EXEC: PC is at a non-executable region. Maybe a wild jump? |
29 | return 0; |
30 | } |
31 | |