1 //===-- Implementation of atexit ------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "src/stdlib/atexit.h"
10 #include "hdr/types/atexithandler_t.h"
11 #include "src/__support/common.h"
12 #include "src/stdlib/exit_handler.h"
13
14 namespace LIBC_NAMESPACE {
15
16 extern "C" {
17
__cxa_atexit(AtExitCallback * callback,void * payload,void *)18 int __cxa_atexit(AtExitCallback *callback, void *payload, void *) {
19 return add_atexit_unit(atexit_callbacks, {callback, payload});
20 }
21
__cxa_finalize(void * dso)22 void __cxa_finalize(void *dso) {
23 if (!dso)
24 call_exit_callbacks(atexit_callbacks);
25 }
26
27 } // extern "C"
28
29 LLVM_LIBC_FUNCTION(int, atexit, (__atexithandler_t callback)) {
30 return add_atexit_unit(
31 atexit_callbacks,
32 {&stdc_at_exit_func, reinterpret_cast<void *>(callback)});
33 }
34
35 } // namespace LIBC_NAMESPACE
36