xref: /aosp_15_r20/external/libcxxabi/test/cxa_thread_atexit_test.pass.cpp (revision c05d8e5dc3e10f6ce4317e8bc22cc4a25f55fa94)
1*c05d8e5dSAndroid Build Coastguard Worker //===--------------------- cxa_thread_atexit_test.cpp ---------------------===//
2*c05d8e5dSAndroid Build Coastguard Worker //
3*c05d8e5dSAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*c05d8e5dSAndroid Build Coastguard Worker //
5*c05d8e5dSAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*c05d8e5dSAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*c05d8e5dSAndroid Build Coastguard Worker //
8*c05d8e5dSAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*c05d8e5dSAndroid Build Coastguard Worker 
10*c05d8e5dSAndroid Build Coastguard Worker // UNSUPPORTED: libcxxabi-no-threads
11*c05d8e5dSAndroid Build Coastguard Worker // REQUIRES: linux
12*c05d8e5dSAndroid Build Coastguard Worker 
13*c05d8e5dSAndroid Build Coastguard Worker #include <assert.h>
14*c05d8e5dSAndroid Build Coastguard Worker #include <cxxabi.h>
15*c05d8e5dSAndroid Build Coastguard Worker 
16*c05d8e5dSAndroid Build Coastguard Worker static bool AtexitImplCalled = false;
17*c05d8e5dSAndroid Build Coastguard Worker 
__cxa_thread_atexit_impl(void (* dtor)(void *),void * obj,void * dso_symbol)18*c05d8e5dSAndroid Build Coastguard Worker extern "C" int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj,
19*c05d8e5dSAndroid Build Coastguard Worker                                         void *dso_symbol) {
20*c05d8e5dSAndroid Build Coastguard Worker   assert(dtor == reinterpret_cast<void (*)(void *)>(1));
21*c05d8e5dSAndroid Build Coastguard Worker   assert(obj == reinterpret_cast<void *>(2));
22*c05d8e5dSAndroid Build Coastguard Worker   assert(dso_symbol == reinterpret_cast<void *>(3));
23*c05d8e5dSAndroid Build Coastguard Worker   AtexitImplCalled = true;
24*c05d8e5dSAndroid Build Coastguard Worker   return 4;
25*c05d8e5dSAndroid Build Coastguard Worker }
26*c05d8e5dSAndroid Build Coastguard Worker 
main()27*c05d8e5dSAndroid Build Coastguard Worker int main() {
28*c05d8e5dSAndroid Build Coastguard Worker   int RV = __cxxabiv1::__cxa_thread_atexit(
29*c05d8e5dSAndroid Build Coastguard Worker       reinterpret_cast<void (*)(void *)>(1), reinterpret_cast<void *>(2),
30*c05d8e5dSAndroid Build Coastguard Worker       reinterpret_cast<void *>(3));
31*c05d8e5dSAndroid Build Coastguard Worker   assert(RV == 4);
32*c05d8e5dSAndroid Build Coastguard Worker   assert(AtexitImplCalled);
33*c05d8e5dSAndroid Build Coastguard Worker   return 0;
34*c05d8e5dSAndroid Build Coastguard Worker }
35