From 3d253874663a19afc62d0f76a78bde90c8bc8aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Wed, 28 Jan 2004 20:52:57 +0000 Subject: [PATCH] Don't wait for GUI processes to finish svn path=/trunk/; revision=7898 --- reactos/include/wine/winternl.h | 4 +- reactos/lib/kernel32/process/create.c | 15 ++++- reactos/subsys/system/cmd/cmd.c | 93 ++++++++++++++++++++++++--- reactos/subsys/system/cmd/makefile | 3 +- 4 files changed, 101 insertions(+), 14 deletions(-) diff --git a/reactos/include/wine/winternl.h b/reactos/include/wine/winternl.h index 6b8e07a3974..7e6e09fc562 100644 --- a/reactos/include/wine/winternl.h +++ b/reactos/include/wine/winternl.h @@ -158,7 +158,9 @@ typedef struct _PEB BYTE __pad_1c[36]; /* 1c */ PRTL_BITMAP TlsBitmap; /* 40 */ ULONG TlsBitmapBits[2]; /* 44 */ - BYTE __pad_4c[156]; /* 4c */ + BYTE __pad_4c[104]; /* 4c */ + ULONG ImageSubSystem; /* b4 */ + BYTE __pad_b8[48]; /* b8 */ PVOID Reserved3[59]; /* e8 */ ULONG SessionId; /* 1d4 */ } PEB, *PPEB; diff --git a/reactos/lib/kernel32/process/create.c b/reactos/lib/kernel32/process/create.c index 86add309055..b7c7215501d 100644 --- a/reactos/lib/kernel32/process/create.c +++ b/reactos/lib/kernel32/process/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.80 2004/01/23 21:16:04 ekohl Exp $ +/* $Id: create.c,v 1.81 2004/01/28 20:52:57 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -559,7 +559,8 @@ static NTSTATUS KlInitPeb ( HANDLE ProcessHandle, PRTL_USER_PROCESS_PARAMETERS Ppb, - PVOID * ImageBaseAddress + PVOID * ImageBaseAddress, + ULONG ImageSubSystem ) { NTSTATUS Status; @@ -662,6 +663,14 @@ static NTSTATUS KlInitPeb sizeof(PpbBase), &BytesWritten); + /* Write image subsystem */ + Offset = FIELD_OFFSET(PEB, ImageSubSystem); + NtWriteVirtualMemory(ProcessHandle, + (PVOID)(PEB_BASE + Offset), + &ImageSubSystem, + sizeof(ImageSubSystem), + &BytesWritten); + /* Read image base address. */ Offset = FIELD_OFFSET(PEB, ImageBaseAddress); NtReadVirtualMemory(ProcessHandle, @@ -1358,7 +1367,7 @@ CreateProcessW */ DPRINT("Creating peb\n"); - KlInitPeb(hProcess, Ppb, &ImageBaseAddress); + KlInitPeb(hProcess, Ppb, &ImageBaseAddress, Sii.Subsystem); RtlDestroyProcessParameters (Ppb); diff --git a/reactos/subsys/system/cmd/cmd.c b/reactos/subsys/system/cmd/cmd.c index 38edf52d946..4e3237be6b4 100644 --- a/reactos/subsys/system/cmd/cmd.c +++ b/reactos/subsys/system/cmd/cmd.c @@ -1,4 +1,4 @@ -/* $Id: cmd.c,v 1.9 2003/12/26 09:52:37 navaraf Exp $ +/* $Id: cmd.c,v 1.10 2004/01/28 20:52:57 gvg Exp $ * * CMD.C - command-line interface. * @@ -129,10 +129,19 @@ #include #include #include +#include +#include + +#ifndef NT_SUCCESS +#define NT_SUCCESS(StatCode) ((NTSTATUS)(StatCode) >= 0) +#endif #include "cmd.h" #include "batch.h" +typedef NTSTATUS (STDCALL *NtQueryInformationProcessProc)(HANDLE, PROCESSINFOCLASS, + PVOID, ULONG, PULONG); +typedef NTSTATUS (STDCALL *NtReadVirtualMemoryProc)(HANDLE, PVOID, PVOID, ULONG, PULONG); BOOL bExit = FALSE; /* indicates EXIT was typed */ BOOL bCanExit = TRUE; /* indicates if this shell is exitable */ @@ -146,6 +155,10 @@ HANDLE hIn; HANDLE hOut; HANDLE hConsole; +static NtQueryInformationProcessProc NtQueryInformationProcessPtr; +static NtReadVirtualMemoryProc NtReadVirtualMemoryPtr; +static BOOL NtDllChecked = FALSE; + #ifdef INCLUDE_CMD_COLOR WORD wColor; /* current color */ WORD wDefColor; /* default color */ @@ -162,6 +175,65 @@ static BOOL IsDelimiter (TCHAR c) return (c == _T('/') || c == _T('=') || c == _T('\0') || _istspace (c)); } +/* + * Is a process a console process? + */ +static BOOL IsConsoleProcess(HANDLE Process) +{ + NTSTATUS Status; + PROCESS_BASIC_INFORMATION Info; + PEB ProcessPeb; + ULONG BytesRead; + HMODULE NtDllModule; + + /* Some people like to run ReactOS cmd.exe on Win98, it helps in the + build process. So don't link implicitly against ntdll.dll, load it + dynamically instead */ + if (! NtDllChecked) + { + NtDllChecked = TRUE; + NtDllModule = LoadLibrary(_T("ntdll.dll")); + if (NULL == NtDllModule) + { + /* Probably non-WinNT system. Just wait for the commands + to finish. */ + NtQueryInformationProcessPtr = NULL; + NtReadVirtualMemoryPtr = NULL; + return TRUE; + } + NtQueryInformationProcessPtr = (NtQueryInformationProcessProc) + GetProcAddress(NtDllModule, "NtQueryInformationProcess"); + NtReadVirtualMemoryPtr = (NtReadVirtualMemoryProc) + GetProcAddress(NtDllModule, "NtReadVirtualMemory"); + } + + if (NULL == NtQueryInformationProcessPtr || NULL == NtReadVirtualMemoryPtr) + { + return FALSE; + } + + Status = NtQueryInformationProcessPtr(Process, ProcessBasicInformation, + &Info, sizeof(PROCESS_BASIC_INFORMATION), NULL); + if (! NT_SUCCESS(Status)) + { +#ifdef _DEBUG + DebugPrintf (_T("NtQueryInformationProcess failed with status %08x\n"), Status); +#endif + return TRUE; + } + Status = NtReadVirtualMemoryPtr(Process, Info.PebBaseAddress, &ProcessPeb, + sizeof(PEB), &BytesRead); + if (! NT_SUCCESS(Status) || sizeof(PEB) != BytesRead) + { +#ifdef _DEBUG + DebugPrintf (_T("Couldn't read virt mem status %08x bytes read %lu\n"), Status, BytesRead); +#endif + return TRUE; + } + + return IMAGE_SUBSYSTEM_WINDOWS_CUI == ProcessPeb.ImageSubSystem; +} + /* * This command (in first) was not found in the command table @@ -260,17 +332,20 @@ Execute (LPTSTR first, LPTSTR rest) &stui, &prci)) { - /* FIXME: Protect this with critical section */ - bChildProcessRunning = TRUE; - dwChildProcessId = prci.dwProcessId; + if (IsConsoleProcess(prci.hProcess)) + { + /* FIXME: Protect this with critical section */ + bChildProcessRunning = TRUE; + dwChildProcessId = prci.dwProcessId; - WaitForSingleObject (prci.hProcess, INFINITE); + WaitForSingleObject (prci.hProcess, INFINITE); - /* FIXME: Protect this with critical section */ - bChildProcessRunning = FALSE; + /* FIXME: Protect this with critical section */ + bChildProcessRunning = FALSE; - GetExitCodeProcess (prci.hProcess, &dwExitCode); - nErrorLevel = (INT)dwExitCode; + GetExitCodeProcess (prci.hProcess, &dwExitCode); + nErrorLevel = (INT)dwExitCode; + } CloseHandle (prci.hThread); CloseHandle (prci.hProcess); } diff --git a/reactos/subsys/system/cmd/makefile b/reactos/subsys/system/cmd/makefile index 95fd4bc6d0c..087033a8185 100644 --- a/reactos/subsys/system/cmd/makefile +++ b/reactos/subsys/system/cmd/makefile @@ -15,7 +15,8 @@ TARGET_NAME = cmd TARGET_INSTALLDIR = system32 -TARGET_CFLAGS = -D__USE_W32API -DANONYMOUSUNIONS -Wall -Werror -I$(PATH_TO_TOP)/include -I$(PATH_TO_TOP)/include/msvcrt +TARGET_CFLAGS = -D__USE_W32API -DANONYMOUSUNIONS -Wall -Werror -I$(PATH_TO_TOP)/include \ + -I$(PATH_TO_TOP)/include/msvcrt -D_WIN32_WINNT=0x0501 WINE_MODE = yes