LibC: add __cxa_at_exit() for libc

This commit is contained in:
Bananymous 2023-06-02 17:49:21 +03:00
parent 3a69768eb0
commit 2207357b93
2 changed files with 36 additions and 0 deletions

View File

@ -13,6 +13,7 @@ set(LIBC_SOURCES
termios.cpp
unistd.cpp
math.S
icxxabi.cpp
)
add_custom_target(libc-headers

35
libc/icxxabi.cpp Normal file
View File

@ -0,0 +1,35 @@
#define ATEXIT_MAX_FUNCS 128
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned uarch_t;
struct atexit_func_entry_t
{
/*
* Each member is at least 4 bytes large. Such that each entry is 12bytes.
* 128 * 12 = 1.5KB exact.
**/
void (*destructor_func)(void *);
void *obj_ptr;
void *dso_handle;
};
atexit_func_entry_t __atexit_funcs[ATEXIT_MAX_FUNCS];
uarch_t __atexit_func_count = 0;
int __cxa_atexit(void (*f)(void *), void *objptr, void *dso)
{
if (__atexit_func_count >= ATEXIT_MAX_FUNCS) {return -1;};
__atexit_funcs[__atexit_func_count].destructor_func = f;
__atexit_funcs[__atexit_func_count].obj_ptr = objptr;
__atexit_funcs[__atexit_func_count].dso_handle = dso;
__atexit_func_count++;
return 0; /*I would prefer if functions returned 1 on success, but the ABI says...*/
};
#ifdef __cplusplus
};
#endif