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++/base_process.h') 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 From 5823a178acbeee2c5fd0744c042bbcc2f59800c0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:47:53 +0200 Subject: fix: atexit: fix atexit list. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/LibC++/base_process.h') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index 900198f..4768c61 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -24,12 +24,12 @@ inline int signal(int code) { return -1; } -extern "C" void (*__atexit_lst_ptr)(void); +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(); + __atexit_lst_ptr[i](); } exit_(code); -- cgit v1.2.3 From 54f5085758f59beb8395edd9658b99d555356578 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:49:07 +0200 Subject: feat: refactor `i` to `idx` for better readbility. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/LibC++/base_process.h') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index 4768c61..77e092e 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -28,8 +28,8 @@ 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[i](); + for (auto idx = 0UL; idx < __atexit_lst_cnt; ++idx) { + __atexit_lst_ptr[idx](); } exit_(code); -- cgit v1.2.3 From cfde696e68ce91ce776807ff44276136cb84e5ba Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 15:54:05 +0200 Subject: feat: introduce `__atexit__cdecl_ptr` to `std::atexit` Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dev/LibC++/base_process.h') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index 77e092e..a30ccca 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -24,6 +24,7 @@ inline int signal(int code) { return -1; } +extern "C" void (*__atexit__cdecl_ptr)(void); extern "C" void (**__atexit_lst_ptr)(void); extern "C" size_t __atexit_lst_cnt; @@ -32,6 +33,8 @@ inline int exit(int code) { __atexit_lst_ptr[idx](); } + if (__atexit__cdecl_ptr) __atexit__cdecl_ptr(); + exit_(code); return -1; } -- cgit v1.2.3 From b112e21f9017b90e3fc48c85383eb368033a97d0 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 24 Aug 2025 22:19:39 +0200 Subject: feat: LibC++: improve `exit` function. Signed-off-by: Amlal El Mahrouss --- dev/LibC++/base_process.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dev/LibC++/base_process.h') diff --git a/dev/LibC++/base_process.h b/dev/LibC++/base_process.h index a30ccca..034240f 100644 --- a/dev/LibC++/base_process.h +++ b/dev/LibC++/base_process.h @@ -24,16 +24,16 @@ inline int signal(int code) { return -1; } -extern "C" void (*__atexit__cdecl_ptr)(void); +extern "C" void (*__atexit_cdecl_ptr)(void); extern "C" void (**__atexit_lst_ptr)(void); extern "C" size_t __atexit_lst_cnt; -inline int exit(int code) { +inline int32_t exit(const int32_t& code) { for (auto idx = 0UL; idx < __atexit_lst_cnt; ++idx) { __atexit_lst_ptr[idx](); } - if (__atexit__cdecl_ptr) __atexit__cdecl_ptr(); + if (__atexit_cdecl_ptr) __atexit_cdecl_ptr(); exit_(code); return -1; -- cgit v1.2.3