2011-12-02 21:18:42 +00:00
|
|
|
/*
|
2006-02-17 00:04:10 +00:00
|
|
|
* dllmain.c
|
|
|
|
*
|
|
|
|
* ReactOS MSVCRT.DLL Compatibility Library
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS NOT COPYRIGHTED
|
|
|
|
*
|
|
|
|
* This source code is offered for use in the public domain. You may
|
|
|
|
* use, modify or distribute it freely.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful but
|
2016-11-12 21:53:33 +00:00
|
|
|
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
|
|
|
|
* DISCLAMED. This includes but is not limited to warranties of
|
2006-02-17 00:04:10 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2006-02-17 00:04:10 +00:00
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
/* EXTERNAL PROTOTYPES ********************************************************/
|
|
|
|
|
|
|
|
extern int BlockEnvToEnvironA(void);
|
|
|
|
extern int BlockEnvToEnvironW(void);
|
|
|
|
extern void FreeEnvironment(char **environment);
|
|
|
|
|
2010-07-11 16:25:30 +00:00
|
|
|
extern unsigned int _osplatform;
|
2006-02-17 00:04:10 +00:00
|
|
|
extern unsigned int _osver;
|
|
|
|
extern unsigned int _winminor;
|
|
|
|
extern unsigned int _winmajor;
|
|
|
|
extern unsigned int _winver;
|
|
|
|
|
|
|
|
extern char* _acmdln; /* pointer to ascii command line */
|
|
|
|
extern wchar_t* _wcmdln; /* pointer to wide character command line */
|
|
|
|
#undef _environ
|
|
|
|
extern char** _environ; /* pointer to environment block */
|
|
|
|
extern char** __initenv; /* pointer to initial environment block */
|
|
|
|
extern wchar_t** _wenviron; /* pointer to environment block */
|
|
|
|
extern wchar_t** __winitenv; /* pointer to initial environment block */
|
|
|
|
|
|
|
|
/* LIBRARY ENTRY POINT ********************************************************/
|
|
|
|
|
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2006-02-17 00:04:10 +00:00
|
|
|
DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
|
|
|
|
{
|
2009-06-07 11:24:37 +00:00
|
|
|
OSVERSIONINFOW osvi;
|
2006-02-17 00:04:10 +00:00
|
|
|
switch (dwReason)
|
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
case DLL_PROCESS_ATTACH:
|
2006-02-17 00:04:10 +00:00
|
|
|
/* initialize version info */
|
2011-12-02 21:18:42 +00:00
|
|
|
TRACE("Process Attach\n");
|
2009-06-07 11:24:37 +00:00
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
|
|
|
|
GetVersionExW( &osvi );
|
|
|
|
_winver = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
|
|
|
|
_winmajor = osvi.dwMajorVersion;
|
|
|
|
_winminor = osvi.dwMinorVersion;
|
2010-07-11 16:25:30 +00:00
|
|
|
_osplatform = osvi.dwPlatformId;
|
2009-06-07 11:24:37 +00:00
|
|
|
_osver = osvi.dwBuildNumber;
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
/* create tls stuff */
|
2011-12-02 21:18:42 +00:00
|
|
|
if (!msvcrt_init_tls())
|
|
|
|
return FALSE;
|
2006-02-17 00:04:10 +00:00
|
|
|
|
|
|
|
if (BlockEnvToEnvironA() < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (BlockEnvToEnvironW() < 0)
|
|
|
|
{
|
|
|
|
FreeEnvironment(_environ);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_acmdln = _strdup(GetCommandLineA());
|
|
|
|
_wcmdln = _wcsdup(GetCommandLineW());
|
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
/* Initialization of the WINE code */
|
2006-02-17 00:04:10 +00:00
|
|
|
msvcrt_init_mt_locks();
|
2011-12-02 21:18:42 +00:00
|
|
|
//msvcrt_init_math();
|
2008-06-11 08:54:46 +00:00
|
|
|
msvcrt_init_io();
|
2011-12-02 21:18:42 +00:00
|
|
|
//msvcrt_init_console();
|
|
|
|
//msvcrt_init_args();
|
|
|
|
//msvcrt_init_signals();
|
2008-06-06 17:49:24 +00:00
|
|
|
TRACE("Attach done\n");
|
2006-02-17 00:04:10 +00:00
|
|
|
break;
|
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
case DLL_THREAD_ATTACH:
|
2011-12-02 21:18:42 +00:00
|
|
|
//msvcrt_get_thread_data creates data when first called
|
2006-02-17 00:04:10 +00:00
|
|
|
break;
|
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
case DLL_THREAD_DETACH:
|
2011-12-02 21:18:42 +00:00
|
|
|
msvcrt_free_tls_mem();
|
2006-02-17 00:04:10 +00:00
|
|
|
break;
|
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
case DLL_PROCESS_DETACH:
|
2011-12-02 21:18:42 +00:00
|
|
|
TRACE("Detach\n");
|
2008-06-11 08:54:46 +00:00
|
|
|
/* Deinit of the WINE code */
|
|
|
|
msvcrt_free_io();
|
2015-04-18 12:15:15 +00:00
|
|
|
if (reserved) break;
|
2017-07-17 16:11:18 +00:00
|
|
|
msvcrt_free_popen_data();
|
2008-06-11 08:54:46 +00:00
|
|
|
msvcrt_free_mt_locks();
|
2011-12-02 21:18:42 +00:00
|
|
|
//msvcrt_free_console();
|
|
|
|
//msvcrt_free_args();
|
|
|
|
//msvcrt_free_signals();
|
|
|
|
msvcrt_free_tls_mem();
|
|
|
|
if (!msvcrt_free_tls())
|
|
|
|
return FALSE;
|
2012-12-09 03:17:14 +00:00
|
|
|
if(global_locale)
|
|
|
|
MSVCRT__free_locale(global_locale);
|
2011-12-02 21:18:42 +00:00
|
|
|
|
2015-04-18 12:15:15 +00:00
|
|
|
if (__winitenv && __winitenv != _wenviron)
|
2006-02-17 00:04:10 +00:00
|
|
|
FreeEnvironment((char**)__winitenv);
|
|
|
|
if (_wenviron)
|
|
|
|
FreeEnvironment((char**)_wenviron);
|
|
|
|
|
2015-04-18 12:15:15 +00:00
|
|
|
if (__initenv && __initenv != _environ)
|
2006-02-17 00:04:10 +00:00
|
|
|
FreeEnvironment(__initenv);
|
|
|
|
if (_environ)
|
|
|
|
FreeEnvironment(_environ);
|
|
|
|
|
2008-06-06 17:49:24 +00:00
|
|
|
TRACE("Detach done\n");
|
2006-02-17 00:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-12-26 17:13:08 +00:00
|
|
|
/* FIXME: This hack is required to prevent the VC linker from linking these
|
|
|
|
exports to the functions from libntdll. See CORE-10753 */
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#ifdef _M_IX86
|
|
|
|
#pragma comment(linker, "/include:__vsnprintf")
|
|
|
|
#pragma comment(linker, "/include:_bsearch")
|
|
|
|
#pragma comment(linker, "/include:_strcspn")
|
|
|
|
#else
|
|
|
|
#pragma comment(linker, "/include:_vsnprintf")
|
|
|
|
#pragma comment(linker, "/include:bsearch")
|
|
|
|
#pragma comment(linker, "/include:strcspn")
|
|
|
|
#endif // _M_IX86
|
|
|
|
#endif // _MSC_VER
|
|
|
|
|
2006-02-17 00:04:10 +00:00
|
|
|
/* EOF */
|