1 //===--------------------- cxa_thread_atexit_test.cpp ---------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: libcxxabi-no-threads
11 // REQUIRES: linux
12 
13 // this test will only work if CMake detects a real __cxa_thread_atexit_impl
14 // at configure time. This function, however, was added only in glibc 2.18,
15 // and there are still plenty of systems only using 2.17 (Ex RHEL 7).
16 // XFAIL: libcxxabi-no-cxa-thread-atexit-impl
17 
18 #include <assert.h>
19 #include <cxxabi.h>
20 
21 static bool AtexitImplCalled = false;
22 
23 extern "C" int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj,
24                                         void *dso_symbol) {
25   assert(dtor == reinterpret_cast<void (*)(void *)>(1));
26   assert(obj == reinterpret_cast<void *>(2));
27   assert(dso_symbol == reinterpret_cast<void *>(3));
28   AtexitImplCalled = true;
29   return 4;
30 }
31 
32 int main() {
33   int RV = __cxxabiv1::__cxa_thread_atexit(
34       reinterpret_cast<void (*)(void *)>(1), reinterpret_cast<void *>(2),
35       reinterpret_cast<void *>(3));
36   assert(RV == 4);
37   assert(AtexitImplCalled);
38   return 0;
39 }
40