[CRT]
[reactos.git] / reactos / lib / sdk / crt / startup / mscmain.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.PD within this package.
5 */
6
7 #include <windows.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <stdarg.h>
11 #include <rtcapi.h>
12 #include <assert.h>
13 #include <internal.h>
14
15 #if defined(_M_IX86)
16 #pragma comment(linker, "/alternatename:__RTC_Initialize=__RTC_NoInitialize")
17 #elif defined(_M_IA64) || defined(_M_AMD64) || defined(_M_ARM)
18 #pragma comment(linker, "/alternatename:_RTC_Initialize=_RTC_NoInitialize")
19 #else
20 #error Unsupported platform
21 #endif
22
23 extern _PVFV __xi_a[];
24 extern _PVFV __xi_z[];
25 extern _PVFV __xc_a[];
26 extern _PVFV __xc_z[];
27
28 static
29 void
30 __do_xtors(
31 _PVFV *start,
32 _PVFV *end)
33 {
34 _PVFV *current;
35 for (current = start; current < end; current++)
36 {
37 if (*current != NULL);
38 (*current)();
39 }
40 }
41
42 void _pei386_runtime_relocator(void)
43 {
44 }
45
46 int __mingw_init_ehandler(void)
47 {
48 /* Nothing to do */
49 return 1;
50 }
51
52 void
53 __do_global_dtors(void)
54 {
55
56 }
57
58 void
59 __do_global_ctors(void)
60 {
61 __do_xtors(__xi_a, __xi_z);
62 __do_xtors(__xc_a, __xc_z);
63 }
64
65 BOOL
66 WINAPI
67 _CRT_INIT0(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
68 {
69 return TRUE;
70 }
71
72 int
73 __cdecl
74 Catch_RTC_Failure(
75 int errType,
76 const wchar_t *file,
77 int line,
78 const wchar_t *module,
79 const wchar_t *format,
80 ...)
81 {
82 /* FIXME: better failure routine */
83 __debugbreak();
84 return 0;
85 }
86
87 extern
88 void
89 __cdecl
90 _RTC_NoInitialize(void)
91 {
92 /* Do nothing, if RunTmChk.lib is not pulled in */
93 }
94
95 _RTC_error_fnW
96 __cdecl
97 _CRT_RTC_INITW(
98 void *_Res0,
99 void **_Res1,
100 int _Res2,
101 int _Res3,
102 int _Res4)
103 {
104 return &Catch_RTC_Failure;
105 }
106
107 static int initialized = 0;
108
109 void
110 __main(void)
111 {
112 if (!initialized)
113 {
114 initialized = 1;
115
116 _RTC_Initialize();
117
118 __do_global_ctors ();
119 }
120 }
121
122