Commit in reactos on MAIN
lib/kernel32/process/create.c+74-261.88 -> 1.89
lib/ntdll/ldr/startup.c+8-81.58 -> 1.59
lib/ntdll/rtl/process.c+12-471.36 -> 1.37
ntoskrnl/ldr/init.c+2-131.48 -> 1.49
ntoskrnl/ps/process.c+89-71.155 -> 1.156
+185-101
5 modified files
1. don't allow the ProcessImageFileName information class for NtSetInformationProcess() anymore
2. implemented the ProcessImageFileName class for NtQueryInformationProcess
3. changed NtCreateProcess to obtain the file name of the loaded image

reactos/lib/kernel32/process
create.c 1.88 -> 1.89
diff -u -r1.88 -r1.89
--- create.c	7 Nov 2004 15:58:41 -0000	1.88
+++ create.c	21 Nov 2004 21:09:42 -0000	1.89
@@ -1,4 +1,4 @@
-/* $Id: create.c,v 1.88 2004/11/07 15:58:41 blight Exp $
+/* $Id: create.c,v 1.89 2004/11/21 21:09:42 weiden Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -765,7 +765,6 @@
    UNICODE_STRING CommandLine_U;
    CSRSS_API_REQUEST CsrRequest;
    CSRSS_API_REPLY CsrReply;
-   CHAR ImageFileName[8];
    PWCHAR s, e;
    ULONG i;
    UNICODE_STRING CurrentDirectory_U;
@@ -780,7 +779,11 @@
    WCHAR Name[MAX_PATH];
    WCHAR *TidyCmdLine;
    BOOL IsBatchFile = FALSE;
-
+   PROCESS_PRIORITY_CLASS PriorityClass;
+   OBJECT_ATTRIBUTES ProcObjectAttributes;
+   ULONG ProcAttributes = 0;
+   PVOID ProcSecurity = NULL;
+   
    DPRINT("CreateProcessW(lpApplicationName '%S', lpCommandLine '%S')\n",
 	   lpApplicationName, lpCommandLine);
 
@@ -876,23 +879,6 @@
 	  return FALSE;
        }
    }
-
-   /*
-    * Store the image file name for the process
-    */
-   e = wcschr(s, L'.');
-   if (e != NULL)
-     {
-	*e = 0;
-     }
-   for (i = 0; i < 8; i++)
-     {
-	ImageFileName[i] = (CHAR)(s[i]);
-     }
-   if (e != NULL)
-     {
-	*e = '.';
-     }
    
    /*
     * Process the application name and command line
@@ -1013,16 +999,79 @@
    }
 /////////////////////////////////////////
    /*
+    * Initialize the process object attributes
+    */
+
+   if(lpProcessAttributes != NULL)
+   {
+     if(lpProcessAttributes->bInheritHandle)
+     {
+       ProcAttributes |= OBJ_INHERIT;
+     }
+     ProcSecurity = lpProcessAttributes->lpSecurityDescriptor;
+   }
+
+   InitializeObjectAttributes(&ProcObjectAttributes,
+			      NULL,
+			      ProcAttributes,
+			      NULL,
+			      ProcSecurity);
+   /*
+    * initialize the process priority class structure
+    */
+   PriorityClass.Foreground = FALSE;
+   
+   if(dwCreationFlags & IDLE_PRIORITY_CLASS)
+   {
+     PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_IDLE;
+   }
+   else if(dwCreationFlags & BELOW_NORMAL_PRIORITY_CLASS)
+   {
+     PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_BELOW_NORMAL;
+   }
+   else if(dwCreationFlags & NORMAL_PRIORITY_CLASS)
+   {
+     PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_NORMAL;
+   }
+   else if(dwCreationFlags & ABOVE_NORMAL_PRIORITY_CLASS)
+   {
+     PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_ABOVE_NORMAL;
+   }
+   else if(dwCreationFlags & HIGH_PRIORITY_CLASS)
+   {
+     PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_HIGH;
+   }
+   else if(dwCreationFlags & REALTIME_PRIORITY_CLASS)
+   {
+     /* FIXME - This is a privileged operation. If we don't have the privilege we should
+                rather use PROCESS_PRIORITY_CLASS_HIGH. */
+     PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_REALTIME;
+   }
+   else
+   {
+     /* FIXME - what to do in this case? */
+     PriorityClass.PriorityClass = PROCESS_PRIORITY_CLASS_NORMAL;
+   }
+
+   /*
     * Create a new process
     */
    Status = NtCreateProcess(&hProcess,
 			    PROCESS_ALL_ACCESS,
-			    NULL,
+			    &ProcObjectAttributes,
 			    NtCurrentProcess(),
 			    bInheritHandles,
 			    hSection,
 			    NULL,
 			    NULL);
