From 7cf9ad08e3c96327b2c6242a382062051f96d6fa Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sat, 30 Jul 2005 23:57:14 +0000 Subject: [PATCH] Don't use CSRSS handles if we alreay have some (so we can inherit file handles, etc) svn path=/trunk/; revision=16908 --- reactos/lib/kernel32/misc/dllmain.c | 30 ++++++++++++++++++--------- reactos/lib/kernel32/process/create.c | 7 ++++++- reactos/ntoskrnl/ke/kthread.c | 13 ++++++------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/reactos/lib/kernel32/misc/dllmain.c b/reactos/lib/kernel32/misc/dllmain.c index f341f3f67b1..c98ce50c241 100644 --- a/reactos/lib/kernel32/misc/dllmain.c +++ b/reactos/lib/kernel32/misc/dllmain.c @@ -167,18 +167,28 @@ BasepInitConsole(VOID) /* We got the handles, let's set them */ Parameters->ConsoleHandle = Request.Data.AllocConsoleRequest.Console; - SetStdHandle(STD_INPUT_HANDLE, Request.Data.AllocConsoleRequest.InputHandle); - SetStdHandle(STD_OUTPUT_HANDLE, Request.Data.AllocConsoleRequest.OutputHandle); - SetStdHandle(STD_ERROR_HANDLE, - DuplicateConsoleHandle(Request.Data.AllocConsoleRequest.OutputHandle, - 0, - TRUE, - DUPLICATE_SAME_ACCESS)); + + /* If we already had some, don't use the new ones */ + if (!Parameters->StandardInput) + { + Parameters->StandardInput = Request.Data.AllocConsoleRequest.InputHandle; + } + if (!Parameters->StandardOutput) + { + Parameters->StandardOutput = Request.Data.AllocConsoleRequest.OutputHandle; + } + if (!Parameters->StandardError) + { + Parameters->StandardError = DuplicateConsoleHandle(Request.Data.AllocConsoleRequest.OutputHandle, + 0, + TRUE, + DUPLICATE_SAME_ACCESS); + } DPRINT1("Console setup: %lx, %lx, %lx\n", - Request.Data.AllocConsoleRequest.Console, - Request.Data.AllocConsoleRequest.InputHandle, - Request.Data.AllocConsoleRequest.OutputHandle); + Parameters->ConsoleHandle, + Parameters->StandardInput, + Parameters->StandardOutput); return TRUE; } diff --git a/reactos/lib/kernel32/process/create.c b/reactos/lib/kernel32/process/create.c index d1b5047de7d..93b2987a31c 100644 --- a/reactos/lib/kernel32/process/create.c +++ b/reactos/lib/kernel32/process/create.c @@ -308,10 +308,13 @@ BasepCopyHandles(IN PRTL_USER_PROCESS_PARAMETERS Params, IN PRTL_USER_PROCESS_PARAMETERS PebParams, IN BOOL InheritHandles) { + DPRINT1("BasepCopyHandles %p %p, %d\n", Params, PebParams, InheritHandles); + /* Copy the handle if we are inheriting or if it's a console handle */ if (InheritHandles || IsConsoleHandle(PebParams->StandardInput)) { Params->StandardInput = PebParams->StandardInput; + DPRINT1("Standard Input: %x\n", Params->StandardInput); } if (InheritHandles || IsConsoleHandle(PebParams->StandardOutput)) { @@ -349,7 +352,7 @@ BasepInitializeEnvironment(HANDLE ProcessHandle, UNICODE_STRING Desktop, Shell, Runtime, Title; PPEB OurPeb = NtCurrentPeb(); - DPRINT("BasepInitializeEnvironment\n"); + DPRINT1("BasepInitializeEnvironment\n"); /* Get the full path name */ RetVal = GetFullPathNameW(ApplicationPathName, @@ -478,6 +481,7 @@ BasepInitializeEnvironment(HANDLE ProcessHandle, /* Write the handles only if we have to */ if (StartupInfo->dwFlags & STARTF_USESTDHANDLES) { + DPRINT1("Using Standard Handles\n"); ProcessParameters->StandardInput = StartupInfo->hStdInput; ProcessParameters->StandardOutput = StartupInfo->hStdOutput; ProcessParameters->StandardError = StartupInfo->hStdError; @@ -506,6 +510,7 @@ BasepInitializeEnvironment(HANDLE ProcessHandle, (STARTF_USESTDHANDLES | STARTF_USEHOTKEY | STARTF_SHELLPRIVATE))) { /* Use handles from PEB, if inheriting or they are console */ + DPRINT1("Copying handles from parent\n"); BasepCopyHandles(ProcessParameters, OurPeb->ProcessParameters, InheritHandles); diff --git a/reactos/ntoskrnl/ke/kthread.c b/reactos/ntoskrnl/ke/kthread.c index 83834665dae..4a83c6e0d20 100644 --- a/reactos/ntoskrnl/ke/kthread.c +++ b/reactos/ntoskrnl/ke/kthread.c @@ -342,11 +342,7 @@ KiAdjustQuantumThread(IN PKTHREAD Thread) Priority = Thread->Priority - (Thread->PriorityDecrement + 1); /* Normalize it if we've gone too low */ - if (Priority < Thread->BasePriority) - { - /* Normalize it if we've gone too low */ - Priority = Thread->BasePriority; - } + if (Priority < Thread->BasePriority) Priority = Thread->BasePriority; /* Reset the priority decrement, we've done it */ Thread->PriorityDecrement = 0; @@ -354,12 +350,15 @@ KiAdjustQuantumThread(IN PKTHREAD Thread) /* Set the new priority, if needed */ if (Priority != Thread->Priority) { - /* HACK HACK This isn't nice, but it's the only way with our current codebase */ + /* + * HACK HACK This isn't nice, but it's the only way with our + * current codebase + */ Thread->Priority = Priority; } else { - /* Priority hasn't changed, find a new thread */ + /* FIXME: Priority hasn't changed, find a new thread */ } } } -- 2.17.1