preliminary comment out the self-modifying code for RtlPrefetchMemoryNonTemporal
[reactos.git] / reactos / ntoskrnl / ob / wait.c
index 105f282..0943abf 100644 (file)
@@ -38,7 +38,6 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
     POBJECT_HEADER ObjectHeader;
     PHANDLE_TABLE HandleTable;
     ACCESS_MASK GrantedAccess;
-    LONG ExHandle;
     PVOID DefaultObject;
     NTSTATUS Status = STATUS_SUCCESS;
 
@@ -76,12 +75,8 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
             
             if(TimeOut)
             {
-                ProbeForRead(TimeOut,
-                             sizeof(LARGE_INTEGER),
-                             sizeof(ULONG));
-
                 /* Make a local copy of the timeout on the stack */
-                SafeTimeOut = *TimeOut;
+                SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
                 TimeOut = &SafeTimeOut;
             }
         }
@@ -120,17 +115,16 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
         {
             /* Use the System Handle Table and decode */
             HandleTable = ObpKernelHandleTable;
-            ExHandle = HANDLE_TO_EX_HANDLE(ObKernelHandleToHandle(Handles[i]));
+            Handles[i] = ObKernelHandleToHandle(Handles[i]);
         }
         else
         {
             /* Use the Process' Handle table and get the Ex Handle */
             HandleTable = PsGetCurrentProcess()->ObjectTable;
-            ExHandle = HANDLE_TO_EX_HANDLE(Handles[i]);
         }
 
         /* Get a pointer to it */
-        if (!(HandleEntry = ExMapHandleToPointer(HandleTable, ExHandle)))
+        if (!(HandleEntry = ExMapHandleToPointer(HandleTable, Handles[i])))
         {
             DPRINT1("Invalid handle\n");
             Status = STATUS_INVALID_HANDLE;
@@ -155,7 +149,7 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
         DefaultObject = ObjectHeader->Type->DefaultObject;
 
         /* Check if it's the internal offset */
-        if ((LONG_PTR)DefaultObject >= 0)
+        if (IsPointerOffset(DefaultObject))
         {
             /* Increase reference count */
             InterlockedIncrement(&ObjectHeader->PointerCount);
@@ -184,11 +178,14 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
     /* For a Waitall, we can't have the same object more then once */
     if (WaitType == WaitAll)
     {
+        /* Clear the main loop variable */
+        i = 0;
+
         /* Start the loop */
         do
         {
             /* Check the current and forward object */
-            for (i = 0, j = i + 1; j < ObjectCount; j++)
+            for (j = i + 1; j < ObjectCount; j++)
             {
                 /* Make sure they don't match */
                 if (WaitObjects[i] == WaitObjects[j])
@@ -246,6 +243,7 @@ Quickie:
     if (LockInUse) KeLeaveCriticalRegion();
 
     /* Return status */
+    DPRINT("Returning: %x\n", Status);
     return Status;
 }
 
@@ -271,11 +269,8 @@ NtWaitForSingleObject(IN HANDLE ObjectHandle,
     {
         _SEH_TRY
         {
-            ProbeForRead(TimeOut,
-                         sizeof(LARGE_INTEGER),
-                         sizeof(ULONG));
             /* Make a copy on the stack */
-            SafeTimeOut = *TimeOut;
+            SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
             TimeOut = &SafeTimeOut;
         }
         _SEH_HANDLE
@@ -300,7 +295,7 @@ NtWaitForSingleObject(IN HANDLE ObjectHandle,
         WaitableObject = BODY_TO_HEADER(Object)->Type->DefaultObject;
 
         /* Is it an offset for internal objects? */
-        if ((LONG_PTR)WaitableObject >= 0)
+        if (IsPointerOffset(WaitableObject))
         {
             /* Turn it into a pointer */
             WaitableObject = (PVOID)((ULONG_PTR)Object +
@@ -352,11 +347,8 @@ NtSignalAndWaitForSingleObject(IN HANDLE ObjectHandleToSignal,
     {
         _SEH_TRY
         {
-            ProbeForRead(TimeOut,
-                         sizeof(LARGE_INTEGER),
-                         sizeof(ULONG));
             /* Make a copy on the stack */
-            SafeTimeOut = *TimeOut;
+            SafeTimeOut = ProbeForReadLargeInteger(TimeOut);
             TimeOut = &SafeTimeOut;
         }
         _SEH_HANDLE
@@ -397,7 +389,7 @@ NtSignalAndWaitForSingleObject(IN HANDLE ObjectHandleToSignal,
     WaitableObject = BODY_TO_HEADER(WaitObj)->Type->DefaultObject;
 
     /* Handle internal offset */
-    if ((LONG_PTR)WaitableObject >= 0)
+    if (IsPointerOffset(WaitableObject))
     {
         /* Get real pointer */
         WaitableObject = (PVOID)((ULONG_PTR)WaitObj +