Merge the following revisions from kernel-fun branch:
[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 /*
24 * Initializer / constructor handling
25 * see http://msdn.microsoft.com/en-us/library/bb918180.aspx
26 * Destructors are registered from the initializers using atexit()
27 */
28
29 extern _PVFV __xi_a[];
30 extern _PVFV __xi_z[];
31 extern _PVFV __xc_a[];
32 extern _PVFV __xc_z[];
33
34 static
35 void
36 __do_xtors(
37 _PVFV *start,
38 _PVFV *end)
39 {
40 _PVFV *current;
41 for (current = start; current < end; current++)
42 {
43 if (*current != NULL)
44 (*current)();
45 }
46 }
47
48 void _pei386_runtime_relocator(void)
49 {
50 }
51
52 int __mingw_init_ehandler(void)
53 {
54 /* Nothing to do */
55 return 1;
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