1
1
// This test is broken with shared libstdc++ / libc++ on Android.
2
2
// RUN: %clangxx_hwasan -static-libstdc++ %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=GOOD
3
+ // RUN: %clangxx_hwasan -static-libstdc++ -DMALLOCEDSTACK %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=GOOD
3
4
// RUN: %clangxx_hwasan -static-libstdc++ -DNO_SANITIZE_F %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=GOOD
4
5
// RUN: %clangxx_hwasan_oldrt -static-libstdc++ %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=GOOD
5
6
// RUN: %clangxx_hwasan_oldrt -static-libstdc++ %s -mllvm -hwasan-instrument-landing-pads=0 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=BAD
8
9
// RISC-V target doesn't support oldrt
9
10
// REQUIRES: aarch64-target-arch
10
11
11
- #include < stdexcept >
12
+ #include < cassert >
12
13
#include < cstdio>
14
+ #include < errno.h>
15
+ #include < pthread.h>
16
+ #include < sanitizer/hwasan_interface.h>
17
+ #include < stdexcept>
18
+ #include < string.h>
13
19
14
20
static void optimization_barrier (void * arg) {
15
21
asm volatile (" " : : " r" (arg) : " memory" );
@@ -42,12 +48,12 @@ __attribute__((noinline, no_sanitize("hwaddress"))) void after_catch() {
42
48
hwasan_read (&x[0 ], sizeof (x));
43
49
}
44
50
45
-
46
51
__attribute__ ((noinline))
47
52
#ifdef NO_SANITIZE_F
48
53
__attribute__ ((no_sanitize(" hwaddress" )))
49
54
#endif
50
- void f () {
55
+ void *
56
+ f (void *) {
51
57
char x[1000 ];
52
58
try {
53
59
// Put two tagged frames on the stack, throw an exception from the deepest one.
@@ -63,8 +69,32 @@ void f() {
63
69
// GOOD: hello
64
70
printf (" %s\n " , e.what ());
65
71
}
72
+ return nullptr ;
66
73
}
67
74
68
75
int main () {
69
- f ();
76
+ __hwasan_enable_allocator_tagging ();
77
+ #ifdef MALLOCEDSTACK
78
+ pthread_attr_t attr;
79
+ void *stack = malloc (PTHREAD_STACK_MIN);
80
+ assert (pthread_attr_init (&attr) == 0 );
81
+ if (pthread_attr_setstack (&attr, stack, PTHREAD_STACK_MIN) != 0 ) {
82
+ fprintf (stderr, " pthread_attr_setstack: %s" , strerror (errno));
83
+ abort ();
84
+ }
85
+ pthread_t thid;
86
+ if (pthread_create (&thid, &attr, f, nullptr ) != 0 ) {
87
+ fprintf (stderr, " pthread_create: %s" , strerror (errno));
88
+ abort ();
89
+ }
90
+ void *ret;
91
+ if (pthread_join (thid, &ret) != 0 ) {
92
+ fprintf (stderr, " pthread_join: %s" , strerror (errno));
93
+ abort ();
94
+ }
95
+ assert (pthread_attr_destroy (&attr) == 0 );
96
+ free (stack);
97
+ #else
98
+ f (nullptr );
99
+ #endif
70
100
}
0 commit comments