1// Check that ASan correctly detects SEGV on the zero page.
2// RUN: %clangxx_asan %s -o %t && not %run %t 2>&1 | FileCheck %s
3
4// Handled as a codesigning violation and exits with SIGKILL not SEGV
5// UNSUPPORTED: ios
6
7
8#if defined(_MSC_VER) && !defined(__CLANG__)
9# define __has_feature(x) 0
10#endif
11
12#if __has_feature(ptrauth_calls)
13# include <ptrauth.h>
14#endif
15
16typedef void void_f();
17int main() {
18 void_f *func = (void_f *)0x4;
19#if __has_feature(ptrauth_calls)
20 func = ptrauth_sign_unauthenticated(
21 func, ptrauth_key_function_pointer, 0);
22#endif
23 func();
24 // x86 reports the SEGV with both address=4 and pc=4.
25 // On PowerPC64 ELFv1, the pointer is taken to be a function-descriptor
26 // pointer out of which three 64-bit quantities are read. This will SEGV, but
27 // the compiler is free to choose the order. As a result, the address is
28 // either 0x4, 0xc or 0x14. The pc is still in main() because it has not
29 // actually made the call when the faulting access occurs.
30 // CHECK: {{AddressSanitizer: (SEGV|access-violation).*(address|pc) 0x0*[45c]}}
31 return 0;
32}
33

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of compiler-rt/test/asan/TestCases/zero_page_pc.cpp