1*c2c66affSColin Finck /** 2*c2c66affSColin Finck * This file has no copyright assigned and is placed in the Public Domain. 3*c2c66affSColin Finck * This file is part of the w64 mingw-runtime package. 4*c2c66affSColin Finck * No warranty is given; refer to the file DISCLAIMER.PD within this package. 5*c2c66affSColin Finck */ 6*c2c66affSColin Finck 7*c2c66affSColin Finck #undef CRTDLL 8*c2c66affSColin Finck #ifndef _DLL 9*c2c66affSColin Finck #define _DLL 10*c2c66affSColin Finck #endif 11*c2c66affSColin Finck 12*c2c66affSColin Finck #include <oscalls.h> 13*c2c66affSColin Finck #include <internal.h> 14*c2c66affSColin Finck #include <stdlib.h> 15*c2c66affSColin Finck #include <crtdefs.h> 16*c2c66affSColin Finck #include <limits.h> 17*c2c66affSColin Finck //#include <windows.h> 18*c2c66affSColin Finck 19*c2c66affSColin Finck #define _EXIT_LOCK1 8 20*c2c66affSColin Finck 21*c2c66affSColin Finck void __cdecl _lock (int _File); 22*c2c66affSColin Finck void __cdecl _unlock (int _File); 23*c2c66affSColin Finck 24*c2c66affSColin Finck _PVFV *__onexitbegin; 25*c2c66affSColin Finck _PVFV *__onexitend; 26*c2c66affSColin Finck 27*c2c66affSColin Finck extern _CRTIMP _onexit_t __cdecl __dllonexit (_onexit_t, _PVFV**, _PVFV**); 28*c2c66affSColin Finck extern _onexit_t (__cdecl * __MINGW_IMP_SYMBOL(_onexit)) (_onexit_t func); 29*c2c66affSColin Finck 30*c2c66affSColin Finck /* Choose a different name to prevent name conflicts. The CRT one works fine. */ 31*c2c66affSColin Finck _onexit_t __cdecl mingw_onexit(_onexit_t func); 32*c2c66affSColin Finck 33*c2c66affSColin Finck _onexit_t __cdecl mingw_onexit(_onexit_t func) 34*c2c66affSColin Finck { 35*c2c66affSColin Finck _PVFV *onexitbegin; 36*c2c66affSColin Finck _PVFV *onexitend; 37*c2c66affSColin Finck _onexit_t retval; 38*c2c66affSColin Finck 39*c2c66affSColin Finck onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin); 40*c2c66affSColin Finck 41*c2c66affSColin Finck if (onexitbegin == (_PVFV *) -1) 42*c2c66affSColin Finck return (* __MINGW_IMP_SYMBOL(_onexit)) (func); 43*c2c66affSColin Finck _lock (_EXIT_LOCK1); 44*c2c66affSColin Finck onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin); 45*c2c66affSColin Finck onexitend = (_PVFV *) _decode_pointer (__onexitend); 46*c2c66affSColin Finck 47*c2c66affSColin Finck retval = __dllonexit (func, &onexitbegin, &onexitend); 48*c2c66affSColin Finck 49*c2c66affSColin Finck __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin); 50*c2c66affSColin Finck __onexitend = (_PVFV *) _encode_pointer (onexitend); 51*c2c66affSColin Finck _unlock (_EXIT_LOCK1); 52*c2c66affSColin Finck return retval; 53*c2c66affSColin Finck } 54*c2c66affSColin Finck 55*c2c66affSColin Finck int __cdecl 56*c2c66affSColin Finck atexit (_PVFV func) 57*c2c66affSColin Finck { 58*c2c66affSColin Finck return (mingw_onexit((_onexit_t)func) == NULL) ? -1 : 0; 59*c2c66affSColin Finck } 60