[KERNEL32]
[reactos.git] / reactos / dll / win32 / kernel32 / client / proc.c
index 0e99abd..6c44e99 100644 (file)
@@ -102,7 +102,7 @@ BuildSubSysCommandLine(IN LPCWSTR SubsystemName,
     /* Allocate buffer for the output string */
     Length = CommandLineString.MaximumLength + ApplicationNameString.MaximumLength + 32;
     Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, Length);
-    RtlInitEmptyUnicodeString(SubsysCommandLine, Buffer, Length);
+    RtlInitEmptyUnicodeString(SubsysCommandLine, Buffer, (USHORT)Length);
     if (!Buffer)
     {
         /* Fail, no memory */
@@ -503,7 +503,7 @@ BasepNotifyCsrOfThread(IN HANDLE ThreadHandle,
     BASE_API_MESSAGE ApiMessage;
     PBASE_CREATE_THREAD CreateThreadRequest = &ApiMessage.Data.CreateThreadRequest;
 
-    DPRINT("BasepNotifyCsrOfThread: Thread: %lx, Handle %lx\n",
+    DPRINT("BasepNotifyCsrOfThread: Thread: %p, Handle %p\n",
             ClientId->UniqueThread, ThreadHandle);
 
     /* Fill out the request */
@@ -629,14 +629,14 @@ BasePushProcessParameters(IN ULONG ParameterFlags,
 
     /* Create the Parameter Block */
     ProcessParameters = NULL;
-    DPRINT1("ImageName: '%wZ'\n", &ImageName);
-    DPRINT1("DllPath  : '%wZ'\n", &DllPath);
-    DPRINT1("CurDir   : '%wZ'\n", &CurrentDirectory);
-    DPRINT1("CmdLine  : '%wZ'\n", &CommandLine);
-    DPRINT1("Title    : '%wZ'\n", &Title);
-    DPRINT1("Desktop  : '%wZ'\n", &Desktop);
-    DPRINT1("Shell    : '%wZ'\n", &Shell);
-    DPRINT1("Runtime  : '%wZ'\n", &Runtime);
+    DPRINT("ImageName: '%wZ'\n", &ImageName);
+    DPRINT("DllPath  : '%wZ'\n", &DllPath);
+    DPRINT("CurDir   : '%wZ'\n", &CurrentDirectory);
+    DPRINT("CmdLine  : '%wZ'\n", &CommandLine);
+    DPRINT("Title    : '%wZ'\n", &Title);
+    DPRINT("Desktop  : '%wZ'\n", &Desktop);
+    DPRINT("Shell    : '%wZ'\n", &Shell);
+    DPRINT("Runtime  : '%wZ'\n", &Runtime);
     Status = RtlCreateProcessParameters(&ProcessParameters,
                                         &ImageName,
                                         &DllPath,
@@ -673,9 +673,8 @@ BasePushProcessParameters(IN ULONG ParameterFlags,
     if (lpEnvironment)
     {
         /* Find the environment size */
-        while ((ScanChar[0]) || (ScanChar[1])) ++ScanChar;
-        ScanChar += (2 * sizeof(UNICODE_NULL));
-        EnviroSize = (ULONG_PTR)ScanChar - (ULONG_PTR)lpEnvironment;
+        while (*ScanChar++) while (*ScanChar++);
+        EnviroSize = (ULONG)((ULONG_PTR)ScanChar - (ULONG_PTR)lpEnvironment);
 
         /* Allocate and Initialize new Environment Block */
         Size = EnviroSize;
@@ -1838,7 +1837,7 @@ GetProcessVersion(IN DWORD ProcessId)
             ProcessHandle = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION,
                                         FALSE,
                                         ProcessId);
-            if (!ProcessHandle) return 0;
+            if (!ProcessHandle) _SEH2_YIELD(return 0);
 
             /* Try to find out where its PEB lives */
             Status = NtQueryInformationProcess(ProcessHandle,
@@ -2295,7 +2294,8 @@ CreateProcessInternalW(IN HANDLE hUserToken,
     SECTION_IMAGE_INFORMATION ImageInformation;
     IO_STATUS_BLOCK IoStatusBlock;
     CLIENT_ID ClientId;
-    ULONG NoWindow, RegionSize, StackSize, ImageMachine, ErrorCode, Flags;
+    ULONG NoWindow, RegionSize, StackSize, ErrorCode, Flags;
+    USHORT ImageMachine;
     ULONG ParameterFlags, PrivilegeValue, HardErrorMode, ErrorResponse;
     ULONG_PTR ErrorParameters[2];
     BOOLEAN InJob, SaferNeeded, UseLargePages, HavePrivilege;
@@ -2377,7 +2377,7 @@ CreateProcessInternalW(IN HANDLE hUserToken,
     ANSI_STRING VdmAnsiEnv;
     UNICODE_STRING VdmString, VdmUnicodeEnv;
     BOOLEAN IsWowApp;
-    PBASE_CHECK_VDM VdmMsg;
+    PBASE_CHECK_VDM CheckVdmMsg;
 
     /* Zero out the initial core variables and handles */
     QuerySection = FALSE;
@@ -2432,7 +2432,7 @@ CreateProcessInternalW(IN HANDLE hUserToken,
 
     /* Set message structures */
     CreateProcessMsg = &CsrMsg.Data.CreateProcessRequest;
-    VdmMsg = &CsrMsg.Data.CheckVDMRequest;
+    CheckVdmMsg = &CsrMsg.Data.CheckVDMRequest;
 
     /* Clear the more complex structures by zeroing out their entire memory */
     RtlZeroMemory(&Context, sizeof(Context));
@@ -2468,7 +2468,7 @@ CreateProcessInternalW(IN HANDLE hUserToken,
     PolicyPathPair.Nt = &SxsNtPolicyPath.String;
 #endif
 
-    DPRINT1("CreateProcessInternalW: %S %S %lx\n", lpApplicationName, lpCommandLine, dwCreationFlags);
+    DPRINT("CreateProcessInternalW: %S %S %lx\n", lpApplicationName, lpCommandLine, dwCreationFlags);
 
     /* Finally, set our TEB and PEB */
     Teb = NtCurrentTeb();
@@ -2576,7 +2576,7 @@ CreateProcessInternalW(IN HANDLE hUserToken,
         }
 
         /* Use the allocated size and convert */
-        UnicodeEnv.MaximumLength = RegionSize;
+        UnicodeEnv.MaximumLength = (USHORT)RegionSize;
         Status = RtlAnsiStringToUnicodeString(&UnicodeEnv, &AnsiEnv, FALSE);
         if (!NT_SUCCESS(Status))
         {
@@ -2710,7 +2710,7 @@ StartScan:
 
         /* Now compute the final EXE path based on the name */
         SearchPath = BaseComputeProcessExePath((LPWSTR)lpApplicationName);
-        DPRINT1("Search Path: %S\n", SearchPath);
+        DPRINT("Search Path: %S\n", SearchPath);
         if (!SearchPath)
         {
             SetLastError(ERROR_NOT_ENOUGH_MEMORY);
@@ -2744,7 +2744,7 @@ StartScan:
             }
         }
 
-        DPRINT1("Length: %lx Buffer: %S\n", Length, NameBuffer);
+        DPRINT("Length: %lu Buffer: %S\n", Length, NameBuffer);
 
         /* Check if there was a failure in SearchPathW */
         if ((Length) && (Length < MAX_PATH))
@@ -2872,7 +2872,7 @@ StartScan:
         SxsWin32ExePath = PathBufferString;
         PathBuffer = PathBufferString.Buffer;
         PathBufferString.Buffer = NULL;
-        DPRINT1("SxS Path: %S\n", PathBuffer);
+        DPRINT("SxS Path: %S\n", PathBuffer);
     }
 
     /* Also set the .EXE path based on the path name */
@@ -2891,7 +2891,7 @@ StartScan:
     }
 
     /* Now use the path name, and the root path, to try opening the app */
-    DPRINT1("Path: %wZ. Dir: %lx\n", &PathName, SxsWin32RelativePath.ContainingDirectory);
+    DPRINT("Path: %wZ. Dir: %p\n", &PathName, SxsWin32RelativePath.ContainingDirectory);
     InitializeObjectAttributes(&LocalObjectAttributes,
                                &PathName,
                                OBJ_CASE_INSENSITIVE,
@@ -2956,7 +2956,7 @@ StartScan:
                              PAGE_EXECUTE,
                              SEC_IMAGE,
                              FileHandle);
-    DPRINT1("Section status: %lx\n", Status);
+    DPRINT("Section status: %lx\n", Status);
     if (NT_SUCCESS(Status))
     {
         /* Are we running on Windows Embedded, Datacenter, Blade or Starter? */
@@ -3205,7 +3205,7 @@ StartScan:
                                           lpCommandLine,
                                           lpCurrentDirectory,
                                           &VdmAnsiEnv,
-                                          (PCSR_API_MESSAGE)VdmMsg,
+                                          &CsrMsg,
                                           &VdmTask,
                                           dwCreationFlags,
                                           &StartupInfo,
@@ -3231,9 +3231,9 @@ StartScan:
                 }
 
                 /* Check which VDM state we're currently in */
-                switch (VdmMsg->VDMState & (VDM_NOT_LOADED |
-                                            VDM_NOT_READY |
-                                            VDM_READY))
+                switch (CheckVdmMsg->VDMState & (VDM_NOT_LOADED |
+                                                 VDM_NOT_READY |
+                                                 VDM_READY))
                 {
                     case VDM_NOT_LOADED:
                         /* VDM is not fully loaded, so not that much to undo */
@@ -3273,7 +3273,7 @@ StartScan:
                         VdmUndoLevel = VDM_UNDO_REUSE;
 
                         /* Check if CSRSS wants us to wait on VDM */
-                        VdmWaitObject = VdmMsg->WaitObjectForParent;
+                        VdmWaitObject = CheckVdmMsg->WaitObjectForParent;
                         break;
 
                     case VDM_NOT_READY:
@@ -3342,7 +3342,7 @@ StartScan:
                                       lpCommandLine,
                                       lpCurrentDirectory,
                                       &VdmAnsiEnv,
-                                      (PCSR_API_MESSAGE)VdmMsg,
+                                      &CsrMsg,
                                       &VdmTask,
                                       dwCreationFlags,
                                       &StartupInfo,
@@ -3357,9 +3357,9 @@ StartScan:
                 };
 
                 /* Handle possible VDM states */
-                switch (VdmMsg->VDMState & (VDM_NOT_LOADED |
-                                            VDM_NOT_READY |
-                                            VDM_READY))
+                switch (CheckVdmMsg->VDMState & (VDM_NOT_LOADED |
+                                                 VDM_NOT_READY |
+                                                 VDM_READY))
                 {
                     case VDM_NOT_LOADED:
                         /* If VDM is not loaded, we'll do a partial undo */
@@ -3396,7 +3396,7 @@ StartScan:
                         VdmUndoLevel = VDM_UNDO_REUSE;
 
                         /* Check if CSRSS wants us to wait on VDM */
-                        VdmWaitObject = VdmMsg->WaitObjectForParent;
+                        VdmWaitObject = CheckVdmMsg->WaitObjectForParent;
                         break;
 
                     case VDM_NOT_READY:
@@ -3439,7 +3439,7 @@ StartScan:
                     ((_wcsnicmp(ExtBuffer, L".bat", 4)) &&
                      (_wcsnicmp(ExtBuffer, L".cmd", 4))))
                 {
-                    DPRINT1("Invalid EXE, and not a batch or script file\n");
+                    DPRINT1("'%wZ': Invalid EXE, and not a batch or script file\n", &PathName);
                     SetLastError(ERROR_BAD_EXE_FORMAT);
                     Result = FALSE;
                     goto Quickie;
@@ -3722,7 +3722,7 @@ StartScan:
     if (!Result)
     {
         /* It was not, bail out */
-        DPRINT1("Invalid subsystem version: %d.%d\n",
+        DPRINT1("Invalid subsystem version: %hu.%hu\n",
                 ImageInformation.SubSystemMajorVersion,
                 ImageInformation.SubSystemMinorVersion);
         SetLastError(ERROR_BAD_EXE_FORMAT);
@@ -3761,7 +3761,7 @@ StartScan:
         }
 
         /* Account for the quotes and space between the two */
-        n += ((sizeof('""') * 2) + sizeof(' '));
+        n += sizeof("\" \"") - sizeof(ANSI_NULL);
 
         /* Convert to bytes, and make sure we don't overflow */
         n *= sizeof(WCHAR);
@@ -3784,7 +3784,7 @@ StartScan:
         /* Set the length */
         RtlInitEmptyUnicodeString(&DebuggerString,
                                   DebuggerString.Buffer,
-                                  n);
+                                  (USHORT)n);
 
         /* Now perform the command line creation */
         ImageDbgStatus = RtlAppendUnicodeToString(&DebuggerString,
@@ -3922,7 +3922,7 @@ StartScan:
         RealTimePrivilegeState = NULL;
 
         /* Is realtime priority being requested? */
-        if (PriorityClass.PriorityClass == REALTIME_PRIORITY_CLASS)
+        if (PriorityClass.PriorityClass == PROCESS_PRIORITY_CLASS_REALTIME)
         {
             /* Check if the caller has real-time access, and enable it if so */
             RealTimePrivilegeState = BasepIsRealtimeAllowed(TRUE);
@@ -4253,7 +4253,7 @@ StartScan:
     {
         /* IA32, IA64 and AMD64 are supported in Server 2003 */
         case IMAGE_FILE_MACHINE_I386:
-         CreateProcessMsg->ProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
+            CreateProcessMsg->ProcessorArchitecture = PROCESSOR_ARCHITECTURE_INTEL;
             break;
         case IMAGE_FILE_MACHINE_IA64:
             CreateProcessMsg->ProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64;
@@ -4657,8 +4657,8 @@ CreateProcessInternalA(HANDLE hToken,
     BOOL bRetVal;
     STARTUPINFOW StartupInfo;
 
-    DPRINT("dwCreationFlags %x, lpEnvironment %x, lpCurrentDirectory %x, "
-            "lpStartupInfo %x, lpProcessInformation %x\n",
+    DPRINT("dwCreationFlags %x, lpEnvironment %p, lpCurrentDirectory %p, "
+            "lpStartupInfo %p, lpProcessInformation %p\n",
             dwCreationFlags, lpEnvironment, lpCurrentDirectory,
             lpStartupInfo, lpProcessInformation);