| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target hwaddress_exec } */ |
| 3 |
/* { dg-shouldfail "hwasan" } */ |
| 4 |
/* { dg-additional-options "-lpthread" } */ |
| 5 |
|
| 6 |
/* This checks the interceptor ABI pthread hooks. |
| 7 |
The stack of the thread that is finishing must be cleared of shadow tags |
| 8 |
when that thread exits. */ |
| 9 |
|
| 10 |
#include <pthread.h> |
| 11 |
|
| 12 |
#ifdef __cplusplus |
| 13 |
extern "C" { |
| 14 |
#endif |
| 15 |
extern int printf (char const *, ...); |
| 16 |
#ifdef __cplusplus |
| 17 |
} |
| 18 |
#endif |
| 19 |
typedef __UINTPTR_TYPE__ uintptr_t; |
| 20 |
typedef __UINT64_TYPE__ uint64_t; |
| 21 |
|
| 22 |
__attribute__ ((noinline)) |
| 23 |
void * Ident (void * argument) |
| 24 |
{ |
| 25 |
return argument; |
| 26 |
} |
| 27 |
|
| 28 |
void * |
| 29 |
pthread_stack_is_cleared (void *argument) |
| 30 |
{ |
| 31 |
(void)argument; |
| 32 |
int internal_array[16] = {0}; |
| 33 |
return Ident((void*)internal_array); |
| 34 |
} |
| 35 |
|
| 36 |
int |
| 37 |
main (int argc, char **argv) |
| 38 |
{ |
| 39 |
int argument[100] = {0}; |
| 40 |
argument[1] = 10; |
| 41 |
pthread_t thread_index; |
| 42 |
pthread_create (&thread_index, NULL, pthread_stack_is_cleared, (void*)argument); |
| 43 |
|
| 44 |
void *retval; |
| 45 |
pthread_join (thread_index, &retval); |
| 46 |
|
| 47 |
printf ("(should fail): "); |
| 48 |
printf ("value left in stack is: %d\n", ((int *)retval)[0]); |
| 49 |
|
| 50 |
return (uintptr_t)retval; |
| 51 |
} |
| 52 |
|
| 53 |
/* { dg-output "HWAddressSanitizer: tag-mismatch on address 0x\[0-9a-f\]*.*" } */ |
| 54 |
/* { dg-output "READ of size 4 at 0x\[0-9a-f\]* tags: \[\[:xdigit:\]\]\[\[:xdigit:\]\]/00 \\(ptr/mem\\) in thread T0.*" } */ |
| 55 |
/* { dg-output "SUMMARY: HWAddressSanitizer: tag-mismatch \[^\n\]*.*" } */ |