https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e91f201be2bd2feeb1939…
commit e91f201be2bd2feeb193915f71ac7b2b717e02e5
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Thu Jul 29 09:38:42 2021 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Wed Aug 4 02:03:07 2021 +0200
[CRT] Implement crt_process_init()
---
dll/win32/crtdll/dllmain.c | 42 +++----------------------------
dll/win32/msvcrt/dllmain.c | 43 ++++----------------------------
sdk/lib/crt/misc/crt_init.c | 59 ++++++++++++++++++++++++++++++++++++++++++++
sdk/lib/crt/misc/misc.cmake | 1 +
sdk/lib/crt/startup/crtexe.c | 7 ++++++
5 files changed, 76 insertions(+), 76 deletions(-)
diff --git a/dll/win32/crtdll/dllmain.c b/dll/win32/crtdll/dllmain.c
index 8d6af8c69b2..c6324f2032f 100644
--- a/dll/win32/crtdll/dllmain.c
+++ b/dll/win32/crtdll/dllmain.c
@@ -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:
diff --git a/dll/win32/msvcrt/dllmain.c b/dll/win32/msvcrt/dllmain.c
index d48d0d31e49..d47430db39e 100644
--- a/dll/win32/msvcrt/dllmain.c
+++ b/dll/win32/msvcrt/dllmain.c
@@ -21,18 +21,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
/* EXTERNAL PROTOTYPES ********************************************************/
-extern int BlockEnvToEnvironA(void);
-extern int BlockEnvToEnvironW(void);
-extern void FreeEnvironment(char **environment);
+BOOL crt_process_init(void);
-extern unsigned int _osplatform;
-extern unsigned int _osver;
-extern unsigned int _winminor;
-extern unsigned int _winmajor;
-extern unsigned int _winver;
+extern void FreeEnvironment(char **environment);
-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;
+ TRACE("Process Attach\n");
- 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;
diff --git a/sdk/lib/crt/misc/crt_init.c b/sdk/lib/crt/misc/crt_init.c
new file mode 100644
index 00000000000..6818144a8ac
--- /dev/null
+++ b/sdk/lib/crt/misc/crt_init.c
@@ -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;
+}
diff --git a/sdk/lib/crt/misc/misc.cmake b/sdk/lib/crt/misc/misc.cmake
index 18abea274c1..d5cea9dd5cc 100644
--- a/sdk/lib/crt/misc/misc.cmake
+++ b/sdk/lib/crt/misc/misc.cmake
@@ -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
diff --git a/sdk/lib/crt/startup/crtexe.c b/sdk/lib/crt/startup/crtexe.c
index 3897242197b..afe23416b8d 100644
--- a/sdk/lib/crt/startup/crtexe.c
+++ b/sdk/lib/crt/startup/crtexe.c
@@ -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"