[CRT]
[reactos.git] / reactos / lib / sdk / crt / startup / mscmain.c
index 11454db..873139a 100644 (file)
@@ -6,6 +6,38 @@
 
 #include <windows.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <rtcapi.h>
+#include <assert.h>
+#include <internal.h>
+
+#if defined(_M_IX86)
+#pragma comment(linker, "/alternatename:__RTC_Initialize=__RTC_NoInitialize")
+#elif defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM)
+#pragma comment(linker, "/alternatename:_RTC_Initialize=_RTC_NoInitialize")
+#else
+#error Unsupported platform
+#endif
+
+extern _PVFV __xi_a[];
+extern _PVFV __xi_z[];
+extern _PVFV __xc_a[];
+extern _PVFV __xc_z[];
+
+static
+void
+__do_xtors(
+    _PVFV *start,
+    _PVFV *end)
+{
+    _PVFV *current;
+    for (current = start; current < end; current++)
+    {
+        if (*current != NULL);
+            (*current)();
+    }
+}
 
 void _pei386_runtime_relocator(void)
 {
@@ -26,7 +58,8 @@ __do_global_dtors(void)
 void
 __do_global_ctors(void)
 {
-
+    __do_xtors(__xi_a, __xi_z);
+    __do_xtors(__xc_a, __xc_z);
 }
 
 BOOL
@@ -36,6 +69,41 @@ _CRT_INIT0(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
     return TRUE;
 }
 
+int
+__cdecl
+Catch_RTC_Failure(
+    int errType,
+    const wchar_t *file,
+    int line,
+    const wchar_t *module,
+    const wchar_t *format,
+    ...)
+{
+    /* FIXME: better failure routine */
+    __debugbreak();
+    return 0;
+}
+
+extern
+void
+__cdecl
+_RTC_NoInitialize(void)
+{
+    /* Do nothing, if RunTmChk.lib is not pulled in */
+}
+
+_RTC_error_fnW
+__cdecl
+_CRT_RTC_INITW(
+    void *_Res0,
+    void **_Res1,
+    int _Res2,
+    int _Res3,
+    int _Res4)
+{
+    return &Catch_RTC_Failure;
+}
+
 static int initialized = 0;
 
 void
@@ -44,6 +112,9 @@ __main(void)
     if (!initialized)
     {
         initialized = 1;
+
+        _RTC_Initialize();
+
         __do_global_ctors ();
     }
 }