2008-07-02 08:20:43 +00:00
|
|
|
/*
|
|
|
|
* msvcrt40 main file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Louis Lenders
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
2011-07-24 13:31:11 +00:00
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
//#include <stdio.h>
|
2011-07-24 13:31:11 +00:00
|
|
|
#define _CRT_PRECOMP_H
|
|
|
|
#include <internal/tls.h>
|
2013-01-24 23:00:42 +00:00
|
|
|
//#include <stdlib.h>
|
|
|
|
//#include <windows.h>
|
2011-07-24 13:31:11 +00:00
|
|
|
#include <internal/wine/msvcrt.h>
|
2012-12-09 11:42:02 +00:00
|
|
|
#include <internal/locale.h>
|
2013-01-24 23:00:42 +00:00
|
|
|
//#include <locale.h>
|
|
|
|
//#include <mbctype.h>
|
2008-07-02 08:20:43 +00:00
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <wine/debug.h>
|
2011-07-24 13:31:11 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2008-07-02 08:20:43 +00:00
|
|
|
|
2011-07-24 13:31:11 +00:00
|
|
|
/* EXTERNAL PROTOTYPES ********************************************************/
|
2008-07-02 08:20:43 +00:00
|
|
|
|
2011-07-24 13:31:11 +00:00
|
|
|
extern int BlockEnvToEnvironA(void);
|
|
|
|
extern int BlockEnvToEnvironW(void);
|
|
|
|
extern void FreeEnvironment(char **environment);
|
|
|
|
|
|
|
|
extern unsigned int _osplatform;
|
|
|
|
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
|
|
|
|
WINAPI
|
|
|
|
DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
|
2008-07-02 08:20:43 +00:00
|
|
|
{
|
2011-07-24 13:31:11 +00:00
|
|
|
OSVERSIONINFOW osvi;
|
|
|
|
switch (dwReason)
|
|
|
|
{
|
2011-12-02 21:18:42 +00:00
|
|
|
case DLL_PROCESS_ATTACH:
|
2011-07-24 13:31:11 +00:00
|
|
|
/* initialize version info */
|
2011-12-02 21:18:42 +00:00
|
|
|
TRACE("Process Attach\n");
|
2011-07-24 13:31:11 +00:00
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
|
|
|
|
GetVersionExW( &osvi );
|
|
|
|
_winver = (osvi.dwMajorVersion << 8) | osvi.dwMinorVersion;
|
|
|
|
_winmajor = osvi.dwMajorVersion;
|
|
|
|
_winminor = osvi.dwMinorVersion;
|
|
|
|
_osplatform = osvi.dwPlatformId;
|
|
|
|
_osver = osvi.dwBuildNumber;
|
|
|
|
|
|
|
|
/* create tls stuff */
|
2011-12-02 21:18:42 +00:00
|
|
|
if (!msvcrt_init_tls())
|
|
|
|
return FALSE;
|
2011-07-24 13:31:11 +00:00
|
|
|
|
|
|
|
if (BlockEnvToEnvironA() < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (BlockEnvToEnvironW() < 0)
|
|
|
|
{
|
|
|
|
FreeEnvironment(_environ);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_acmdln = _strdup(GetCommandLineA());
|
|
|
|
_wcmdln = _wcsdup(GetCommandLineW());
|
|
|
|
|
|
|
|
/* Initialization of the WINE code */
|
|
|
|
msvcrt_init_mt_locks();
|
2011-12-02 21:18:42 +00:00
|
|
|
//msvcrt_init_math();
|
2011-07-24 13:31:11 +00:00
|
|
|
msvcrt_init_io();
|
2011-12-02 21:18:42 +00:00
|
|
|
//msvcrt_init_console();
|
|
|
|
//msvcrt_init_args();
|
|
|
|
//msvcrt_init_signals();
|
2011-07-24 13:31:11 +00:00
|
|
|
TRACE("Attach done\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_ATTACH:
|
2011-12-02 21:18:42 +00:00
|
|
|
//msvcrt_get_thread_data creates data when first called
|
2011-07-24 13:31:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_DETACH:
|
2011-12-02 21:18:42 +00:00
|
|
|
msvcrt_free_tls_mem();
|
2011-07-24 13:31:11 +00:00
|
|
|
break;
|
|
|
|
|
2008-07-02 08:20:43 +00:00
|
|
|
case DLL_PROCESS_DETACH:
|
2011-12-02 21:18:42 +00:00
|
|
|
TRACE("Detach\n");
|
2011-07-24 13:31:11 +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();
|
2011-07-24 13:31:11 +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 11:42:02 +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)
|
2011-07-24 13:31:11 +00:00
|
|
|
FreeEnvironment((char**)__winitenv);
|
|
|
|
if (_wenviron)
|
|
|
|
FreeEnvironment((char**)_wenviron);
|
|
|
|
|
2015-04-18 12:15:15 +00:00
|
|
|
if (__initenv && __initenv != _environ)
|
2011-07-24 13:31:11 +00:00
|
|
|
FreeEnvironment(__initenv);
|
|
|
|
if (_environ)
|
|
|
|
FreeEnvironment(_environ);
|
|
|
|
|
|
|
|
TRACE("Detach done\n");
|
2008-07-02 08:20:43 +00:00
|
|
|
break;
|
2011-07-24 13:31:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2008-07-02 08:20:43 +00:00
|
|
|
}
|
2011-07-24 13:31:11 +00:00
|
|
|
|
2012-12-09 11:42:02 +00:00
|
|
|
/* EOF */
|