-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HwasanThreadList::DontNeedThread clobbers Thread::next_, Breaking the freelist. As a result, only the top of the freelist ever gets reused, and the rest of it is lost. Since the Thread object with its associated ring buffer is only 8Kb, this is typically only noticable in long running processes, such as fuzzers. Fix the problem by switching from an intrusive linked list to a vector. Differential Revision: https://reviews.llvm.org/D91392
- Loading branch information
Showing
4 changed files
with
78 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Test that Thread objects are reused. | ||
// RUN: %clangxx_hwasan -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> | ||
|
||
#include "../utils.h" | ||
|
||
pthread_barrier_t bar; | ||
|
||
void *threadfn(void *) { | ||
pthread_barrier_wait(UNTAG(&bar)); | ||
return nullptr; | ||
} | ||
|
||
void start_stop_threads() { | ||
constexpr int N = 2; | ||
pthread_t threads[N]; | ||
|
||
pthread_barrier_init(UNTAG(&bar), nullptr, N + 1); | ||
for (auto &t : threads) | ||
pthread_create(&t, nullptr, threadfn, nullptr); | ||
|
||
pthread_barrier_wait(UNTAG(&bar)); | ||
|
||
for (auto &t : threads) | ||
pthread_join(t, nullptr); | ||
pthread_barrier_destroy(UNTAG(&bar)); | ||
} | ||
|
||
int main() { | ||
// Cut off initial threads. | ||
// CHECK: === test start === | ||
untag_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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters