static int __cdecl pre_c_init (void) { managedapp = check_managed_app (); if (mingw_app_type) __set_app_type(_GUI_APP); else __set_app_type (_CONSOLE_APP); __onexitbegin = __onexitend = (_PVFV *) _encode_pointer ((_PVFV *)(-1)); * __MINGW_IMP_SYMBOL(_fmode) = _fmode; * __MINGW_IMP_SYMBOL(_commode) = _commode; #ifdef WPRFLAG _wsetargv(); #else _setargv(); #endif if (_MINGW_INSTALL_DEBUG_MATHERR) { if (! __defaultmatherr) { __setusermatherr (_matherr); __defaultmatherr = 1; } } if (__globallocalestatus == -1) { } return 0; }
_onexit_t __cdecl _onexit ( _onexit_t func ) { _PVFV * onexitbegin; _PVFV * onexitend; _onexit_t retval; onexitbegin = (_PVFV *)_decode_pointer(__onexitbegin); if (onexitbegin == (_PVFV *)-1) { /* EXE */ #ifdef _M_IX86 return (*_imp___onexit)(func); #else /* _M_IX86 */ return (*__imp__onexit)(func); #endif /* _M_IX86 */ } /* * Note that we decode/encode the onexit array pointers on the * client side, not the CRT DLL side, to ease backwards compatibility. * That means we have to take a lock on this side, making the lock * found in __dllonexit redundant. */ _lock(_EXIT_LOCK1); __try { onexitbegin = (_PVFV *)_decode_pointer(__onexitbegin); onexitend = (_PVFV *)_decode_pointer(__onexitend); retval = __dllonexit(func, &onexitbegin, &onexitend); __onexitbegin = (_PVFV *)_encode_pointer(onexitbegin); __onexitend = (_PVFV *)_encode_pointer(onexitend); } __finally { _unlock(_EXIT_LOCK1); } return retval; }
_onexit_t __cdecl mingw_onexit(_onexit_t func) { _PVFV *onexitbegin; _PVFV *onexitend; _onexit_t retval; onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin); if (onexitbegin == (_PVFV *) -1) return (* __MINGW_IMP_SYMBOL(_onexit)) (func); _lock (_EXIT_LOCK1); onexitbegin = (_PVFV *) _decode_pointer (__onexitbegin); onexitend = (_PVFV *) _decode_pointer (__onexitend); retval = __dllonexit (func, &onexitbegin, &onexitend); __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin); __onexitend = (_PVFV *) _encode_pointer (onexitend); _unlock (_EXIT_LOCK1); return retval; }
static int pre_c_init (void) { _PVFV *onexitbegin; onexitbegin = (_PVFV *) malloc (32 * sizeof (_PVFV)); __onexitend = __onexitbegin = (_PVFV *) _encode_pointer (onexitbegin); if (onexitbegin == NULL) return 1; *onexitbegin = (_PVFV) NULL; return 0; }
_CRTIMP _invalid_parameter_handler __cdecl _set_invalid_parameter_handler( _invalid_parameter_handler pNew ) { _invalid_parameter_handler pOld = NULL; pOld = __pInvalidArgHandler; pOld = (_invalid_parameter_handler) _decode_pointer((PVOID)pOld); pNew = (_invalid_parameter_handler) _encode_pointer((PVOID)pNew); __pInvalidArgHandler = pNew; return pOld; }
errno_t __cdecl rand_s ( unsigned int* _RandomValue ) { PGENRANDOM pfnRtlGenRandom = _decode_pointer(g_pfnRtlGenRandom); _VALIDATE_RETURN_ERRCODE(_RandomValue != NULL, EINVAL); *_RandomValue = 0; // Review : better value to initialize it to? if (pfnRtlGenRandom == NULL) { PGENRANDOM encoded; void* enull; // Advapi32.dll is unloaded when the App exits. HMODULE hAdvApi32 = LoadLibrary("ADVAPI32.DLL"); if (!hAdvApi32) { _VALIDATE_RETURN_ERRCODE(("rand_s is not available on this platform", 0), EINVAL); } pfnRtlGenRandom = (PGENRANDOM) GetProcAddress(hAdvApi32, _TO_STR(RtlGenRandom)); if (pfnRtlGenRandom == NULL) { _VALIDATE_RETURN_ERRCODE(("rand_s is not available on this platform", 0), _get_errno_from_oserr(GetLastError())); } encoded = (PGENRANDOM) _encode_pointer(pfnRtlGenRandom); enull = _encoded_null(); #ifdef _M_IX86 if ((void*)(LONG_PTR)InterlockedExchange( (LONG*)&g_pfnRtlGenRandom, (LONG)(LONG_PTR)encoded) != enull) #else /* _M_IX86 */ if (InterlockedExchangePointer( (void**)&g_pfnRtlGenRandom, (void*)encoded) != enull) #endif /* _M_IX86 */ { /* A different thread has already loaded advapi32.dll. */ FreeLibrary(hAdvApi32); } } if (!(*pfnRtlGenRandom)(_RandomValue, (ULONG)sizeof(unsigned int))) { errno = ENOMEM; return errno; } return 0; }
static int __cdecl pre_c_init(void) { _PVFV * onexitbegin; /* * create the onexit table. */ onexitbegin = (_PVFV *)_malloc_crt(32 * sizeof(_PVFV)); __onexitend = __onexitbegin = (_PVFV *)_encode_pointer(onexitbegin); if ( onexitbegin == NULL ) /* * cannot allocate minimal required * size. generate failure to load DLL */ return 1; *onexitbegin = (_PVFV) NULL; /* * Run the RTC initialization code for this DLL */ #ifdef _RTC _RTC_Initialize(); atexit(_RTC_Terminate); #endif /* _RTC */ #ifndef _SYSCRT /* * Register __clean_type_info_names so that we clean up all the * type_info.names that are allocated */ atexit(__clean_type_info_names); #endif /* _SYSCRT */ return 0; }
_PHNDLR __cdecl signal( int signum, _PHNDLR sigact ) { struct _XCPT_ACTION *pxcptact; _PHNDLR oldsigact; int Error=0; _ptiddata ptd; BOOL SetConsoleCtrlError = FALSE; /* * Check for values of sigact supported on other platforms but not * on this one. Also, make sure sigact is not SIG_DIE */ if ( (sigact == SIG_ACK) || (sigact == SIG_SGE) ) goto sigreterror; /* * Take care of all signals which do not correspond to exceptions * in the host OS. Those are: * * SIGINT * SIGBREAK * SIGABRT * SIGTERM * */ if ( (signum == SIGINT) || (signum == SIGBREAK) || (signum == SIGABRT) || (signum == SIGABRT_COMPAT) || (signum == SIGTERM) ) { _mlock( _SIGNAL_LOCK ); __try { /* * if SIGINT or SIGBREAK, make sure the handler is installed * to capture ^C and ^Break events. */ if ( ((signum == SIGINT) || (signum == SIGBREAK)) && !ConsoleCtrlHandler_Installed ) { if ( SetConsoleCtrlHandler(ctrlevent_capture, TRUE) == TRUE ) { ConsoleCtrlHandler_Installed = TRUE; } else { _doserrno = GetLastError(); SetConsoleCtrlError=TRUE; } } switch (signum) { case SIGINT: oldsigact = (_PHNDLR) _decode_pointer(ctrlc_action); if(sigact!=SIG_GET) { ctrlc_action = (_PHNDLR) _encode_pointer(sigact); } break; case SIGBREAK: oldsigact = (_PHNDLR) _decode_pointer(ctrlbreak_action); if(sigact!=SIG_GET) { ctrlbreak_action = (_PHNDLR) _encode_pointer(sigact); } break; case SIGABRT: case SIGABRT_COMPAT: oldsigact = (_PHNDLR) _decode_pointer(abort_action); if(sigact!=SIG_GET) { abort_action = (_PHNDLR) _encode_pointer(sigact); } break; case SIGTERM: oldsigact = (_PHNDLR) _decode_pointer(term_action); if(sigact!=SIG_GET) { term_action = (_PHNDLR) _encode_pointer(sigact); } break; } } __finally { _munlock( _SIGNAL_LOCK ); } if (SetConsoleCtrlError) { goto sigreterror; } goto sigretok; }
static int __cdecl pre_c_init(void) { /* * Determine if this is a managed application */ managedapp = check_managed_app(); /* * Set __app_type properly */ #ifdef _WINMAIN_ __set_app_type(_GUI_APP); #else /* _WINMAIN_ */ __set_app_type(_CONSOLE_APP); #endif /* _WINMAIN_ */ /* * Mark this module as an EXE file so that atexit/_onexit * will do the right thing when called, including for C++ * d-tors. */ __onexitbegin = __onexitend = (_PVFV*)_encode_pointer((_PVFV*)(-1)); /* * Propogate the _fmode and _commode variables to the DLL */ *_IMP___FMODE = _fmode; *_IMP___COMMODE = _commode; #ifdef _M_IX86 /* * Set the local copy of the Pentium FDIV adjustment flag */ _adjust_fdiv = * _imp___adjust_fdiv; #endif /* _M_IX86 */ /* * Run the RTC initialization code for this DLL */ #ifdef _RTC _RTC_Initialize(); #endif /* _RTC */ /* * Call _setargv(), which will trigger a call to __setargv() if * SETARGV.OBJ is linked with the EXE. If SETARGV.OBJ is not * linked with the EXE, a dummy _setargv() will be called. */ #ifdef WPRFLAG _wsetargv(); #else /* WPRFLAG */ _setargv(); #endif /* WPRFLAG */ /* * If the user has supplied a _matherr routine then set * __pusermatherr to point to it. */ if (!__defaultmatherr) { __setusermatherr(_matherr); } #ifdef _M_IX86 _setdefaultprecision(); #endif /* _M_IX86 */ /* Enable per-thread locale if user asked for it */ if (__globallocalestatus == -1) { _configthreadlocale(-1); } return 0; }
/**** *_mtinit() - Init multi-thread data bases * *Purpose: * (1) Call _mtinitlocks to create/open all lock semaphores. * (2) Allocate a TLS index to hold pointers to per-thread data * structure. * * NOTES: * (1) Only to be called ONCE at startup * (2) Must be called BEFORE any mthread requests are made * *Entry: * <NONE> *Exit: * returns FALSE on failure * *Uses: * <any registers may be modified at init time> * *Exceptions: * *******************************************************************************/ int __cdecl _mtinit ( void ) { _ptiddata ptd; #ifndef _M_AMD64 /* * Initialize fiber local storage function pointers. */ HINSTANCE hKernel32 = GetModuleHandle(_KERNEL32); if (hKernel32 == NULL) { _mtterm(); return FALSE; /* fail to load DLL */ } gpFlsAlloc = (PFLS_ALLOC_FUNCTION)GetProcAddress(hKernel32, "FlsAlloc"); gpFlsGetValue = (PFLS_GETVALUE_FUNCTION)GetProcAddress(hKernel32, "FlsGetValue"); gpFlsSetValue = (PFLS_SETVALUE_FUNCTION)GetProcAddress(hKernel32, "FlsSetValue"); gpFlsFree = (PFLS_FREE_FUNCTION)GetProcAddress(hKernel32, "FlsFree"); if (!gpFlsAlloc || !gpFlsGetValue || !gpFlsSetValue || !gpFlsFree) { gpFlsAlloc = (PFLS_ALLOC_FUNCTION)__crtTlsAlloc; gpFlsGetValue = (PFLS_GETVALUE_FUNCTION)TlsGetValue; gpFlsSetValue = (PFLS_SETVALUE_FUNCTION)TlsSetValue; gpFlsFree = (PFLS_FREE_FUNCTION)TlsFree; } /* * Allocate and initialize a TLS index to store FlsGetValue pointer * so that the FLS_* macros can work transparently */ if ( (__getvalueindex = TlsAlloc()) == 0xffffffff || !TlsSetValue(__getvalueindex, (LPVOID)gpFlsGetValue) ) { return FALSE; } #endif /* _M_AMD64 */ _init_pointers(); /* initialize global function pointers */ #ifndef _M_AMD64 /* * Encode the fiber local storage function pointers */ gpFlsAlloc = (PFLS_ALLOC_FUNCTION) _encode_pointer(gpFlsAlloc); gpFlsGetValue = (PFLS_GETVALUE_FUNCTION) _encode_pointer(gpFlsGetValue); gpFlsSetValue = (PFLS_SETVALUE_FUNCTION) _encode_pointer(gpFlsSetValue); gpFlsFree = (PFLS_FREE_FUNCTION) _encode_pointer(gpFlsFree); #endif /* _M_AMD64 */ /* * Initialize the mthread lock data base */ if ( !_mtinitlocks() ) { _mtterm(); return FALSE; /* fail to load DLL */ } /* * Allocate a TLS index to maintain pointers to per-thread data */ if ( (__flsindex = FLS_ALLOC(&_freefls)) == 0xffffffff ) { _mtterm(); return FALSE; /* fail to load DLL */ } /* * Create a per-thread data structure for this (i.e., the startup) * thread. */ if ( ((ptd = _calloc_crt(1, sizeof(struct _tiddata))) == NULL) || !FLS_SETVALUE(__flsindex, (LPVOID)ptd) ) { _mtterm(); return FALSE; /* fail to load DLL */ } /* * Initialize the per-thread data */ _initptd(ptd,NULL); ptd->_tid = GetCurrentThreadId(); ptd->_thandle = (uintptr_t)(-1); return TRUE; }
_CRTIMP void * __cdecl _encoded_null() { return _encode_pointer(NULL); }