From: Rémi Bernon rbernon@codeweavers.com
--- dlls/msvcrt/crt_main.c | 29 +++++++++++++++++++++++++++++ dlls/msvcrt/crt_wmain.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
diff --git a/dlls/msvcrt/crt_main.c b/dlls/msvcrt/crt_main.c index eb785e30bb0..b388489e704 100644 --- a/dlls/msvcrt/crt_main.c +++ b/dlls/msvcrt/crt_main.c @@ -30,6 +30,34 @@ #include "winbase.h" #include "winternl.h"
+#if defined(_MSC_VER) +#define _CRTALLOC(x) __declspec(allocate(x)) +#elif defined(__GNUC__) +#define _CRTALLOC(x) __attribute__((section(x))) +#else +#define _CRTALLOC(x) static /* unsupported */ +#endif + +_CRTALLOC(".CRT$XIA") void (*__xi_a)(void) = 0; +_CRTALLOC(".CRT$XIZ") void (*__xi_z)(void) = 0; +_CRTALLOC(".CRT$XCA") void (*__xc_a)(void) = 0; +_CRTALLOC(".CRT$XCZ") void (*__xc_z)(void) = 0; + +#if defined(__GNUC__) +void (*__CTOR_LIST__)(void) __attribute__((weak)) = 0; +void (*__DTOR_LIST__)(void) __attribute__((weak)) = 0; +#endif + +static void _CRT_INIT(void) +{ + void (**ctor)(void); + if ((ctor = &__xi_a)) while (++ctor != &__xi_z && *ctor) (*ctor)(); + if ((ctor = &__xc_a)) while (++ctor != &__xc_z && *ctor) (*ctor)(); +#if defined(__GNUC__) + if ((ctor = &__CTOR_LIST__) && *ctor == (void *)-1) while (++ctor != &__DTOR_LIST__ && *ctor) (*ctor)(); +#endif +} + int __cdecl main(int argc, char **argv, char **env);
static const IMAGE_NT_HEADERS *get_nt_header( void ) @@ -55,6 +83,7 @@ int __cdecl mainCRTStartup(void) #endif _set_app_type(get_nt_header()->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI ? _crt_gui_app : _crt_console_app);
+ _CRT_INIT(); ret = main(argc, argv, env);
exit(ret); diff --git a/dlls/msvcrt/crt_wmain.c b/dlls/msvcrt/crt_wmain.c index 79755d1a6e9..38be3ee5942 100644 --- a/dlls/msvcrt/crt_wmain.c +++ b/dlls/msvcrt/crt_wmain.c @@ -30,6 +30,34 @@ #include "winbase.h" #include "winternl.h"
+#if defined(_MSC_VER) +#define _CRTALLOC(x) __declspec(allocate(x)) +#elif defined(__GNUC__) +#define _CRTALLOC(x) __attribute__((section(x))) +#else +#define _CRTALLOC(x) static /* unsupported */ +#endif + +_CRTALLOC(".CRT$XIA") void (*__xi_a)(void) = 0; +_CRTALLOC(".CRT$XIZ") void (*__xi_z)(void) = 0; +_CRTALLOC(".CRT$XCA") void (*__xc_a)(void) = 0; +_CRTALLOC(".CRT$XCZ") void (*__xc_z)(void) = 0; + +#if defined(__GNUC__) +void (*__CTOR_LIST__)(void) __attribute__((weak)) = 0; +void (*__DTOR_LIST__)(void) __attribute__((weak)) = 0; +#endif + +static void _CRT_INIT(void) +{ + void (**ctor)(void); + if ((ctor = &__xi_a)) while (++ctor != &__xi_z && *ctor) (*ctor)(); + if ((ctor = &__xc_a)) while (++ctor != &__xc_z && *ctor) (*ctor)(); +#if defined(__GNUC__) + if ((ctor = &__CTOR_LIST__) && *ctor == (void *)-1) while (++ctor != &__DTOR_LIST__ && *ctor) (*ctor)(); +#endif +} + int __cdecl wmain(int argc, WCHAR **argv, WCHAR **env);
static const IMAGE_NT_HEADERS *get_nt_header( void ) @@ -55,6 +83,7 @@ int __cdecl wmainCRTStartup(void) #endif _set_app_type(get_nt_header()->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI ? _crt_gui_app : _crt_console_app);
+ _CRT_INIT(); ret = wmain(argc, argv, env);
exit(ret);