| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-require-effective-target hwaddress_exec } */ |
| 3 |
/* { dg-shouldfail "hwasan" } */ |
| 4 |
/* { dg-additional-options "-lpthread" } */ |
| 5 |
|
| 6 |
#include <pthread.h> |
| 7 |
|
| 8 |
#ifdef __cplusplus |
| 9 |
extern "C" { |
| 10 |
#endif |
| 11 |
extern int printf (char const *, ...); |
| 12 |
#ifdef __cplusplus |
| 13 |
} |
| 14 |
#endif |
| 15 |
typedef __UINTPTR_TYPE__ uintptr_t; |
| 16 |
typedef __UINT64_TYPE__ uint64_t; |
| 17 |
|
| 18 |
/* Test that tags are checked across different threads. |
| 19 |
i.e. if this thread tries to access a different threads memory with the |
| 20 |
incorrect tag, then this thread fails. */ |
| 21 |
void * |
| 22 |
failing_thread_function (void *argument) |
| 23 |
{ |
| 24 |
void * other = (void *)((uint64_t)argument & 0xffffffffffffffULL); |
| 25 |
int *num = (int*)argument; |
| 26 |
printf ("(should succeed): first number = %d\n", num[0]); |
| 27 |
printf ("(now should fail):\n"); |
| 28 |
|
| 29 |
int *othernum = (int*)other; |
| 30 |
printf (" second number = %d\n", othernum[0]); |
| 31 |
return (void *)1; |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
main (int argc, char **argv) |
| 36 |
{ |
| 37 |
int argument[100] = {0}; |
| 38 |
argument[1] = 10; |
| 39 |
pthread_t thread_index; |
| 40 |
pthread_create (&thread_index, NULL, failing_thread_function, (void*)argument); |
| 41 |
|
| 42 |
void *retval; |
| 43 |
pthread_join (thread_index, &retval); |
| 44 |
|
| 45 |
return (uintptr_t)retval; |
| 46 |
} |
| 47 |
|
| 48 |
/* { dg-output "HWAddressSanitizer: tag-mismatch on address 0x\[0-9a-f\]*.*" } */ |
| 49 |
/* { dg-output "READ of size 4 at 0x\[0-9a-f\]* tags: 00/\[\[:xdigit:\]\]\[\[:xdigit:\]\].* \\(ptr/mem\\) in thread T1.*" } */ |
| 50 |
/* { dg-output "Address 0x\[0-9a-f\]* is located in stack of thread T0.*" } */ |
| 51 |
/* { dg-output "SUMMARY: HWAddressSanitizer: tag-mismatch \[^\n\]*.*" } */ |