Kernel: Add __cxa_atexit iomplementation

This commit is contained in:
apio 2023-01-13 18:56:05 +01:00
parent 09dc8bd522
commit 7462b764d8
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 53 additions and 0 deletions

View File

@ -3,6 +3,7 @@
set(SOURCES
src/main.cpp
src/Log.cpp
src/cxxabi.cpp
src/video/Framebuffer.cpp
src/video/TextConsole.cpp
src/memory/MemoryManager.cpp

52
kernel/src/cxxabi.cpp Normal file
View File

@ -0,0 +1,52 @@
typedef void* (*cxa_atexit_func_t)(void*);
struct cxa_atexit_entry
{
cxa_atexit_func_t function;
void* argument;
void* dso_handle;
};
#define CXA_ATEXIT_MAX 64
int cxa_atexit_entry_count = 0;
cxa_atexit_entry cxa_atexit_entries[CXA_ATEXIT_MAX];
__attribute__((visibility("hidden"))) void* __dso_handle = 0;
extern "C"
{
int __cxa_atexit(cxa_atexit_func_t func, void* arg, void* dso)
{
if (cxa_atexit_entry_count >= CXA_ATEXIT_MAX) return -1;
cxa_atexit_entries[cxa_atexit_entry_count].function = func;
cxa_atexit_entries[cxa_atexit_entry_count].argument = arg;
cxa_atexit_entries[cxa_atexit_entry_count].dso_handle = dso;
cxa_atexit_entry_count++;
return 0;
}
void __cxa_finalize(void* f)
{
int i = cxa_atexit_entry_count;
if (!f)
{
while (i--)
{
if (cxa_atexit_entries[i].function) { cxa_atexit_entries[i].function(cxa_atexit_entries[i].argument); }
}
}
else
{
while (i--)
{
if (cxa_atexit_entries[i].function == (cxa_atexit_func_t)f)
{
cxa_atexit_entries[i].function(cxa_atexit_entries[i].argument);
cxa_atexit_entries[i].function = 0;
}
}
}
}
}