2023-10-30 11:10:08 +02:00
|
|
|
#include <icxxabi.h>
|
2023-06-02 17:49:21 +03:00
|
|
|
|
2023-10-30 11:10:08 +02:00
|
|
|
#define ATEXIT_MAX_FUNCS 128
|
2023-06-02 17:49:21 +03:00
|
|
|
|
|
|
|
struct atexit_func_entry_t
|
|
|
|
{
|
2023-10-30 11:10:08 +02:00
|
|
|
void (*destructor)(void*);
|
|
|
|
void* data;
|
|
|
|
void* dso_handle;
|
2023-06-02 17:49:21 +03:00
|
|
|
};
|
|
|
|
|
2023-10-30 11:10:08 +02:00
|
|
|
static atexit_func_entry_t __atexit_funcs[ATEXIT_MAX_FUNCS];
|
|
|
|
static int __atexit_func_count = 0;
|
2023-06-02 17:49:21 +03:00
|
|
|
|
2023-10-30 11:10:08 +02:00
|
|
|
int __cxa_atexit(void (*func)(void*), void* data, void* dso_handle)
|
2023-06-02 17:49:21 +03:00
|
|
|
{
|
2023-10-30 11:10:08 +02:00
|
|
|
if (__atexit_func_count >= ATEXIT_MAX_FUNCS)
|
|
|
|
return -1;;
|
|
|
|
__atexit_funcs[__atexit_func_count].destructor = func;
|
|
|
|
__atexit_funcs[__atexit_func_count].data = data;
|
|
|
|
__atexit_funcs[__atexit_func_count].dso_handle = dso_handle;
|
2023-06-02 17:49:21 +03:00
|
|
|
__atexit_func_count++;
|
2023-10-30 11:10:08 +02:00
|
|
|
return 0;
|
2023-06-02 17:49:21 +03:00
|
|
|
};
|
|
|
|
|
2023-10-30 11:10:08 +02:00
|
|
|
void __cxa_finalize(void* func)
|
|
|
|
{
|
|
|
|
for (int i = __atexit_func_count - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (func && func != __atexit_funcs[i].destructor)
|
|
|
|
continue;
|
|
|
|
if (__atexit_funcs[i].destructor == nullptr)
|
|
|
|
continue;
|
|
|
|
__atexit_funcs[i].destructor(__atexit_funcs[i].data);
|
|
|
|
__atexit_funcs[i].destructor = nullptr;
|
|
|
|
}
|
|
|
|
}
|