+   /* FIXME - handle failure!!!!! */
+   
+   Status = NtSetInformationProcess(hProcess,
+                                    ProcessPriorityClass,
+                                    &PriorityClass,
+                                    sizeof(PROCESS_PRIORITY_CLASS));
+   /* FIXME - handle failure!!!!! */
+   
    if (lpStartupInfo)
    {
       if (lpStartupInfo->lpReserved2)
@@ -1069,6 +1118,7 @@
 			 0,
 			 TRUE,
 			 DUPLICATE_SAME_ACCESS);
+      /* FIXME - handle failure!!!!! */
    }
 
    /*
@@ -1079,6 +1129,8 @@
 			   &Sii,
 			   sizeof(Sii),
 			   &i);
+   /* FIXME - handle failure!!!!! */
+   
    /*
     * Close the section
     */
@@ -1316,11 +1368,7 @@
    KlInitPeb(hProcess, Ppb, &ImageBaseAddress, Sii.Subsystem);
 
    RtlDestroyProcessParameters (Ppb);
-
-   Status = NtSetInformationProcess(hProcess,
-				    ProcessImageFileName,
-				    ImageFileName,
-				    8);
+   
    /*
     * Create the thread for the kernel
     */

reactos/lib/ntdll/ldr
startup.c 1.58 -> 1.59
diff -u -r1.58 -r1.59
--- startup.c	5 Oct 2004 10:38:57 -0000	1.58
+++ startup.c	21 Nov 2004 21:09:42 -0000	1.59
@@ -1,4 +1,4 @@
-/* $Id: startup.c,v 1.58 2004/10/05 10:38:57 ekohl Exp $
+/* $Id: startup.c,v 1.59 2004/11/21 21:09:42 weiden Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -263,7 +263,7 @@
            PEDosHeader->e_lfanew == 0L ||
            *(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_PE_MAGIC)
          {
-           DbgPrint("Image has bad header\n");
+           DPRINT1("Image has bad header\n");
            ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
          }
 
@@ -289,7 +289,7 @@
                                         NULL);
        if (Peb->ProcessHeap == 0)
          {
-           DbgPrint("Failed to create process heap\n");
+           DPRINT1("Failed to create process heap\n");
            ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
          }
 
@@ -322,7 +322,7 @@
                                                   sizeof(PEB_LDR_DATA));
        if (Peb->Ldr == NULL)
          {
-           DbgPrint("Failed to create loader data\n");
+           DPRINT1("Failed to create loader data\n");
            ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
          }
        Peb->Ldr->Length = sizeof(PEB_LDR_DATA);
@@ -348,7 +348,7 @@
                                                 sizeof(LDR_MODULE));
        if (NtModule == NULL)
          {
-           DbgPrint("Failed to create loader module entry (NTDLL)\n");
+           DPRINT1("Failed to create loader module entry (NTDLL)\n");
            ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
 	 }
        memset(NtModule, 0, sizeof(LDR_MODULE));
@@ -387,7 +387,7 @@
                                                  sizeof(LDR_MODULE));
        if (ExeModule == NULL)
          {
-           DbgPrint("Failed to create loader module infomation\n");
+           DPRINT1("Failed to create loader module infomation\n");
            ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
          }
        ExeModule->BaseAddress = Peb->ImageBaseAddress;
@@ -395,7 +395,7 @@
        if ((Peb->ProcessParameters == NULL) ||
            (Peb->ProcessParameters->ImagePathName.Length == 0))
          {
-           DbgPrint("Failed to access the process parameter block\n");
+           DPRINT1("Failed to access the process parameter block\n");
            ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
          }
 
@@ -438,7 +438,7 @@
        /* Check before returning that we can run the image safely. */
        if (EntryPoint == NULL)
          {
-           DbgPrint("Failed to initialize image\n");
+           DPRINT1("Failed to initialize image\n");
            ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
          }
      }

