[CRT] Implement crt_process_init()

This commit is contained in:
Timo Kreuzer 2021-07-29 09:38:42 +02:00
parent 8043b76e85
commit e91f201be2
5 changed files with 76 additions and 76 deletions

View file

@ -29,14 +29,10 @@ extern void __getmainargs( int *argc, char ***argv, char ***envp,
/* EXTERNAL PROTOTYPES ********************************************************/
extern int BlockEnvToEnvironA(void);
extern int BlockEnvToEnvironW(void);
BOOL crt_process_init(void);
extern void FreeEnvironment(char **environment);
extern unsigned int _osver;
extern unsigned int _winminor;
extern unsigned int _winmajor;
extern unsigned int _winver;
unsigned int CRTDLL__basemajor_dll = 0;
unsigned int CRTDLL__baseminor_dll = 0;
@ -48,8 +44,6 @@ unsigned int CRTDLL__osmode_dll = 0;
unsigned int CRTDLL__osversion_dll = 0;
int _fileinfo_dll;
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 */
@ -112,40 +106,12 @@ DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
CRTDLL__osmode_dll = 1; /* FIXME */
CRTDLL__osversion_dll = (version & 0xFFFF);
_winmajor = (_osver >> 8) & 0xFF;
_winminor = _osver & 0xFF;
_winver = (_winmajor << 8) + _winminor;
_osver = (_osver >> 16) & 0xFFFF;
/* create tls stuff */
if (!msvcrt_init_tls())
return FALSE;
if (BlockEnvToEnvironA() < 0)
return FALSE;
if (BlockEnvToEnvironW() < 0)
if (!crt_process_init())
{
FreeEnvironment(_environ);
ERR("crt_init() failed!\n");
return FALSE;
}
_acmdln = _strdup(GetCommandLineA());
_wcmdln = _wcsdup(GetCommandLineW());
/* Initialization of the WINE code */
msvcrt_init_mt_locks();
//if(!msvcrt_init_locale()) {
//msvcrt_free_mt_locks();
// msvcrt_free_tls_mem();
//return FALSE;
//}
//msvcrt_init_math();
msvcrt_init_io();
//msvcrt_init_console();
//msvcrt_init_args();
//msvcrt_init_signals();
_setmbcp(_MB_CP_LOCALE);
TRACE("Attach done\n");
break;
case DLL_THREAD_ATTACH:

View file

@ -21,18 +21,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
/* EXTERNAL PROTOTYPES ********************************************************/
extern int BlockEnvToEnvironA(void);
extern int BlockEnvToEnvironW(void);
BOOL crt_process_init(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 */
@ -45,43 +37,18 @@ BOOL
WINAPI
DllMain(PVOID hinstDll, ULONG dwReason, PVOID reserved)
{
OSVERSIONINFOW osvi;
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
/* initialize version info */
TRACE("Process Attach\n");
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 */
if (!msvcrt_init_tls())
return FALSE;
if (BlockEnvToEnvironA() < 0)
return FALSE;
if (BlockEnvToEnvironW() < 0)
if (!crt_process_init())
{
FreeEnvironment(_environ);
ERR("crt_init() failed!\n");
return FALSE;
}
_acmdln = _strdup(GetCommandLineA());
_wcmdln = _wcsdup(GetCommandLineW());
/* Initialization of the WINE code */
msvcrt_init_mt_locks();
//msvcrt_init_math();
msvcrt_init_io();
//msvcrt_init_console();
//msvcrt_init_args();
//msvcrt_init_signals();
TRACE("Attach done\n");
break;

View file

@ -0,0 +1,59 @@
#include <precomp.h>
extern int BlockEnvToEnvironA(void);
extern int BlockEnvToEnvironW(void);
extern void FreeEnvironment(char **environment);
extern void msvcrt_init_mt_locks(void);
extern void msvcrt_init_io(void);
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 */
BOOL
crt_process_init(void)
{
OSVERSIONINFOW osvi;
/* initialize version info */
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 */
if (!msvcrt_init_tls())
return FALSE;
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();
//msvcrt_init_math();
msvcrt_init_io();
//msvcrt_init_console();
//msvcrt_init_args();
//msvcrt_init_signals();
return TRUE;
}

View file

@ -14,6 +14,7 @@ list(APPEND CRT_MISC_SOURCE
misc/__crt_MessageBoxA.c
misc/amsg.c
misc/assert.c
misc/crt_init.c
misc/environ.c
misc/getargs.c
misc/i10output.c

View file

@ -163,6 +163,7 @@ int __cdecl WinMainCRTStartup (void)
}
int __cdecl mainCRTStartup (void);
BOOL crt_process_init(void);
#ifdef _WIN64
int __mingw_init_ehandler (void);
@ -171,6 +172,12 @@ int __mingw_init_ehandler (void);
int __cdecl mainCRTStartup (void)
{
int ret = 255;
#ifndef _DLL
if (!crt_process_init())
{
return -1;
}
#endif
#ifdef __SEH__
asm ("\t.l_start:\n"
"\t.seh_handler __C_specific_handler, @except\n"