Files
clang-p2996/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp
Mitch Phillips f1a47181f5 [hwasan] Remove untagging of kernel-consumed memory
Now that page aliasing for x64 has landed, we don't need to worry about
passing tagged pointers to libc, and thus D98875 removed it.
Unfortunately, we still test on aarch64 devices that don't have the
kernel tagged address ABI (https://reviews.llvm.org/D98875#2649269).

All the memory that we pass to the kernel in these tests is from global
variables. Instead of having architecture-specific untagging mechanisms
for this memory, let's just not tag the globals.

Reviewed By: eugenis, morehouse

Differential Revision: https://reviews.llvm.org/D101121
2021-04-23 11:04:36 -07:00

54 lines
1.3 KiB
C++

// Test that Thread objects are reused.
// RUN: %clangxx_hwasan -mllvm -hwasan-globals=0 -mllvm -hwasan-instrument-stack=0 %s -o %t && %env_hwasan_opts=verbose_threads=1 %run %t 2>&1 | FileCheck %s
#include <assert.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sanitizer/hwasan_interface.h>
pthread_barrier_t bar;
void *threadfn(void *) {
pthread_barrier_wait(&bar);
return nullptr;
}
void start_stop_threads() {
constexpr int N = 2;
pthread_t threads[N];
pthread_barrier_init(&bar, nullptr, N + 1);
for (auto &t : threads)
pthread_create(&t, nullptr, threadfn, nullptr);
pthread_barrier_wait(&bar);
for (auto &t : threads)
pthread_join(t, nullptr);
pthread_barrier_destroy(&bar);
}
int main() {
// Cut off initial threads.
// CHECK: === test start ===
fprintf(stderr, "=== test start ===\n");
// CHECK: Creating : T{{[0-9]+}} [[A:0x[0-9a-f]+]] stack:
// CHECK: Creating : T{{[0-9]+}} [[B:0x[0-9a-f]+]] stack:
start_stop_threads();
// CHECK-DAG: Creating : T{{[0-9]+}} [[A]] stack:
// CHECK-DAG: Creating : T{{[0-9]+}} [[B]] stack:
start_stop_threads();
// CHECK-DAG: Creating : T{{[0-9]+}} [[A]] stack:
// CHECK-DAG: Creating : T{{[0-9]+}} [[B]] stack:
start_stop_threads();
return 0;
}