summaryrefslogtreecommitdiff
path: root/libcxxabi/test/forced_unwind4.pass.cpp
blob: 2864426ca16dcd85667f3f5208ec496e6e9c9080 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: linux && target={{aarch64-.+}}

// pthread_cancel in case of glibc calls _Unwind_ForcedUnwind from a signal on
// the child_thread. This test ensures sigretrun is handled correctly (see:
// UnwindCursor<A, R>::setInfoForSigReturn).

#include <cstdlib> // defines __BIONIC__

// Android/Bionic does not support pthread_cancel.
#ifdef __BIONIC__
int main() {
  return 0;
}
#else

#include <chrono>
#include <condition_variable>
#include <pthread.h>
#include <unistd.h>

using namespace std::chrono_literals;

std::condition_variable cv;
std::mutex cv_m;
bool thread_ready = false;

static void* test(void* arg) {
  (void)arg;
  thread_ready = true;
  cv.notify_all();

  // This must be a pthread cancellation point.
  while (1)
    sleep(100);

  return (void*)1;
}

int main() {
  pthread_t child_thread;
  std::unique_lock<std::mutex> lk(cv_m);
  pthread_create(&child_thread, 0, test, (void*)0);

  if (!cv.wait_for(lk, 100ms, [] { return thread_ready; }))
    return -1;

  pthread_cancel(child_thread);
  pthread_join(child_thread, NULL);
  return 0;
}
#endif