From bdc13bdc0a163d6839ed19a6077e61c162220826 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:46:57 +0200 Subject: feat: c++abi: introduce atexit ptr to cleanup data when exiting program. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'dev/LibC++') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index 126ac60..900198f 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -12,7 +12,10 @@ /// @param code the exit code. /// @return the return > 0 for non successful. extern "C" int exit_(int code); -extern "C" int signal_(int code); + +/// @brief CRT signal handler. +/// @param code the signal code. +extern "C" void signal_(int code); /// @brief Standard C++ namespace namespace std::base_process { @@ -21,7 +24,14 @@ inline int signal(int code) { return -1; } +extern "C" void (*__atexit_lst_ptr)(void); +extern "C" size_t __atexit_lst_cnt; + inline int exit(int code) { + for (auto i = 0UL; i < __atexit_lst_cnt; ++i) { + __atexit_lst_ptr(); + } + exit_(code); return -1; } -- cgit v1.2.3