From a2464ecca726930038fbe59f8788960aabea283e Mon Sep 17 00:00:00 2001 From: Aleksey Bragin Date: Thu, 6 May 2010 10:50:26 +0000 Subject: [PATCH] [KERNEL32] - Code committed in revision 846 was lazily initializing command line options with a first call to GetCommandLine. However, this is not really thread-safe. Move initialization to DLL_PROCESS_ATTACH, where it should actually happen. See issue #5347 for more details. svn path=/trunk/; revision=47113 --- reactos/dll/win32/kernel32/include/kernel32.h | 4 ++++ reactos/dll/win32/kernel32/misc/dllmain.c | 3 +++ reactos/dll/win32/kernel32/process/cmdline.c | 20 +++---------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/reactos/dll/win32/kernel32/include/kernel32.h b/reactos/dll/win32/kernel32/include/kernel32.h index 60056f111f7..19731210435 100755 --- a/reactos/dll/win32/kernel32/include/kernel32.h +++ b/reactos/dll/win32/kernel32/include/kernel32.h @@ -190,3 +190,7 @@ IntGetCodePageEntry(UINT CodePage); LPWSTR GetDllLoadPath(LPCWSTR lpModule); + +VOID +WINAPI +InitCommandLines(VOID); diff --git a/reactos/dll/win32/kernel32/misc/dllmain.c b/reactos/dll/win32/kernel32/misc/dllmain.c index 02199f9349d..ef47c4d538f 100644 --- a/reactos/dll/win32/kernel32/misc/dllmain.c +++ b/reactos/dll/win32/kernel32/misc/dllmain.c @@ -330,6 +330,9 @@ DllMain(HANDLE hDll, wcscpy(SystemDirectory.Buffer, WindowsDirectory.Buffer); wcscat(SystemDirectory.Buffer, L"\\System32"); + /* Initialize command line */ + InitCommandLines(); + /* Open object base directory */ Status = OpenBaseDirectory(&hBaseDir); if (!NT_SUCCESS(Status)) diff --git a/reactos/dll/win32/kernel32/process/cmdline.c b/reactos/dll/win32/kernel32/process/cmdline.c index 9b84ab92a74..2c2b2421966 100644 --- a/reactos/dll/win32/kernel32/process/cmdline.c +++ b/reactos/dll/win32/kernel32/process/cmdline.c @@ -27,19 +27,17 @@ static BOOL bCommandLineInitialized = FALSE; /* FUNCTIONS ****************************************************************/ -static VOID +WINAPI InitCommandLines(VOID) { PRTL_USER_PROCESS_PARAMETERS Params; - /* FIXME - not thread-safe! */ - - // get command line + /* get command line */ Params = NtCurrentPeb()->ProcessParameters; RtlNormalizeProcessParams (Params); - // initialize command line buffers + /* initialize command line buffers */ CommandLineStringW.Length = Params->CommandLine.Length; CommandLineStringW.MaximumLength = CommandLineStringW.Length + sizeof(WCHAR); CommandLineStringW.Buffer = RtlAllocateHeap(GetProcessHeap(), @@ -80,13 +78,7 @@ LPSTR WINAPI GetCommandLineA(VOID) { - if (bCommandLineInitialized == FALSE) - { - InitCommandLines(); - } - DPRINT("CommandLine \'%s\'\n", CommandLineStringA.Buffer); - return CommandLineStringA.Buffer; } @@ -98,13 +90,7 @@ LPWSTR WINAPI GetCommandLineW(VOID) { - if (bCommandLineInitialized == FALSE) - { - InitCommandLines(); - } - DPRINT("CommandLine \'%S\'\n", CommandLineStringW.Buffer); - return CommandLineStringW.Buffer; }