Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KLibc: idea for supporting atexit #18

Open
Deek opened this issue Jan 16, 2023 · 0 comments
Open

KLibc: idea for supporting atexit #18

Deek opened this issue Jan 16, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@Deek
Copy link
Owner

Deek commented Jan 16, 2023

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

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

for (func = top->_ex_fptr; func; func = top = top->_ex_next)
    (*func)();
@Deek Deek added the enhancement New feature or request label Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant