Don't use CSRSS handles if we alreay have some (so we can inherit file handles, etc)
authorAlex Ionescu <aionescu@gmail.com>
Sat, 30 Jul 2005 23:57:14 +0000 (23:57 +0000)
committerAlex Ionescu <aionescu@gmail.com>
Sat, 30 Jul 2005 23:57:14 +0000 (23:57 +0000)
svn path=/trunk/; revision=16908

reactos/lib/kernel32/misc/dllmain.c
reactos/lib/kernel32/process/create.c
reactos/ntoskrnl/ke/kthread.c

index f341f3f..c98ce50 100644 (file)
@@ -167,18 +167,28 @@ BasepInitConsole(VOID)
 
     /* We got the handles, let's set them */
     Parameters->ConsoleHandle = Request.Data.AllocConsoleRequest.Console;
 
     /* 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", 
 
     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;
 }
 
     return TRUE;
 }
 
index d1b5047..93b2987 100644 (file)
@@ -308,10 +308,13 @@ BasepCopyHandles(IN PRTL_USER_PROCESS_PARAMETERS Params,
                  IN PRTL_USER_PROCESS_PARAMETERS PebParams,
                  IN BOOL InheritHandles)
 {
                  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;
     /* 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))
     {
     }
     if (InheritHandles || IsConsoleHandle(PebParams->StandardOutput))
     {
@@ -349,7 +352,7 @@ BasepInitializeEnvironment(HANDLE ProcessHandle,
     UNICODE_STRING Desktop, Shell, Runtime, Title;
     PPEB OurPeb = NtCurrentPeb();
     
     UNICODE_STRING Desktop, Shell, Runtime, Title;
     PPEB OurPeb = NtCurrentPeb();
     
-    DPRINT("BasepInitializeEnvironment\n");
+    DPRINT1("BasepInitializeEnvironment\n");
     
     /* Get the full path name */
     RetVal = GetFullPathNameW(ApplicationPathName,
     
     /* 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)
     {
     /* 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;
         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 */ 
               (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);
             BasepCopyHandles(ProcessParameters,
                              OurPeb->ProcessParameters,
                              InheritHandles);
index 8383466..4a83c6e 100644 (file)
@@ -342,11 +342,7 @@ KiAdjustQuantumThread(IN PKTHREAD Thread)
             Priority = Thread->Priority - (Thread->PriorityDecrement + 1);
 
             /* Normalize it if we've gone too low */
             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;
 
             /* 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)
             {
             /* 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
             {
                 Thread->Priority = Priority;
             }
             else
             {
-                /* Priority hasn't changed, find a new thread */
+                /* FIXME: Priority hasn't changed, find a new thread */
             }
         }
     }
             }
         }
     }