libc.obj: add atexit and normal exit. add exit code save/read
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 20s
Build system / Build (pull_request) Successful in 16m18s

This commit is contained in:
2026-02-22 13:56:25 +05:00
parent 0319a2d7cb
commit ba8747e2ab
6 changed files with 159 additions and 5 deletions

View File

@@ -0,0 +1,35 @@
#include <stdlib.h>
struct atexit_n {
struct atexit_n* last;
void (*func)(void);
};
static struct atexit_n* __last_n = NULL;
int atexit(void (*func)(void))
{
struct atexit_n* n = malloc(sizeof(struct atexit_n));
if (n == NULL) {
return 1;
}
n->last = __last_n;
n->func = func;
__last_n = n;
return 0;
}
void __run_atexit()
{
struct atexit_n* n = __last_n;
while (n != NULL) {
n->func();
struct atexit_n* to_free = n;
n = n->last;
free(to_free);
}
}