diff --git a/reactos/dll/win32/msvcrt/msvcrt.spec b/reactos/dll/win32/msvcrt/msvcrt.spec
index 55d88bfd2c4..02d506e9699 100644
--- a/reactos/dll/win32/msvcrt/msvcrt.spec
+++ b/reactos/dll/win32/msvcrt/msvcrt.spec
@@ -1156,7 +1156,7 @@
@ cdecl asin(double)
@ cdecl atan(double)
@ cdecl atan2(double double)
-@ cdecl atexit(ptr)
+@ extern atexit # <-- keep this as an extern, thank you
@ cdecl atof(str)
@ cdecl atoi(str)
@ cdecl atol(str)
diff --git a/reactos/dll/win32/msvcrt20/msvcrt20.spec b/reactos/dll/win32/msvcrt20/msvcrt20.spec
index 81138c5c7dc..3a6a103a065 100644
--- a/reactos/dll/win32/msvcrt20/msvcrt20.spec
+++ b/reactos/dll/win32/msvcrt20/msvcrt20.spec
@@ -937,7 +937,7 @@
@ cdecl asin(double)
@ cdecl atan(double)
@ cdecl atan2(double double)
-@ cdecl atexit(ptr)
+@ extern atexit # <-- do not touch this!
@ cdecl atof(str)
@ cdecl atoi(str)
@ cdecl atol(str)
diff --git a/reactos/dll/win32/msvcrt40/msvcrt40.spec b/reactos/dll/win32/msvcrt40/msvcrt40.spec
index 7f7819622dc..5383a360f80 100644
--- a/reactos/dll/win32/msvcrt40/msvcrt40.spec
+++ b/reactos/dll/win32/msvcrt40/msvcrt40.spec
@@ -975,7 +975,7 @@
@ cdecl asin(double)
@ cdecl atan(double)
@ cdecl atan2(double double)
-@ cdecl atexit(ptr)
+@ extern atexit # <-- changing this will kill your cat, understand?
@ cdecl atof(str)
@ cdecl atoi(str)
@ cdecl atol(str)
diff --git a/reactos/lib/3rdparty/mingw/crtexe.c b/reactos/lib/3rdparty/mingw/crtexe.c
index 7ac3b890bae..daab5cd5984 100644
--- a/reactos/lib/3rdparty/mingw/crtexe.c
+++ b/reactos/lib/3rdparty/mingw/crtexe.c
@@ -71,8 +71,8 @@ extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[];
/* TLS initialization hook. */
extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback;
-//extern _PVFV *__onexitbegin;
-//extern _PVFV *__onexitend;
+extern _PVFV *__onexitbegin;
+extern _PVFV *__onexitend;
extern int mingw_app_type;
@@ -119,7 +119,7 @@ pre_c_init (void)
__set_app_type(_GUI_APP);
else
__set_app_type (_CONSOLE_APP);
-// __onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1));
+ __onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1));
* __MINGW_IMP_SYMBOL(_fmode) = _fmode;
* __MINGW_IMP_SYMBOL(_commode) = _commode;
diff --git a/reactos/lib/3rdparty/mingw/mingw.rbuild b/reactos/lib/3rdparty/mingw/mingw.rbuild
index 565dc2f9c97..737810cca13 100644
--- a/reactos/lib/3rdparty/mingw/mingw.rbuild
+++ b/reactos/lib/3rdparty/mingw/mingw.rbuild
@@ -12,7 +12,7 @@
include/reactos/mingw-w64
kernel32
_newmode.c
-
+ atonexit.c
binmode.c
charmax.c
cinitexe.c
diff --git a/reactos/lib/sdk/crt/msvcrtex.cmake b/reactos/lib/sdk/crt/msvcrtex.cmake
index 070e8dae4da..9099448f55e 100644
--- a/reactos/lib/sdk/crt/msvcrtex.cmake
+++ b/reactos/lib/sdk/crt/msvcrtex.cmake
@@ -17,7 +17,7 @@ list(APPEND MSVCRTEX_SOURCE
startup/natstart.c
startup/charmax.c
startup/merr.c
-# startup/atonexit.c
+ startup/atonexit.c
startup/txtmode.c
startup/pesect.c
startup/tlsmcrt.c
diff --git a/reactos/lib/sdk/crt/startup/crtdll.c b/reactos/lib/sdk/crt/startup/crtdll.c
index 40557d9b5a2..6fa17a821f8 100644
--- a/reactos/lib/sdk/crt/startup/crtdll.c
+++ b/reactos/lib/sdk/crt/startup/crtdll.c
@@ -49,8 +49,8 @@ extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback;
static int __proc_attached = 0;
-//extern _PVFV *__onexitbegin;
-//extern _PVFV *__onexitend;
+extern _PVFV *__onexitbegin;
+extern _PVFV *__onexitend;
extern int mingw_app_type;
@@ -65,7 +65,7 @@ _CRTALLOC(".CRT$XIAA") _PIFV pcinit = pre_c_init;
static int
pre_c_init (void)
{
-/* _PVFV *onexitbegin;
+ _PVFV *onexitbegin;
onexitbegin = (_PVFV *) malloc (32 * sizeof (_PVFV));
__onexitend = __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin);
@@ -73,8 +73,7 @@ pre_c_init (void)
if (onexitbegin == NULL)
return 1;
*onexitbegin = (_PVFV) NULL;
- return 0;*/
- return 1;
+ return 0;
}
WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
@@ -136,7 +135,7 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
_amsg_exit (31);
}
else
- {/*
+ {
_PVFV * onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin);
if (onexitbegin)
{
@@ -146,7 +145,7 @@ WINBOOL WINAPI _CRT_INIT (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
(**onexitend) ();
free (onexitbegin);
__onexitbegin = __onexitend = (_PVFV *) NULL;
- }*/
+ }
__native_startup_state = __uninitialized;
(void) InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0);
}
diff --git a/reactos/lib/sdk/crt/startup/crtexe.c b/reactos/lib/sdk/crt/startup/crtexe.c
index cf1b79e007c..8d15e29ebc3 100644
--- a/reactos/lib/sdk/crt/startup/crtexe.c
+++ b/reactos/lib/sdk/crt/startup/crtexe.c
@@ -75,8 +75,8 @@ extern _CRTALLOC(".CRT$XCZ") _PVFV __xc_z[];
/* TLS initialization hook. */
extern const PIMAGE_TLS_CALLBACK __dyn_tls_init_callback;
-//extern _PVFV *__onexitbegin;
-//extern _PVFV *__onexitend;
+extern _PVFV *__onexitbegin;
+extern _PVFV *__onexitend;
extern int mingw_app_type;
@@ -128,7 +128,7 @@ pre_c_init (void)
__set_app_type(_GUI_APP);
else
__set_app_type (_CONSOLE_APP);
-// __onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1));
+ __onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1));
* __MINGW_IMP_SYMBOL(_fmode) = _fmode;
* __MINGW_IMP_SYMBOL(_commode) = _commode;