1*7c3d14c8STreehugger Robot // In a non-forking sandbox, we can't spawn an external symbolizer, but dladdr()
2*7c3d14c8STreehugger Robot // should still work and provide function names. No line numbers though.
3*7c3d14c8STreehugger Robot // Second, `atos` symbolizer can't inspect a process that has an inaccessible
4*7c3d14c8STreehugger Robot // task port, in which case we should again fallback to dladdr gracefully.
5*7c3d14c8STreehugger Robot
6*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -o %t
7*7c3d14c8STreehugger Robot // RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny process-fork)' %t 2>&1 | FileCheck %s
8*7c3d14c8STreehugger Robot // RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s
9*7c3d14c8STreehugger Robot // RUN: env ASAN_SYMBOLIZER_PATH="" not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s
10*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 %s -o %t
11*7c3d14c8STreehugger Robot // RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny process-fork)' %t 2>&1 | FileCheck %s
12*7c3d14c8STreehugger Robot // RUN: not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s
13*7c3d14c8STreehugger Robot // RUN: env ASAN_SYMBOLIZER_PATH="" not %run sandbox-exec -p '(version 1)(allow default)(deny mach-priv-task-port)' %t 2>&1 | FileCheck %s
14*7c3d14c8STreehugger Robot
15*7c3d14c8STreehugger Robot #include <stdlib.h>
main()16*7c3d14c8STreehugger Robot int main() {
17*7c3d14c8STreehugger Robot char *x = (char*)malloc(10 * sizeof(char));
18*7c3d14c8STreehugger Robot free(x);
19*7c3d14c8STreehugger Robot return x[5];
20*7c3d14c8STreehugger Robot // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
21*7c3d14c8STreehugger Robot // CHECK: {{READ of size 1 at 0x.* thread T0}}
22*7c3d14c8STreehugger Robot // CHECK: {{ #0 0x.* in main}}
23*7c3d14c8STreehugger Robot // CHECK: {{freed by thread T0 here:}}
24*7c3d14c8STreehugger Robot // CHECK: {{ #0 0x.* in wrap_free}}
25*7c3d14c8STreehugger Robot // CHECK: {{ #1 0x.* in main}}
26*7c3d14c8STreehugger Robot // CHECK: {{previously allocated by thread T0 here:}}
27*7c3d14c8STreehugger Robot // CHECK: {{ #0 0x.* in wrap_malloc}}
28*7c3d14c8STreehugger Robot // CHECK: {{ #1 0x.* in main}}
29*7c3d14c8STreehugger Robot }
30