Deek / Deek/CoCoC

KLibc: idea for supporting atexit

Open
#18 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C
Stars
36
Forks
14
PR merge metrics
No merged PRs in 30d

Description

`exit()` calls the internal function `_tidyup()` to clean up, this should be equivalent to modern C's atexit list. We should be able to refactor this code so that there is a linked list of exit functions, something like
```c
struct _exitfun {
_VOIDPTR _ex_fptr;
struct _exitfun *_ex_next;
};
```
by default, there is a single function pointer pointing to the original `_tidyup()` function, and with a "next" pointer of NULL. Calling `atexit(myfunc)` allocates a new structure (two pointers) with `ibrk()`; assigns the head of the exit func list to the address of 'myfunc', then sets the 'next' pointer to the old head.

Inside `exit()`, we can then do the equivalent of
```c
for (func = top->_ex_fptr; func; func = top = top->_ex_next)
(*func)();
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.