[NTOS] Fix 64 bit issues

This commit is contained in:
Timo Kreuzer 2018-01-29 20:31:07 +01:00
parent 6dcf3c29e0
commit ff7cc6f37e
7 changed files with 38 additions and 36 deletions

View file

@ -1589,7 +1589,7 @@ Phase1InitializationDiscard(IN PVOID Context)
sizeof(InitBuffer->VersionBuffer), sizeof(InitBuffer->VersionBuffer),
NT_SUCCESS(MsgStatus) ? NT_SUCCESS(MsgStatus) ?
(PCHAR)MsgEntry->Text : (PCHAR)MsgEntry->Text :
"%u System Processor [%u MB Memory] %Z\r\n", "%u System Processor [%Iu MB Memory] %Z\r\n",
KeNumberProcessors, KeNumberProcessors,
Size, Size,
&TempString); &TempString);

View file

@ -258,8 +258,6 @@ MI_MAKE_SUBSECTION_PTE(
_Out_ PMMPTE NewPte, _Out_ PMMPTE NewPte,
_In_ PVOID Segment) _In_ PVOID Segment)
{ {
ULONG_PTR Offset;
/* Mark this as a prototype */ /* Mark this as a prototype */
NewPte->u.Long = 0; NewPte->u.Long = 0;
NewPte->u.Subsect.Prototype = 1; NewPte->u.Subsect.Prototype = 1;

View file

@ -1478,5 +1478,8 @@ XIPInit(
#define InterlockedCompareExchangeUL(Destination, Exchange, Comperand) \ #define InterlockedCompareExchangeUL(Destination, Exchange, Comperand) \
(ULONG)InterlockedCompareExchange((PLONG)(Destination), (LONG)(Exchange), (LONG)(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) \ #define ExfInterlockedCompareExchange64UL(Destination, Exchange, Comperand) \
(ULONGLONG)ExfInterlockedCompareExchange64((PLONGLONG)(Destination), (PLONGLONG)(Exchange), (PLONGLONG)(Comperand)) (ULONGLONG)ExfInterlockedCompareExchange64((PLONGLONG)(Destination), (PLONGLONG)(Exchange), (PLONGLONG)(Comperand))

View file

@ -118,7 +118,7 @@ ObpReferenceProcessObjectByHandle(IN HANDLE Handle,
/* Reference ourselves */ /* Reference ourselves */
ObjectHeader = OBJECT_TO_OBJECT_HEADER(Process); ObjectHeader = OBJECT_TO_OBJECT_HEADER(Process);
InterlockedIncrement(&ObjectHeader->PointerCount); InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
/* Return the pointer */ /* Return the pointer */
*Object = Process; *Object = Process;
@ -135,7 +135,7 @@ ObpReferenceProcessObjectByHandle(IN HANDLE Handle,
/* Reference ourselves */ /* Reference ourselves */
ObjectHeader = OBJECT_TO_OBJECT_HEADER(Thread); ObjectHeader = OBJECT_TO_OBJECT_HEADER(Thread);
InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1); InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
/* No audit mask */ /* No audit mask */
*AuditMask = 0; *AuditMask = 0;
@ -188,7 +188,7 @@ ObpReferenceProcessObjectByHandle(IN HANDLE Handle,
*Object = &ObjectHeader->Body; *Object = &ObjectHeader->Body;
/* Add a reference */ /* Add a reference */
InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1); InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
/* Unlock the handle */ /* Unlock the handle */
ExUnlockHandleTableEntry(HandleTable, HandleEntry); ExUnlockHandleTableEntry(HandleTable, HandleEntry);
@ -556,7 +556,7 @@ ObpDecrementHandleCount(IN PVOID ObjectBody,
ProcessHandleCount = 0; ProcessHandleCount = 0;
/* Decrement the handle count */ /* 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 */ /* Check if we're out of handles and this was an exclusive object */
if (!(NewCount) && (ObjectHeader->Flags & OB_FLAG_EXCLUSIVE)) if (!(NewCount) && (ObjectHeader->Flags & OB_FLAG_EXCLUSIVE))
@ -964,7 +964,7 @@ ObpIncrementHandleCount(IN PVOID Object,
} }
/* Increase the handle count */ /* Increase the handle count */
InterlockedIncrement(&ObjectHeader->HandleCount); InterlockedIncrementSizeT(&ObjectHeader->HandleCount);
ProcessHandleCount = 0; ProcessHandleCount = 0;
/* Check if we have a handle database */ /* Check if we have a handle database */
@ -1191,7 +1191,7 @@ ObpIncrementUnnamedHandleCount(IN PVOID Object,
} }
/* Increase the handle count */ /* Increase the handle count */
InterlockedIncrement(&ObjectHeader->HandleCount); InterlockedIncrementSizeT(&ObjectHeader->HandleCount);
ProcessHandleCount = 0; ProcessHandleCount = 0;
/* Check if we have a handle database */ /* Check if we have a handle database */
@ -1386,8 +1386,8 @@ ObpCreateUnnamedHandle(IN PVOID Object,
if (AdditionalReferences) if (AdditionalReferences)
{ {
/* Add them to the header */ /* Add them to the header */
InterlockedExchangeAdd(&ObjectHeader->PointerCount, InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount,
AdditionalReferences); AdditionalReferences);
} }
/* Save the access mask */ /* Save the access mask */
@ -1437,8 +1437,8 @@ ObpCreateUnnamedHandle(IN PVOID Object,
if (AdditionalReferences) if (AdditionalReferences)
{ {
/* Dereference it as many times as required */ /* Dereference it as many times as required */
InterlockedExchangeAdd(&ObjectHeader->PointerCount, InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount,
-(LONG)AdditionalReferences); -(LONG)AdditionalReferences);
} }
/* Decrement the handle count and detach */ /* Decrement the handle count and detach */
@ -1603,7 +1603,8 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason,
if (AdditionalReferences) if (AdditionalReferences)
{ {
/* Add them to the header */ /* Add them to the header */
InterlockedExchangeAdd(&ObjectHeader->PointerCount, AdditionalReferences); InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount,
AdditionalReferences);
} }
/* Now we can release the object */ /* Now we can release the object */
@ -1692,8 +1693,8 @@ ObpCreateHandle(IN OB_OPEN_REASON OpenReason,
if (AdditionalReferences > 1) if (AdditionalReferences > 1)
{ {
/* Dereference it many times */ /* Dereference it many times */
InterlockedExchangeAdd(&ObjectHeader->PointerCount, InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount,
-(LONG)(AdditionalReferences - 1)); -(LONG)(AdditionalReferences - 1));
} }
/* Dereference the object one last time */ /* Dereference the object one last time */
@ -1972,7 +1973,7 @@ ObpDuplicateHandleCallback(IN PEPROCESS Process,
ObjectHeader = ObpGetHandleObject(HandleTableEntry); ObjectHeader = ObpGetHandleObject(HandleTableEntry);
/* Increment the pointer count */ /* Increment the pointer count */
InterlockedIncrement(&ObjectHeader->PointerCount); InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
/* Release the handle lock */ /* Release the handle lock */
ExUnlockHandleTableEntry(HandleTable, OldEntry); ExUnlockHandleTableEntry(HandleTable, OldEntry);

View file

@ -834,7 +834,7 @@ ReparseObject:
Directory = NULL; Directory = NULL;
/* Increment the pointer count */ /* Increment the pointer count */
InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1); InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount, 1);
/* Cleanup from the first lookup */ /* Cleanup from the first lookup */
ObpReleaseLookupContext(LookupContext); ObpReleaseLookupContext(LookupContext);

View file

@ -24,7 +24,7 @@ FASTCALL
ObReferenceObjectSafe(IN PVOID Object) ObReferenceObjectSafe(IN PVOID Object)
{ {
POBJECT_HEADER ObjectHeader; POBJECT_HEADER ObjectHeader;
LONG OldValue, NewValue; LONG_PTR OldValue, NewValue;
/* Get the object header */ /* Get the object header */
ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object); ObjectHeader = OBJECT_TO_OBJECT_HEADER(Object);
@ -37,9 +37,9 @@ ObReferenceObjectSafe(IN PVOID Object)
do do
{ {
/* Increase the reference count */ /* Increase the reference count */
NewValue = InterlockedCompareExchange(&ObjectHeader->PointerCount, NewValue = InterlockedCompareExchangeSizeT(&ObjectHeader->PointerCount,
OldValue + 1, OldValue + 1,
OldValue); OldValue);
if (OldValue == NewValue) return TRUE; if (OldValue == NewValue) return TRUE;
/* Keep looping */ /* Keep looping */
@ -80,9 +80,9 @@ ObReferenceObjectEx(IN PVOID Object,
IN LONG Count) IN LONG Count)
{ {
/* Increment the reference count and return the count now */ /* Increment the reference count and return the count now */
return InterlockedExchangeAdd(&OBJECT_TO_OBJECT_HEADER(Object)-> return InterlockedExchangeAddSizeT(&OBJECT_TO_OBJECT_HEADER(Object)->
PointerCount, PointerCount,
Count) + Count; Count) + Count;
} }
LONG LONG
@ -91,13 +91,13 @@ ObDereferenceObjectEx(IN PVOID Object,
IN LONG Count) IN LONG Count)
{ {
POBJECT_HEADER Header; POBJECT_HEADER Header;
LONG NewCount; LONG_PTR NewCount;
/* Extract the object header */ /* Extract the object header */
Header = OBJECT_TO_OBJECT_HEADER(Object); Header = OBJECT_TO_OBJECT_HEADER(Object);
/* Check whether the object can now be deleted. */ /* Check whether the object can now be deleted. */
NewCount = InterlockedExchangeAdd(&Header->PointerCount, -Count) - Count; NewCount = InterlockedExchangeAddSizeT(&Header->PointerCount, -Count) - Count;
if (!NewCount) ObpDeferObjectDeletion(Header); if (!NewCount) ObpDeferObjectDeletion(Header);
/* Return the current count */ /* Return the current count */
@ -274,7 +274,7 @@ ObReferenceFileObjectForWrite(IN HANDLE Handle,
/* FIXME: Audit access if required */ /* FIXME: Audit access if required */
/* Reference the object directly since we have its header */ /* Reference the object directly since we have its header */
InterlockedIncrement(&ObjectHeader->PointerCount); InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
/* Unlock the handle */ /* Unlock the handle */
ExUnlockHandleTableEntry(HandleTable, HandleEntry); ExUnlockHandleTableEntry(HandleTable, HandleEntry);
@ -312,7 +312,7 @@ ObfReferenceObject(IN PVOID Object)
ASSERT(Object); ASSERT(Object);
/* Get the header and increment the reference count */ /* 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 LONG_PTR
@ -332,7 +332,7 @@ ObfDereferenceObject(IN PVOID Object)
} }
/* Check whether the object can now be deleted. */ /* Check whether the object can now be deleted. */
OldCount = InterlockedDecrement(&Header->PointerCount); OldCount = InterlockedDecrementSizeT(&Header->PointerCount);
if (!OldCount) if (!OldCount)
{ {
/* Sanity check */ /* Sanity check */
@ -362,7 +362,7 @@ ObDereferenceObjectDeferDelete(IN PVOID Object)
POBJECT_HEADER Header = OBJECT_TO_OBJECT_HEADER(Object); POBJECT_HEADER Header = OBJECT_TO_OBJECT_HEADER(Object);
/* Check whether the object can now be deleted. */ /* Check whether the object can now be deleted. */
if (!InterlockedDecrement(&Header->PointerCount)) if (!InterlockedDecrementSizeT(&Header->PointerCount))
{ {
/* Add us to the deferred deletion list */ /* Add us to the deferred deletion list */
ObpDeferObjectDeletion(Header); ObpDeferObjectDeletion(Header);
@ -402,7 +402,7 @@ ObReferenceObjectByPointer(IN PVOID Object,
} }
/* Increment the reference count and return success */ /* Increment the reference count and return success */
InterlockedIncrement(&Header->PointerCount); InterlockedIncrementSizeT(&Header->PointerCount);
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -543,7 +543,7 @@ ObReferenceObjectByHandle(IN HANDLE Handle,
/* Reference ourselves */ /* Reference ourselves */
ObjectHeader = OBJECT_TO_OBJECT_HEADER(CurrentProcess); ObjectHeader = OBJECT_TO_OBJECT_HEADER(CurrentProcess);
InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1); InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount, 1);
/* Return the pointer */ /* Return the pointer */
*Object = CurrentProcess; *Object = CurrentProcess;
@ -591,7 +591,7 @@ ObReferenceObjectByHandle(IN HANDLE Handle,
/* Reference ourselves */ /* Reference ourselves */
ObjectHeader = OBJECT_TO_OBJECT_HEADER(CurrentThread); ObjectHeader = OBJECT_TO_OBJECT_HEADER(CurrentThread);
InterlockedExchangeAdd(&ObjectHeader->PointerCount, 1); InterlockedExchangeAddSizeT(&ObjectHeader->PointerCount, 1);
/* Return the pointer */ /* Return the pointer */
*Object = CurrentThread; *Object = CurrentThread;
@ -654,7 +654,7 @@ ObReferenceObjectByHandle(IN HANDLE Handle,
!(~GrantedAccess & DesiredAccess)) !(~GrantedAccess & DesiredAccess))
{ {
/* Reference the object directly since we have its header */ /* Reference the object directly since we have its header */
InterlockedIncrement(&ObjectHeader->PointerCount); InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
/* Mask out the internal attributes */ /* Mask out the internal attributes */
Attributes = HandleEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES; Attributes = HandleEntry->ObAttributes & OBJ_HANDLE_ATTRIBUTES;

View file

@ -201,7 +201,7 @@ NtWaitForMultipleObjects(IN ULONG ObjectCount,
if (IsPointerOffset(DefaultObject)) if (IsPointerOffset(DefaultObject))
{ {
/* Increase reference count */ /* Increase reference count */
InterlockedIncrement(&ObjectHeader->PointerCount); InterlockedIncrementSizeT(&ObjectHeader->PointerCount);
ReferencedObjects++; ReferencedObjects++;
/* Save the Object and Wait Object, this is a relative offset */ /* Save the Object and Wait Object, this is a relative offset */