WINBOOL WINAPI DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved) { mingw_app_type = 0; if (dwReason == DLL_PROCESS_ATTACH) { __security_init_cookie (); #ifdef _WIN64 __mingw_init_ehandler (); #endif } return __DllMainCRTStartup (hDllHandle, dwReason, lpreserved); }
__declspec(noinline) int __tmainCRTStartup (void) { _TCHAR *lpszCommandLine = NULL; STARTUPINFO StartupInfo; WINBOOL inDoubleQuote = FALSE; memset (&StartupInfo, 0, sizeof (STARTUPINFO)); if (mingw_app_type) GetStartupInfo (&StartupInfo); { void *lock_free = NULL; void *fiberid = ((PNT_TIB)NtCurrentTeb())->StackBase; int nested = FALSE; while((lock_free = InterlockedCompareExchangePointer ((volatile PVOID *) &__native_startup_lock, fiberid, 0)) != 0) { if (lock_free == fiberid) { nested = TRUE; break; } Sleep(1000); } if (__native_startup_state == __initializing) { _amsg_exit (31); } else if (__native_startup_state == __uninitialized) { __native_startup_state = __initializing; _initterm ((_PVFV *)(void *)__xi_a, (_PVFV *)(void *) __xi_z); } else has_cctor = 1; if (__native_startup_state == __initializing) { _initterm (__xc_a, __xc_z); __native_startup_state = __initialized; } _ASSERTE(__native_startup_state == __initialized); if (! nested) (VOID)InterlockedExchangePointer ((volatile PVOID *) &__native_startup_lock, 0); if (__dyn_tls_init_callback != NULL) __dyn_tls_init_callback (NULL, DLL_THREAD_ATTACH, NULL); _pei386_runtime_relocator (); __mingw_oldexcpt_handler = SetUnhandledExceptionFilter (_gnu_exception_handler); #ifdef _WIN64 __mingw_init_ehandler (); #endif __mingw_prepare_except_for_msvcr80_and_higher (); _fpreset (); if (mingw_app_type) { #ifdef WPRFLAG lpszCommandLine = (_TCHAR *) _wcmdln; #else lpszCommandLine = (char *) _acmdln; #endif while (*lpszCommandLine > SPACECHAR || (*lpszCommandLine&&inDoubleQuote)) { if (*lpszCommandLine == DQUOTECHAR) inDoubleQuote = !inDoubleQuote; #ifdef _MBCS if (_ismbblead (*lpszCommandLine)) { if (lpszCommandLine) /* FIXME: Why this check? Should I check for *lpszCommandLine != 0 too? */ lpszCommandLine++; } #endif ++lpszCommandLine; } while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR)) lpszCommandLine++; __mingw_winmain_hInstance = (HINSTANCE) &__ImageBase; __mingw_winmain_lpCmdLine = lpszCommandLine; __mingw_winmain_nShowCmd = StartupInfo.dwFlags & STARTF_USESHOWWINDOW ? StartupInfo.wShowWindow : SW_SHOWDEFAULT; } duplicate_ppstrings (argc, &argv); #ifdef WPRFLAG __winitenv = envp; /* C++ initialization. gcc inserts this call automatically for a function called main, but not for wmain. */ __main (); mainret = wmain (argc, argv, envp); #else __initenv = envp; mainret = main (argc, argv, envp); #endif if (!managedapp) exit (mainret); if (has_cctor == 0) _cexit (); } return mainret; }