reactos/lib/ntdll/rtl
process.c 1.36 -> 1.37
diff -u -r1.36 -r1.37
--- process.c	19 Nov 2004 01:30:35 -0000	1.36
+++ process.c	21 Nov 2004 21:09:42 -0000	1.37
@@ -1,4 +1,4 @@
-/* $Id: process.c,v 1.36 2004/11/19 01:30:35 weiden Exp $
+/* $Id: process.c,v 1.37 2004/11/21 21:09:42 weiden Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS system libraries
@@ -49,19 +49,16 @@
 }
 
 static NTSTATUS
-RtlpMapFile(PRTL_USER_PROCESS_PARAMETERS Ppb,
+RtlpMapFile(PUNICODE_STRING ImageFileName,
+            PRTL_USER_PROCESS_PARAMETERS Ppb,
 	    ULONG Attributes,
-	    PHANDLE Section,
-	    PCHAR ImageFileName)
+	    PHANDLE Section)
 {
    HANDLE hFile;
    IO_STATUS_BLOCK IoStatusBlock;
    OBJECT_ATTRIBUTES ObjectAttributes;
    PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
    NTSTATUS Status;
-   PWCHAR s;
-   PWCHAR e;
-   ULONG i;
    
    hFile = NULL;
 
@@ -70,7 +67,7 @@
 //   DbgPrint("ImagePathName %x\n", Ppb->ImagePathName.Buffer);
    
    InitializeObjectAttributes(&ObjectAttributes,
-			      &(Ppb->ImagePathName),
+			      ImageFileName,
 			      Attributes & (OBJ_CASE_INSENSITIVE | OBJ_INHERIT),
 			      NULL,
 			      SecurityDescriptor);
@@ -78,34 +75,6 @@
    RtlNormalizeProcessParams (Ppb);
    
    /*
-    * 
-    */
-//   DbgPrint("ImagePathName %x\n", Ppb->ImagePathName.Buffer);
-//   DbgPrint("ImagePathName %S\n", Ppb->ImagePathName.Buffer);
-   s = wcsrchr(Ppb->ImagePathName.Buffer, '\\');
-   if (s == NULL)
-     {
-	s = Ppb->ImagePathName.Buffer;
-     }
-   else
-     {
-	s++;
-     }
-   e = wcschr(s, '.');
-   if (e != NULL)
-     {
-	*e = 0;
-     }
-   for (i = 0; i < 8; i++)
-     {
-	ImageFileName[i] = (CHAR)(s[i]);
-     }
-   if (e != NULL)
-     {
-	*e = '.';
-     }
-   
-   /*
     * Try to open the executable
     */
 
@@ -264,17 +233,16 @@
    NTSTATUS Status;
    PROCESS_BASIC_INFORMATION ProcessBasicInfo;
    ULONG retlen;
-   CHAR FileName[8];
    SECTION_IMAGE_INFORMATION Sii;
    ULONG ResultLength;
    PVOID ImageBaseAddress;
    
    DPRINT("RtlCreateUserProcess\n");
    
