brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1019 B · 94f4d80 Raw
38 lines · c
1// Tests that doing dfsan_flush() while another thread is executing doesn't2// segfault.3// RUN: %clang_dfsan %s -o %t && %run %t4 5#include <assert.h>6#include <pthread.h>7#include <sanitizer/dfsan_interface.h>8#include <stdlib.h>9 10static unsigned char GlobalBuf[4096];11static int ShutDownThread;12static int StartFlush;13 14// Access GlobalBuf continuously, causing its shadow to be touched as well.15// When main() calls dfsan_flush(), no segfault should be triggered.16static void *accessGlobalInBackground(void *Arg) {17  __atomic_store_n(&StartFlush, 1, __ATOMIC_RELEASE);18 19  while (!__atomic_load_n(&ShutDownThread, __ATOMIC_ACQUIRE))20    for (unsigned I = 0; I < sizeof(GlobalBuf); ++I)21      ++GlobalBuf[I];22 23  return NULL;24}25 26int main() {27  pthread_t Thread;28  pthread_create(&Thread, NULL, accessGlobalInBackground, NULL);29  while (!__atomic_load_n(&StartFlush, __ATOMIC_ACQUIRE))30    ; // Spin31 32  dfsan_flush();33 34  __atomic_store_n(&ShutDownThread, 1, __ATOMIC_RELEASE);35  pthread_join(Thread, NULL);36  return 0;37}38