| 1 |
// -*- C++ -*- |
| 2 |
//===----------------------------------------------------------------------===// |
| 3 |
// |
| 4 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 |
// See https://llvm.org/LICENSE.txt for license information. |
| 6 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 |
// |
| 8 |
//===----------------------------------------------------------------------===// |
| 9 |
|
| 10 |
// REQUIRES: linux && target=aarch64-{{.+}}-gnu |
| 11 |
|
| 12 |
// pthread_cancel in case of glibc calls _Unwind_ForcedUnwind from a signal on |
| 13 |
// the child_thread. This test ensures sigreturn is handled correctly (see: |
| 14 |
// UnwindCursor<A, R>::setInfoForSigReturn). |
| 15 |
|
| 16 |
#include <cstdlib> // defines __BIONIC__ |
| 17 |
|
| 18 |
// Android/Bionic does not support pthread_cancel. |
| 19 |
#ifdef __BIONIC__ |
| 20 |
int main(int, char**) { return 0; } |
| 21 |
#else |
| 22 |
|
| 23 |
#include <chrono> |
| 24 |
#include <condition_variable> |
| 25 |
#include <pthread.h> |
| 26 |
#include <unistd.h> |
| 27 |
|
| 28 |
using namespace std::chrono_literals; |
| 29 |
|
| 30 |
std::condition_variable cv; |
| 31 |
std::mutex cv_m; |
| 32 |
bool thread_ready = false; |
| 33 |
|
| 34 |
static void* test(void* arg) { |
| 35 |
(void)arg; |
| 36 |
thread_ready = true; |
| 37 |
cv.notify_all(); |
| 38 |
|
| 39 |
// This must be a pthread cancellation point. |
| 40 |
while (1) |
| 41 |
sleep(100); |
| 42 |
|
| 43 |
return (void*)1; |
| 44 |
} |
| 45 |
|
| 46 |
int main(int, char**) { |
| 47 |
pthread_t child_thread; |
| 48 |
std::unique_lock<std::mutex> lk(cv_m); |
| 49 |
pthread_create(&child_thread, 0, test, (void*)0); |
| 50 |
|
| 51 |
if (!cv.wait_for(lk, 100ms, [] { return thread_ready; })) |
| 52 |
return -1; |
| 53 |
|
| 54 |
pthread_cancel(child_thread); |
| 55 |
pthread_join(child_thread, NULL); |
| 56 |
return 0; |
| 57 |
} |
| 58 |
#endif |