-   Status = RtlpMapFile(ProcessParameters,
+   Status = RtlpMapFile(ImageFileName,
+                        ProcessParameters,
 			Attributes,
-			&hSection,
-			FileName);
+			&hSection);
    if( !NT_SUCCESS( Status ) )
      return Status;
 
@@ -309,11 +277,6 @@
    DPRINT("ProcessBasicInfo.UniqueProcessId %d\n",
 	  ProcessBasicInfo.UniqueProcessId);
    ProcessInfo->ClientId.UniqueProcess = (HANDLE)ProcessBasicInfo.UniqueProcessId;
-			  
-   Status = NtSetInformationProcess(ProcessInfo->ProcessHandle,
-				    ProcessImageFileName,
-				    FileName,
-				    8);
 
    /*
     * Create Process Environment Block
@@ -342,13 +305,15 @@
 				  ImageBaseAddress + (ULONG)Sii.EntryPoint,
 				  &ProcessInfo->ClientId,
 				  &ProcessInfo->ThreadHandle);
+
+   NtClose(hSection);
+   
    if (!NT_SUCCESS(Status))
    {
 	DPRINT("Failed to create thread\n");
-	NtClose(hSection);
 	return(Status);
    }
-   NtClose(hSection);
+
    return(STATUS_SUCCESS);
 }
 

reactos/ntoskrnl/ldr
init.c 1.48 -> 1.49
diff -u -r1.48 -r1.49
--- init.c	24 Oct 2004 20:37:26 -0000	1.48
+++ init.c	21 Nov 2004 21:09:42 -0000	1.49
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: init.c,v 1.48 2004/10/24 20:37:26 weiden Exp $
+/* $Id: init.c,v 1.49 2004/11/21 21:09:42 weiden Exp $
  *
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/ldr/init.c
@@ -146,7 +146,7 @@
   RtlCopyMemory(LocalPpb->ImagePathName.Buffer,
 		ImagePath->Buffer,
 		ImagePath->Length);
-  LocalPpb->ImagePathName.Buffer[ImagePath->Length / sizeof(WCHAR)] = (WCHAR)0;
+  LocalPpb->ImagePathName.Buffer[ImagePath->Length / sizeof(WCHAR)] = L'\0';
 
   /* Denormalize the process parameter block */
   DENORMALIZE(LocalPpb->ImagePathName.Buffer, LocalPpb);
@@ -195,17 +195,6 @@
 		      &RegionSize,
 		      MEM_RELEASE);
 
