2 * Common routine to implement atexit-like functionality.
13 * Register a function to be performed at exit or on shared library unload.
17 _DEFUN (__register_exitproc,
20 void (*fn) (void) _AND
24 struct _on_exit_args * args;
25 register struct _atexit *p;
27 #ifndef __SINGLE_THREAD__
28 __LOCK_INIT(static, lock);
33 p = _GLOBAL_REENT->_atexit;
35 _GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0;
36 if (p->_ind >= _ATEXIT_SIZE)
38 p = (struct _atexit *) malloc (sizeof *p);
41 #ifndef __SINGLE_THREAD__
47 p->_next = _GLOBAL_REENT->_atexit;
48 _GLOBAL_REENT->_atexit = p;
50 p->_on_exit_args._fntypes = 0;
51 #ifdef __REENT_HAS_CXA_SUPPORT
52 p->_on_exit_args._is_cxa = 0;
57 if (type != __et_atexit)
60 args = p->_on_exit_args_ptr;
63 args = malloc (sizeof * p->_on_exit_args_ptr);
66 #ifndef __SINGLE_THREAD__
73 #ifdef __REENT_HAS_CXA_SUPPORT
74 p->_on_exit_args_ptr = args;
78 args = &p->_on_exit_args;
80 args->_fnargs[p->_ind] = arg;
81 args->_fntypes |= (1 << p->_ind);
82 #ifdef __REENT_HAS_CXA_SUPPORT
83 args->_dso_handle[p->_ind] = d;
85 args->_is_cxa |= (1 << p->_ind);
88 p->_fns[p->_ind++] = fn;
89 #ifndef __SINGLE_THREAD__