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