-  /* Set image file name */
-  Status = NtSetInformationProcess(ProcessHandle,
-				   ProcessImageFileName,
-				   "SMSS",
-				   5);
-  if (!NT_SUCCESS(Status))
-    {
-      DPRINT("NtSetInformationProcess() failed (Status %lx)\n", Status);
-      return(Status);
-    }
-
   /* Read image base address. */
   Offset = FIELD_OFFSET(PEB, ImageBaseAddress);
   NtReadVirtualMemory(ProcessHandle,

reactos/ntoskrnl/ps
process.c 1.155 -> 1.156
diff -u -r1.155 -r1.156
--- process.c	21 Nov 2004 13:18:19 -0000	1.155
+++ process.c	21 Nov 2004 21:09:43 -0000	1.156
@@ -1,4 +1,4 @@
-/* $Id: process.c,v 1.155 2004/11/21 13:18:19 weiden Exp $
+/* $Id: process.c,v 1.156 2004/11/21 21:09:43 weiden Exp $
  *
  * COPYRIGHT:         See COPYING in the top level directory
  * PROJECT:           ReactOS kernel
@@ -849,6 +849,65 @@
 	KEBUGCHECK(0);
      }
 
+   if (SectionHandle != NULL)
+     {
+        PSECTION_OBJECT SectionObject;
+        UNICODE_STRING FileName;
+        PWCHAR szSrc;
+        PCHAR szDest;
+        USHORT lnFName = 0;
+        
+        /*
+         * Determine the image file name and save it to the EPROCESS structure
+         */
+        Status = ObReferenceObjectByHandle(SectionHandle,
+                                           0,
+                                           MmSectionObjectType,
+                                           UserMode,
+                                           (PVOID*)&SectionObject,
+                                           NULL);
+	if (!NT_SUCCESS(Status))
+	  {
+	     DbgPrint("Failed to reference section object\n", Status);
+	     ObDereferenceObject(Process);
+	     ObDereferenceObject(pParentProcess);
+	     return(Status);
+	  }
+
+        FileName = SectionObject->FileObject->FileName;
+        szSrc = (PWCHAR)(FileName.Buffer + FileName.Length - 1);
+        while(szSrc >= FileName.Buffer)
+        {
+          if(*szSrc == L'\\')
+          {
+            szSrc++;
+            break;
+          }
+          else
+          {
+            szSrc--;
+            lnFName++;
+          }
+        }
+        
+        /* copy the image file name to the process and truncate it to 15 characters
+           if necessary */
+        szDest = Process->ImageFileName;
+        lnFName = min(lnFName, sizeof(Process->ImageFileName) - 1);
+        while(lnFName-- > 0)
+        {
+          *(szDest++) = (UCHAR)*(szSrc++);
+        }
+        *szDest = '\0';
+        
+
+        ObDereferenceObject(SectionObject);
+     }
+   else
+     {
+        Process->ImageFileName[0] = '\0';
+     }
+
    /*
     * Map ntdll
     */
@@ -867,7 +926,7 @@
     */
    if (SectionHandle != NULL)
      {
-	DPRINT("Mapping process image\n");
+        DPRINT("Mapping process image\n");
 	Status = LdrpMapImage(*ProcessHandle,
 			      SectionHandle,
 			      &ImageBase);
@@ -1255,6 +1314,34 @@
 	}
 	break;
 
+      case ProcessImageFileName:
+      {
+        /*
+         * We DO NOT return the file name stored in the EPROCESS structure.
+         * Propably if we can't find a PEB or ProcessParameters structure for the
+         * process!
+         */
+        PRTL_USER_PROCESS_PARAMETERS ProcParams;
+        ASSERT(Process->Peb);
+        ASSERT(Process->Peb->ProcessParameters);
+        ProcParams = Process->Peb->ProcessParameters;
+        if(ProcessInformationLength < sizeof(UNICODE_STRING) + ProcParams->ImagePathName.Length + sizeof(WCHAR))
+        {
+          Status = STATUS_INFO_LENGTH_MISMATCH;
+        }
+        else
+        {
+          PUNICODE_STRING DstPath = (PUNICODE_STRING)ProcessInformation;
+          DstPath->Length = ProcParams->ImagePathName.Length;
+          DstPath->MaximumLength = DstPath->Length + sizeof(WCHAR);
+          DstPath->Buffer = (PWSTR)(DstPath + 1);
+          
+          RtlCopyMemory(DstPath->Buffer, ProcParams->ImagePathName.Buffer, ProcParams->ImagePathName.Length);
+          DstPath->Buffer[DstPath->Length / sizeof(WCHAR)] = L'\0';
+        }
+        break;
+      }
+
       /*
        * Note: The following 10 information classes are verified to not be
        * implemented on NT, and do indeed return STATUS_INVALID_INFO_CLASS;
@@ -1343,11 +1430,6 @@
 	Status = PspAssignPrimaryToken(Process, *ProcessAccessTokenP);
 	break;
 	
-      case ProcessImageFileName:
-	memcpy(Process->ImageFileName, ProcessInformation, 8);
-	Status = STATUS_SUCCESS;
-	break;
-	
       case ProcessLdtInformation:
       case ProcessLdtSize:
       case ProcessDefaultHardErrorMode:
CVSspam 0.2.8