2011-05-23 15:50:03 +00:00
|
|
|
/**
|
|
|
|
* This file has no copyright assigned and is placed in the Public Domain.
|
|
|
|
* This file is part of the w64 mingw-runtime package.
|
|
|
|
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef CRTDLL
|
|
|
|
#ifndef _DLL
|
|
|
|
#define _DLL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <oscalls.h>
|
|
|
|
#include <internal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <crtdefs.h>
|
|
|
|
#include <limits.h>
|
2013-01-24 23:00:42 +00:00
|
|
|
//#include <windows.h>
|
2011-05-23 15:50:03 +00:00
|
|
|
|
|
|
|
#define _EXIT_LOCK1 8
|
|
|
|
|
|
|
|
void __cdecl _lock (int _File);
|
|
|
|
void __cdecl _unlock (int _File);
|
|
|
|
|
|
|
|
_PVFV *__onexitbegin;
|
|
|
|
_PVFV *__onexitend;
|
|
|
|
|
2020-10-22 15:11:02 +00:00
|
|
|
extern _onexit_t __cdecl __dllonexit (_onexit_t, _PVFV**, _PVFV**);
|
2011-05-23 15:50:03 +00:00
|
|
|
extern _onexit_t (__cdecl * __MINGW_IMP_SYMBOL(_onexit)) (_onexit_t func);
|
|
|
|
|
2020-10-22 15:11:02 +00:00
|
|
|
/* INTERNAL: call atexit functions */
|
|
|
|
void __call_atexit(void)
|
|
|
|
{
|
|
|
|
/* Note: should only be called with the exit lock held */
|
|
|
|
_PVFV *first, *last;
|
|
|
|
|
|
|
|
first = (_PVFV *)_decode_pointer(__onexitbegin);
|
|
|
|
last = (_PVFV *)_decode_pointer(__onexitend);;
|
|
|
|
|
|
|
|
if (!first) return;
|
|
|
|
|
|
|
|
while (--last >= first)
|
|
|
|
if (*last)
|
|
|
|
(**last)();
|
|
|
|
|
|
|
|
free(first);
|
|
|
|
}
|
|
|
|
|
2011-05-23 15:50:03 +00:00
|
|
|
/* Choose a different name to prevent name conflicts. The CRT one works fine. */
|
2020-10-22 15:11:02 +00:00
|
|
|
_onexit_t __cdecl _onexit(_onexit_t func);
|
2011-05-23 15:50:03 +00:00
|
|
|
|
2020-10-22 15:11:02 +00:00
|
|
|
_onexit_t __cdecl _onexit(_onexit_t func)
|
2011-05-23 15:50:03 +00:00
|
|
|
{
|
|
|
|
_PVFV *onexitbegin;
|
|
|
|
_PVFV *onexitend;
|
|
|
|
_onexit_t retval;
|
|
|
|
|
|
|
|
onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
|
|
|
|
|
|
|
|
if (onexitbegin == (_PVFV *) -1)
|
2020-10-22 15:11:02 +00:00
|
|
|
#ifdef __REACTOS__
|
|
|
|
{
|
|
|
|
onexitbegin = (_PVFV *)calloc(32, sizeof(_onexit_t));
|
|
|
|
if (onexitbegin == NULL)
|
|
|
|
return NULL;
|
|
|
|
__onexitbegin = _encode_pointer(onexitbegin);
|
|
|
|
__onexitend = _encode_pointer(onexitbegin + 32);
|
|
|
|
}
|
|
|
|
#else
|
2011-05-23 15:50:03 +00:00
|
|
|
return (* __MINGW_IMP_SYMBOL(_onexit)) (func);
|
2020-10-22 15:11:02 +00:00
|
|
|
#endif
|
2011-05-23 15:50:03 +00:00
|
|
|
_lock (_EXIT_LOCK1);
|
|
|
|
onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
|
|
|
|
onexitend = (_PVFV *) _decode_pointer (__onexitend);
|
|
|
|
|
|
|
|
retval = __dllonexit (func, &onexitbegin, &onexitend);
|
|
|
|
|
|
|
|
__onexitbegin = (_PVFV *) _encode_pointer (onexitbegin);
|
|
|
|
__onexitend = (_PVFV *) _encode_pointer (onexitend);
|
|
|
|
_unlock (_EXIT_LOCK1);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __cdecl
|
|
|
|
atexit (_PVFV func)
|
|
|
|
{
|
2020-10-22 15:11:02 +00:00
|
|
|
return (_onexit((_onexit_t)func) == NULL) ? -1 : 0;
|
2011-05-23 15:50:03 +00:00
|
|
|
}
|