[NTOS] Fix 64 bit issues
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 29 Jan 2018 19:31:07 +0000 (20:31 +0100)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 4 Aug 2018 17:19:34 +0000 (19:19 +0200)
ntoskrnl/ex/init.c
ntoskrnl/include/internal/amd64/mm.h
ntoskrnl/include/internal/ex.h
ntoskrnl/ob/obhandle.c
ntoskrnl/ob/obname.c
ntoskrnl/ob/obref.c
ntoskrnl/ob/obwait.c

index e241334..826cc3b 100644 (file)
@@ -1589,7 +1589,7 @@ Phase1InitializationDiscard(IN PVOID Context)
                                 sizeof(InitBuffer->VersionBuffer),
                                 NT_SUCCESS(MsgStatus) ?
                                 (PCHAR)MsgEntry->Text :
-                                "%u System Processor [%u MB Memory] %Z\r\n",
+                                "%u System Processor [%Iu MB Memory] %Z\r\n",
                                 KeNumberProcessors,
                                 Size,
                                 &TempString);
index 7d339a1..f788094 100644 (file)
@@ -258,8 +258,6 @@ MI_MAKE_SUBSECTION_PTE(
     _Out_ PMMPTE NewPte,
     _In_ PVOID Segment)
 {
-    ULONG_PTR Offset;
-
     /* Mark this as a prototype */
     NewPte->u.Long = 0;
     NewPte->u.Subsect.Prototype = 1;
index 740bb96..a8e715a 100644 (file)
@@ -1478,5 +1478,8 @@ XIPInit(
 #define InterlockedCompareExchangeUL(Destination, Exchange, Comperand) \
    (ULONG)InterlockedCompareExchange((PLONG)(Destination), (LONG)(Exchange), (LONG)(Comperand))
 
+#define InterlockedCompareExchangeSizeT(Destination, Exchange, Comperand) \
+   (SIZE_T)InterlockedCompareExchangePointer((PVOID*)(Destination), (PVOID)(SIZE_T)(Exchange), (PVOID)(SIZE_T)(Comperand))
+
 #define ExfInterlockedCompareExchange64UL(Destination, Exchange, Comperand) \
    (ULONGLONG)ExfInterlockedCompareExchange64((PLONGLONG)(Destination), (PLONGLONG)(Exchange), (PLONGLONG)(Comperand))
index 58e7ba3..d753a68 100644 (file)
@@ -118,7 +118,7 @@ ObpReferenceProcessObjectByHandle(IN HANDLE Handle,
 
             /* Reference ourselves */
             ObjectHeader = OBJECT_TO_OBJECT_HEADER(Process);
-            InterlockedIncrement(&ObjectHeader->PointerCount);
+            InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
 
             /* Return the pointer */
             *Object = Process;
@@ -135,7 +135,7 @@ ObpReferenceProcessObjectByHandle(IN HANDLE Handle,
 
             /* Reference ourselves */
             ObjectHeader = OBJECT_TO_OBJECT_HEADER(Thread);
-            InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
+            InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
 
             /* No audit mask */
             *AuditMask = 0;
@@ -188,7 +188,7 @@ ObpReferenceProcessObjectByHandle(IN HANDLE Handle,
         *Object = &ObjectHeader->Body;
 
         /* Add a reference */
-        InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
+        InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
 
         /* Unlock the handle */
         ExUnlockHandleTableEntry(HandleTable, HandleEntry);
@@ -556,7 +556,7 @@ ObpDecrementHandleCount(IN PVOID ObjectBody,
     ProcessHandleCount = 0;
 
     /* Decrement the handle count */
-    NewCount = InterlockedDecrement(&ObjectHeader->HandleCount);
+    NewCount = InterlockedDecrementSizeT(&ObjectHeader->HandleCount);
 
     /* Check if we're out of handles and this was an exclusive object */
     if (!(NewCount) && (ObjectHeader->Flags & OB_FLAG_EXCLUSIVE))
@@ -964,7 +964,7 @@ ObpIncrementHandleCount(IN PVOID Object,
     }
 
     /* Increase the handle count */
-    InterlockedIncrement(&ObjectHeader->HandleCount);
+    InterlockedIncrementSizeT(&ObjectHeader->HandleCount);
     ProcessHandleCount = 0;
 
     /* Check if we have a handle database */
@@ -1191,7 +1191,7 @@ ObpIncrementUnnamedHandleCount(IN PVOID Object,
     }
 
     /* Increase the handle count */
-    InterlockedIncrement(&ObjectHeader->HandleCount);
+    InterlockedIncrementSizeT(&ObjectHeader->HandleCount);
     ProcessHandleCount = 0;
 
     /* Check if we have a handle database */
@@ -1386,8 +1386,8 @@ ObpCreateUnnamedHandle(IN PVOID Object,
     if (AdditionalReferences)
     {
         /* Add them to the header */
-        InterlockedExchangeAdd(&ObjectHeader->PointerCount,
-                               AdditionalReferences);
+        InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount,
+                                    AdditionalReferences);
     }
 
     /* Save the access mask */
@@ -1437,8 +1437,8 @@ ObpCreateUnnamedHandle(IN PVOID Object,
     if (AdditionalReferences)
     {
         /* Dereference it as many times as required */
-        InterlockedExchangeAdd(&ObjectHeader->PointerCount,
-                               -(LONG)AdditionalReferences);
+        InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount,
+                                    -(LONG)AdditionalReferences);
     }
 
     /* Decrement the handle count and detach */
@@ -1603,7 +1603,8 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason,
     if (AdditionalReferences)
     {
         /* Add them to the header */
-        InterlockedExchangeAdd(&ObjectHeader->PointerCount, AdditionalReferences);
+        InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount,
+                                    AdditionalReferences);
     }
 
     /* Now we can release the object */
@@ -1692,8 +1693,8 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason,
         if (AdditionalReferences > 1)
         {
             /* Dereference it many times */
-            InterlockedExchangeAdd(&ObjectHeader->PointerCount,
-                                  -(LONG)(AdditionalReferences - 1));
+            InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount,
+                                        -(LONG)(AdditionalReferences - 1));
         }
 
         /* Dereference the object one last time */
@@ -1972,7 +1973,7 @@ ObpDuplicateHandleCallback(IN PEPROCESS Process,
         ObjectHeader = ObpGetHandleObject(HandleTableEntry);
 
         /* Increment the pointer count */
-        InterlockedIncrement(&ObjectHeader->PointerCount);
+        InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
 
         /* Release the handle lock */
         ExUnlockHandleTableEntry(HandleTable, OldEntry);
index 849c791..32e4894 100644 (file)
@@ -834,7 +834,7 @@ ReparseObject:
                 Directory = NULL;
 
                 /* Increment the pointer count */
-                InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
+                InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount, 1);
 
                 /* Cleanup from the first lookup */
                 ObpReleaseLookupContext(LookupContext);
index 2f4da20..d6b29d3 100644 (file)
@@ -24,7 +24,7 @@ FASTCALL
 ObReferenceObjectSafe(IN PVOID Object)
 {
     POBJECT_HEADER ObjectHeader;
-    LONG OldValue, NewValue;
+    LONG_PTR OldValue, NewValue;
 
     /* Get the object header */
     ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
@@ -37,9 +37,9 @@ ObReferenceObjectSafe(IN PVOID Object)
     do
     {
         /* Increase the reference count */
-        NewValue = InterlockedCompareExchange(&ObjectHeader->PointerCount,
-                                              OldValue + 1,
-                                              OldValue);
+        NewValue = InterlockedCompareExchangeSizeT(&ObjectHeader->PointerCount,
+                                                   OldValue + 1,
+                                                   OldValue);
         if (OldValue == NewValue) return TRUE;
 
         /* Keep looping */
@@ -80,9 +80,9 @@ ObReferenceObjectEx(IN PVOID Object,
                     IN LONG Count)
 {
     /* Increment the reference count and return the count now */
-    return InterlockedExchangeAdd(&OBJECT_TO_OBJECT_HEADER(Object)->
-                                  PointerCount,
-                                  Count) + Count;
+    return InterlockedExchangeAddSizeT(&OBJECT_TO_OBJECT_HEADER(Object)->
+                                       PointerCount,
+                                       Count) + Count;
 }
 
 LONG
@@ -91,13 +91,13 @@ ObDereferenceObjectEx(IN PVOID Object,
                       IN LONG Count)
 {
     POBJECT_HEADER Header;
-    LONG NewCount;
+    LONG_PTR NewCount;
 
     /* Extract the object header */
     Header = OBJECT_TO_OBJECT_HEADER(Object);
 
     /* Check whether the object can now be deleted. */
-    NewCount = InterlockedExchangeAdd(&Header->PointerCount, -Count) - Count;
+    NewCount = InterlockedExchangeAddSizeT(&Header->PointerCount, -Count) - Count;
     if (!NewCount) ObpDeferObjectDeletion(Header);
 
     /* Return the current count */
@@ -274,7 +274,7 @@ ObReferenceFileObjectForWrite(IN HANDLE Handle,
                 /* FIXME: Audit access if required */
 
                 /* Reference the object directly since we have its header */
-                InterlockedIncrement(&ObjectHeader->PointerCount);
+                InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
 
                 /* Unlock the handle */
                 ExUnlockHandleTableEntry(HandleTable, HandleEntry);
@@ -312,7 +312,7 @@ ObfReferenceObject(IN PVOID Object)
     ASSERT(Object);
 
     /* Get the header and increment the reference count */
-    return InterlockedIncrement(&OBJECT_TO_OBJECT_HEADER(Object)->PointerCount);
+    return InterlockedIncrementSizeT(&OBJECT_TO_OBJECT_HEADER(Object)->PointerCount);
 }
 
 LONG_PTR
@@ -332,7 +332,7 @@ ObfDereferenceObject(IN PVOID Object)
     }
 
     /* Check whether the object can now be deleted. */
-    OldCount = InterlockedDecrement(&Header->PointerCount);
+    OldCount = InterlockedDecrementSizeT(&Header->PointerCount);
     if (!OldCount)
     {
         /* Sanity check */
@@ -362,7 +362,7 @@ ObDereferenceObjectDeferDelete(IN PVOID Object)
     POBJECT_HEADER Header = OBJECT_TO_OBJECT_HEADER(Object);
 
     /* Check whether the object can now be deleted. */
-    if (!InterlockedDecrement(&Header->PointerCount))
+    if (!InterlockedDecrementSizeT(&Header->PointerCount))
     {
         /* Add us to the deferred deletion list */
         ObpDeferObjectDeletion(Header);
@@ -402,7 +402,7 @@ ObReferenceObjectByPointer(IN PVOID Object,
     }
 
     /* Increment the reference count and return success */
-    InterlockedIncrement(&Header->PointerCount);
+    InterlockedIncrementSizeT(&Header->PointerCount);
     return STATUS_SUCCESS;
 }
 
@@ -543,7 +543,7 @@ ObReferenceObjectByHandle(IN HANDLE Handle,
 
                     /* Reference ourselves */
                     ObjectHeader = OBJECT_TO_OBJECT_HEADER(CurrentProcess);
-                    InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
+                    InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount, 1);
 
                     /* Return the pointer */
                     *Object = CurrentProcess;
@@ -591,7 +591,7 @@ ObReferenceObjectByHandle(IN HANDLE Handle,
 
                     /* Reference ourselves */
                     ObjectHeader = OBJECT_TO_OBJECT_HEADER(CurrentThread);
-                    InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1);
+                    InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount, 1);
 
                     /* Return the pointer */
                     *Object = CurrentThread;
@@ -654,7 +654,7 @@ ObReferenceObjectByHandle(IN HANDLE Handle,
                 !(~GrantedAccess & DesiredAccess))
             {
                 /* Reference the object directly since we have its header */
-                InterlockedIncrement(&ObjectHeader->PointerCount);
+                InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
 
                 /* Mask out the internal attributes */
                 Attributes = HandleEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;
index 99e5a56..ff9cb21 100644 (file)
@@ -201,7 +201,7 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
         if (IsPointerOffset(DefaultObject))
         {
             /* Increase reference count */
-            InterlockedIncrement(&ObjectHeader->PointerCount);
+            InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
             ReferencedObjects++;
 
             /* Save the Object and Wait Object, this is a relative offset */