mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 21:52:59 +00:00
[FORMATTING] apply a consistent indentation (4 spaces), no code change
svn path=/trunk/; revision=32553
This commit is contained in:
parent
7f8158f09e
commit
351736138c
1 changed files with 998 additions and 992 deletions
|
@ -153,7 +153,7 @@ GDIOBJ_iAllocHandleTable(OUT PSECTION_OBJECT *SectionObject)
|
|||
HandleTable->LookasideLists = ExAllocatePoolWithTag(NonPagedPool,
|
||||
BASE_OBJTYPE_COUNT * sizeof(PAGED_LOOKASIDE_LIST),
|
||||
TAG_GDIHNDTBLE);
|
||||
if(HandleTable->LookasideLists == NULL)
|
||||
if (HandleTable->LookasideLists == NULL)
|
||||
{
|
||||
MmUnmapViewInSystemSpace(HandleTable);
|
||||
ObDereferenceObject(*SectionObject);
|
||||
|
@ -161,12 +161,17 @@ GDIOBJ_iAllocHandleTable(OUT PSECTION_OBJECT *SectionObject)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
for(ObjType = 0; ObjType < BASE_OBJTYPE_COUNT; ObjType++)
|
||||
for (ObjType = 0; ObjType < BASE_OBJTYPE_COUNT; ObjType++)
|
||||
{
|
||||
if (ObjTypeInfo[ObjType].bUseLookaside)
|
||||
{
|
||||
ExInitializePagedLookasideList(HandleTable->LookasideLists + ObjType, NULL, NULL, 0,
|
||||
ObjTypeInfo[ObjType].ulBodySize, ObjTypeInfo[ObjType].Tag, 0);
|
||||
ExInitializePagedLookasideList(HandleTable->LookasideLists + ObjType,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
ObjTypeInfo[ObjType].ulBodySize,
|
||||
ObjTypeInfo[ObjType].Tag,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,7 +219,7 @@ void IntDumpHandleTable(PGDI_HANDLE_TABLE HandleTable)
|
|||
{
|
||||
int i, n = 0, j, k, J;
|
||||
|
||||
if ( leak_reported )
|
||||
if (leak_reported)
|
||||
{
|
||||
DPRINT1("gdi handle abusers already reported!\n");
|
||||
return;
|
||||
|
@ -224,18 +229,18 @@ void IntDumpHandleTable(PGDI_HANDLE_TABLE HandleTable)
|
|||
DPRINT1("reporting gdi handle abusers:\n");
|
||||
|
||||
/* step through GDI handle table and find out who our culprit is... */
|
||||
for ( i = RESERVE_ENTRIES_COUNT; i < GDI_HANDLE_COUNT; i++ )
|
||||
for (i = RESERVE_ENTRIES_COUNT; i < GDI_HANDLE_COUNT; i++)
|
||||
{
|
||||
for ( j = 0; j < n; j++ )
|
||||
for (j = 0; j < n; j++)
|
||||
{
|
||||
next:
|
||||
J = h[j].idx;
|
||||
for ( k = 0; k < GDI_STACK_LEVELS; k++ )
|
||||
for (k = 0; k < GDI_STACK_LEVELS; k++)
|
||||
{
|
||||
if ( GDIHandleAllocator[i][k]
|
||||
!= GDIHandleAllocator[J][k] )
|
||||
if (GDIHandleAllocator[i][k]
|
||||
!= GDIHandleAllocator[J][k])
|
||||
{
|
||||
if ( ++j == n )
|
||||
if (++j == n)
|
||||
goto done;
|
||||
else
|
||||
goto next;
|
||||
|
@ -244,9 +249,9 @@ next:
|
|||
goto done;
|
||||
}
|
||||
done:
|
||||
if ( j < H )
|
||||
if (j < H)
|
||||
{
|
||||
if ( j == n )
|
||||
if (j == n)
|
||||
{
|
||||
h[j].idx = i;
|
||||
h[j].count = 1;
|
||||
|
@ -257,35 +262,35 @@ done:
|
|||
}
|
||||
}
|
||||
/* bubble sort time! weeeeee!! */
|
||||
for ( i = 0; i < n-1; i++ )
|
||||
for (i = 0; i < n-1; i++)
|
||||
{
|
||||
if ( h[i].count < h[i+1].count )
|
||||
if (h[i].count < h[i+1].count)
|
||||
{
|
||||
struct DbgOpenGDIHandle t;
|
||||
t = h[i+1];
|
||||
h[i+1] = h[i];
|
||||
j = i;
|
||||
while ( j > 0 && h[j-1].count < t.count )
|
||||
while (j > 0 && h[j-1].count < t.count)
|
||||
j--;
|
||||
h[j] = t;
|
||||
}
|
||||
}
|
||||
/* print the worst offenders... */
|
||||
DbgPrint ( "Worst GDI Handle leak offenders (out of %i unique locations):\n", n );
|
||||
for ( i = 0; i < n && h[i].count > 1; i++ )
|
||||
DbgPrint("Worst GDI Handle leak offenders (out of %i unique locations):\n", n);
|
||||
for (i = 0; i < n && h[i].count > 1; i++)
|
||||
{
|
||||
int j;
|
||||
DbgPrint ( " %i allocs: ", h[i].count );
|
||||
for ( j = 0; j < GDI_STACK_LEVELS; j++ )
|
||||
DbgPrint(" %i allocs: ", h[i].count);
|
||||
for (j = 0; j < GDI_STACK_LEVELS; j++)
|
||||
{
|
||||
ULONG Addr = GDIHandleAllocator[h[i].idx][j];
|
||||
if ( !KiRosPrintAddress ( (PVOID)Addr ) )
|
||||
DbgPrint ( "<%X>", Addr );
|
||||
if (!KiRosPrintAddress((PVOID)Addr))
|
||||
DbgPrint("<%X>", Addr);
|
||||
}
|
||||
DbgPrint ( "\n" );
|
||||
DbgPrint("\n");
|
||||
}
|
||||
if ( i < n && h[i].count == 1 )
|
||||
DbgPrint ( "(list terminated - the remaining entries have 1 allocation only)\n" );
|
||||
if (i < n && h[i].count == 1)
|
||||
DbgPrint("(list terminated - the remaining entries have 1 allocation only)\n");
|
||||
}
|
||||
|
||||
ULONG
|
||||
|
@ -430,11 +435,11 @@ INTERNAL_CALL
|
|||
GDIOBJ_ValidateHandle(HGDIOBJ hObj, ULONG ObjectType)
|
||||
{
|
||||
PGDI_TABLE_ENTRY Entry = GDI_HANDLE_GET_ENTRY(GdiHandleTable, hObj);
|
||||
if((((ULONG_PTR)hObj & GDI_HANDLE_TYPE_MASK) == ObjectType) &&
|
||||
if ((((ULONG_PTR)hObj & GDI_HANDLE_TYPE_MASK) == ObjectType) &&
|
||||
(Entry->Type << GDI_ENTRY_UPPER_SHIFT) == GDI_HANDLE_GET_UPPER(hObj))
|
||||
{
|
||||
HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
|
||||
if(pid == NULL || pid == PsGetCurrentProcessId())
|
||||
if (pid == NULL || pid == PsGetCurrentProcessId())
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -467,7 +472,7 @@ GDIOBJ_AllocObj(ULONG ObjectType)
|
|||
W32Process = PsGetCurrentProcessWin32Process();
|
||||
/* HACK HACK HACK: simplest-possible quota implementation - don't allow a process
|
||||
to take too many GDI objects, itself. */
|
||||
if ( W32Process && W32Process->GDIObjects >= 0x2710 )
|
||||
if (W32Process && W32Process->GDIObjects >= 0x2710)
|
||||
return NULL;
|
||||
|
||||
ASSERT(ObjectType != GDI_OBJECT_TYPE_DONTCARE);
|
||||
|
@ -476,7 +481,7 @@ GDIOBJ_AllocObj(ULONG ObjectType)
|
|||
if (ObjTypeInfo[TypeIndex].bUseLookaside)
|
||||
{
|
||||
LookasideList = FindLookasideList(TypeIndex);
|
||||
if(LookasideList != NULL)
|
||||
if (LookasideList != NULL)
|
||||
{
|
||||
newObject = ExAllocateFromPagedLookasideList(LookasideList);
|
||||
}
|
||||
|
@ -487,7 +492,7 @@ GDIOBJ_AllocObj(ULONG ObjectType)
|
|||
ObjTypeInfo[TypeIndex].ulBodySize,
|
||||
ObjTypeInfo[TypeIndex].Tag);
|
||||
}
|
||||
if(newObject != NULL)
|
||||
if (newObject != NULL)
|
||||
{
|
||||
UINT Index;
|
||||
PGDI_TABLE_ENTRY Entry;
|
||||
|
@ -512,7 +517,7 @@ GDIOBJ_AllocObj(ULONG ObjectType)
|
|||
|
||||
LockHandle:
|
||||
PrevProcId = _InterlockedCompareExchangePointer((PVOID*)&Entry->ProcessId, LockedProcessId, 0);
|
||||
if(PrevProcId == NULL)
|
||||
if (PrevProcId == NULL)
|
||||
{
|
||||
HGDIOBJ Handle;
|
||||
|
||||
|
@ -530,7 +535,7 @@ LockHandle:
|
|||
|
||||
GDIDBG_CAPTUREALLOCATOR(Index);
|
||||
|
||||
if(W32Process != NULL)
|
||||
if (W32Process != NULL)
|
||||
{
|
||||
_InterlockedIncrement(&W32Process->GDIObjects);
|
||||
}
|
||||
|
@ -542,7 +547,7 @@ LockHandle:
|
|||
else
|
||||
{
|
||||
#ifdef GDI_DEBUG
|
||||
if(++Attempts > 20)
|
||||
if (++Attempts > 20)
|
||||
{
|
||||
DPRINT1("[%d]Waiting on handle in index 0x%x\n", Attempts, Index);
|
||||
}
|
||||
|
@ -598,7 +603,7 @@ GDIOBJ_FreeObj(HGDIOBJ hObj, DWORD ExpectedType)
|
|||
|
||||
DPRINT("GDIOBJ_FreeObj: hObj: 0x%08x\n", hObj);
|
||||
|
||||
if(GDI_HANDLE_IS_STOCKOBJ(hObj))
|
||||
if (GDI_HANDLE_IS_STOCKOBJ(hObj))
|
||||
{
|
||||
DPRINT1("GDIOBJ_FreeObj() failed, can't delete stock object handle: 0x%x !!!\n", hObj);
|
||||
GDIDBG_TRACECALLER();
|
||||
|
@ -631,9 +636,9 @@ LockHandle:
|
|||
/* lock the object, we must not delete global objects, so don't exchange the locking
|
||||
process ID to zero when attempting to lock a global object... */
|
||||
PrevProcId = _InterlockedCompareExchangePointer((PVOID*)&Entry->ProcessId, LockedProcessId, ProcessId);
|
||||
if(PrevProcId == ProcessId)
|
||||
if (PrevProcId == ProcessId)
|
||||
{
|
||||
if( (Entry->KernelData != NULL) &&
|
||||
if ( (Entry->KernelData != NULL) &&
|
||||
((Entry->Type << GDI_ENTRY_UPPER_SHIFT) == HandleUpper) &&
|
||||
((Entry->Type & GDI_ENTRY_BASETYPE_MASK) == (HandleUpper & GDI_ENTRY_BASETYPE_MASK)) )
|
||||
{
|
||||
|
@ -641,7 +646,7 @@ LockHandle:
|
|||
|
||||
Object = Entry->KernelData;
|
||||
|
||||
if(Object->cExclusiveLock == 0)
|
||||
if (Object->cExclusiveLock == 0)
|
||||
{
|
||||
BOOL Ret;
|
||||
PW32PROCESS W32Process = PsGetCurrentProcessWin32Process();
|
||||
|
@ -655,7 +660,7 @@ LockHandle:
|
|||
/* push this entry to the free list */
|
||||
InterlockedPushFreeEntry(GDI_ENTRY_TO_INDEX(GdiHandleTable, Entry));
|
||||
|
||||
if(W32Process != NULL)
|
||||
if (W32Process != NULL)
|
||||
{
|
||||
_InterlockedDecrement(&W32Process->GDIObjects);
|
||||
}
|
||||
|
@ -668,7 +673,7 @@ LockHandle:
|
|||
if (ObjTypeInfo[TypeIndex].bUseLookaside)
|
||||
{
|
||||
LookasideList = FindLookasideList(TypeIndex);
|
||||
if(LookasideList != NULL)
|
||||
if (LookasideList != NULL)
|
||||
{
|
||||
ExFreeToPagedLookasideList(LookasideList, Object);
|
||||
}
|
||||
|
@ -696,10 +701,10 @@ LockHandle:
|
|||
(void)_InterlockedExchangePointer((PVOID*)&Entry->ProcessId, PrevProcId);
|
||||
}
|
||||
}
|
||||
else if(PrevProcId == LockedProcessId)
|
||||
else if (PrevProcId == LockedProcessId)
|
||||
{
|
||||
#ifdef GDI_DEBUG
|
||||
if(++Attempts > 20)
|
||||
if (++Attempts > 20)
|
||||
{
|
||||
DPRINT1("[%d]Waiting on 0x%x\n", Attempts, hObj);
|
||||
}
|
||||
|
@ -712,9 +717,9 @@ LockHandle:
|
|||
}
|
||||
else
|
||||
{
|
||||
if(!Silent)
|
||||
if (!Silent)
|
||||
{
|
||||
if(((ULONG_PTR)PrevProcId & ~0x1) == 0)
|
||||
if (((ULONG_PTR)PrevProcId & ~0x1) == 0)
|
||||
{
|
||||
DPRINT1("Attempted to free global gdi handle 0x%x, caller needs to get ownership first!!!\n", hObj);
|
||||
DPRINT1("Type = 0x%lx, KernelData = 0x%p, ProcessId = 0x%p\n", Entry->Type, Entry->KernelData, Entry->ProcessId);
|
||||
|
@ -758,7 +763,7 @@ FASTCALL
|
|||
NtGdiDeleteObject(HGDIOBJ hObject)
|
||||
{
|
||||
DPRINT("NtGdiDeleteObject handle 0x%08x\n", hObject);
|
||||
if(!IsObjectDead(hObject))
|
||||
if (!IsObjectDead(hObject))
|
||||
{
|
||||
return NULL != hObject
|
||||
? GDIOBJ_FreeObj(hObject, GDI_OBJECT_TYPE_DONTCARE) : FALSE;
|
||||
|
@ -775,7 +780,7 @@ NtGdiDeleteObject(HGDIOBJ hObject)
|
|||
* \param Process - PID of the process that will be destroyed.
|
||||
*/
|
||||
BOOL INTERNAL_CALL
|
||||
GDI_CleanupForProcess (struct _EPROCESS *Process)
|
||||
GDI_CleanupForProcess(struct _EPROCESS *Process)
|
||||
{
|
||||
PGDI_TABLE_ENTRY Entry, End;
|
||||
PEPROCESS CurrentProcess;
|
||||
|
@ -792,19 +797,20 @@ GDI_CleanupForProcess (struct _EPROCESS *Process)
|
|||
W32Process = (PW32PROCESS)Process->Win32Process;
|
||||
ASSERT(W32Process);
|
||||
|
||||
if(W32Process->GDIObjects > 0)
|
||||
if (W32Process->GDIObjects > 0)
|
||||
{
|
||||
/* FIXME - Instead of building the handle here and delete it using GDIOBJ_FreeObj
|
||||
we should delete it directly here! */
|
||||
ProcId = Process->UniqueProcessId;
|
||||
|
||||
End = &GdiHandleTable->Entries[GDI_HANDLE_COUNT];
|
||||
for(Entry = &GdiHandleTable->Entries[RESERVE_ENTRIES_COUNT];
|
||||
for (Entry = &GdiHandleTable->Entries[RESERVE_ENTRIES_COUNT];
|
||||
Entry != End;
|
||||
Entry++, Index++)
|
||||
{
|
||||
/* ignore the lock bit */
|
||||
if((HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1) == ProcId && (Entry->Type & ~GDI_ENTRY_REUSE_MASK) != 0)
|
||||
if ( (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1) == ProcId &&
|
||||
(Entry->Type & ~GDI_ENTRY_REUSE_MASK) != 0 )
|
||||
{
|
||||
HGDIOBJ ObjectHandle;
|
||||
|
||||
|
@ -814,7 +820,7 @@ GDI_CleanupForProcess (struct _EPROCESS *Process)
|
|||
simply ignore this fact here. */
|
||||
ObjectHandle = (HGDIOBJ)(Index | (Entry->Type << GDI_ENTRY_UPPER_SHIFT));
|
||||
|
||||
if(GDIOBJ_FreeObj(ObjectHandle, GDI_OBJECT_TYPE_DONTCARE) &&
|
||||
if (GDIOBJ_FreeObj(ObjectHandle, GDI_OBJECT_TYPE_DONTCARE) &&
|
||||
W32Process->GDIObjects == 0)
|
||||
{
|
||||
/* there are no more gdi handles for this process, bail */
|
||||
|
@ -845,7 +851,7 @@ GDI_CleanupForProcess (struct _EPROCESS *Process)
|
|||
* \todo Get rid of the ExpectedType parameter!
|
||||
*/
|
||||
PGDIOBJ INTERNAL_CALL
|
||||
GDIOBJ_LockObj (HGDIOBJ hObj, DWORD ExpectedType)
|
||||
GDIOBJ_LockObj(HGDIOBJ hObj, DWORD ExpectedType)
|
||||
{
|
||||
ULONG HandleIndex;
|
||||
PGDI_TABLE_ENTRY Entry;
|
||||
|
@ -983,7 +989,7 @@ GDIOBJ_LockObj (HGDIOBJ hObj, DWORD ExpectedType)
|
|||
* \todo Get rid of the ExpectedType parameter!
|
||||
*/
|
||||
PGDIOBJ INTERNAL_CALL
|
||||
GDIOBJ_ShareLockObj (HGDIOBJ hObj, DWORD ExpectedType)
|
||||
GDIOBJ_ShareLockObj(HGDIOBJ hObj, DWORD ExpectedType)
|
||||
{
|
||||
ULONG HandleIndex;
|
||||
PGDI_TABLE_ENTRY Entry;
|
||||
|
@ -1127,7 +1133,7 @@ GDIOBJ_OwnedByCurrentProcess(HGDIOBJ ObjectHandle)
|
|||
|
||||
DPRINT("GDIOBJ_OwnedByCurrentProcess: ObjectHandle: 0x%08x\n", ObjectHandle);
|
||||
|
||||
if(!GDI_HANDLE_IS_STOCKOBJ(ObjectHandle))
|
||||
if (!GDI_HANDLE_IS_STOCKOBJ(ObjectHandle))
|
||||
{
|
||||
ProcessId = PsGetCurrentProcessId();
|
||||
|
||||
|
@ -1145,7 +1151,7 @@ GDIOBJ_OwnedByCurrentProcess(HGDIOBJ ObjectHandle)
|
|||
BOOL INTERNAL_CALL
|
||||
GDIOBJ_ConvertToStockObj(HGDIOBJ *phObj)
|
||||
{
|
||||
/*
|
||||
/*
|
||||
* FIXME !!!!! THIS FUNCTION NEEDS TO BE FIXED - IT IS NOT SAFE WHEN OTHER THREADS
|
||||
* MIGHT ATTEMPT TO LOCK THE OBJECT DURING THIS CALL!!!
|
||||
*/
|
||||
|
@ -1164,7 +1170,7 @@ GDIOBJ_ConvertToStockObj(HGDIOBJ *phObj)
|
|||
|
||||
Thread = PsGetCurrentThreadWin32Thread();
|
||||
|
||||
if(!GDI_HANDLE_IS_STOCKOBJ(hObj))
|
||||
if (!GDI_HANDLE_IS_STOCKOBJ(hObj))
|
||||
{
|
||||
ProcessId = PsGetCurrentProcessId();
|
||||
LockedProcessId = (HANDLE)((ULONG_PTR)ProcessId | 0x1);
|
||||
|
@ -1174,7 +1180,7 @@ GDIOBJ_ConvertToStockObj(HGDIOBJ *phObj)
|
|||
LockHandle:
|
||||
/* lock the object, we must not convert stock objects, so don't check!!! */
|
||||
PrevProcId = _InterlockedCompareExchangePointer((PVOID*)&Entry->ProcessId, LockedProcessId, ProcessId);
|
||||
if(PrevProcId == ProcessId)
|
||||
if (PrevProcId == ProcessId)
|
||||
{
|
||||
LONG NewType, PrevType, OldType;
|
||||
|
||||
|
@ -1194,7 +1200,7 @@ LockHandle:
|
|||
|
||||
/* Try to exchange the type field - but only if the old (previous type) matches! */
|
||||
PrevType = _InterlockedCompareExchange(&Entry->Type, NewType, OldType);
|
||||
if(PrevType == OldType && Entry->KernelData != NULL)
|
||||
if (PrevType == OldType && Entry->KernelData != NULL)
|
||||
{
|
||||
PW32THREAD PrevThread;
|
||||
POBJ Object;
|
||||
|
@ -1206,10 +1212,10 @@ LockHandle:
|
|||
Object = Entry->KernelData;
|
||||
|
||||
PrevThread = Object->Tid;
|
||||
if(Object->cExclusiveLock == 0 || PrevThread == Thread)
|
||||
if (Object->cExclusiveLock == 0 || PrevThread == Thread)
|
||||
{
|
||||
/* dereference the process' object counter */
|
||||
if(PrevProcId != GDI_GLOBAL_PROCESS)
|
||||
if (PrevProcId != GDI_GLOBAL_PROCESS)
|
||||
{
|
||||
PEPROCESS OldProcess;
|
||||
PW32PROCESS W32Process;
|
||||
|
@ -1217,10 +1223,10 @@ LockHandle:
|
|||
|
||||
/* FIXME */
|
||||
Status = PsLookupProcessByProcessId((HANDLE)((ULONG_PTR)PrevProcId & ~0x1), &OldProcess);
|
||||
if(NT_SUCCESS(Status))
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
W32Process = (PW32PROCESS)OldProcess->Win32Process;
|
||||
if(W32Process != NULL)
|
||||
if (W32Process != NULL)
|
||||
{
|
||||
_InterlockedDecrement(&W32Process->GDIObjects);
|
||||
}
|
||||
|
@ -1240,7 +1246,7 @@ LockHandle:
|
|||
else
|
||||
{
|
||||
#ifdef GDI_DEBUG
|
||||
if(++Attempts > 20)
|
||||
if (++Attempts > 20)
|
||||
{
|
||||
DPRINT1("[%d]Locked by 0x%x (we're 0x%x)\n", Attempts, PrevThread, Thread);
|
||||
}
|
||||
|
@ -1260,10 +1266,10 @@ LockHandle:
|
|||
DPRINT1("OldType = 0x%x, Entry->Type = 0x%x, NewType = 0x%x, Entry->KernelData = 0x%x\n", OldType, Entry->Type, NewType, Entry->KernelData);
|
||||
}
|
||||
}
|
||||
else if(PrevProcId == LockedProcessId)
|
||||
else if (PrevProcId == LockedProcessId)
|
||||
{
|
||||
#ifdef GDI_DEBUG
|
||||
if(++Attempts > 20)
|
||||
if (++Attempts > 20)
|
||||
{
|
||||
DPRINT1("[%d]Waiting on 0x%x\n", Attempts, hObj);
|
||||
}
|
||||
|
@ -1297,7 +1303,7 @@ GDIOBJ_SetOwnership(HGDIOBJ ObjectHandle, PEPROCESS NewOwner)
|
|||
|
||||
Thread = PsGetCurrentThreadWin32Thread();
|
||||
|
||||
if(!GDI_HANDLE_IS_STOCKOBJ(ObjectHandle))
|
||||
if (!GDI_HANDLE_IS_STOCKOBJ(ObjectHandle))
|
||||
{
|
||||
ProcessId = PsGetCurrentProcessId();
|
||||
LockedProcessId = (HANDLE)((ULONG_PTR)ProcessId | 0x1);
|
||||
|
@ -1307,16 +1313,16 @@ GDIOBJ_SetOwnership(HGDIOBJ ObjectHandle, PEPROCESS NewOwner)
|
|||
LockHandle:
|
||||
/* lock the object, we must not convert stock objects, so don't check!!! */
|
||||
PrevProcId = _InterlockedCompareExchangePointer((PVOID*)&Entry->ProcessId, ProcessId, LockedProcessId);
|
||||
if(PrevProcId == ProcessId)
|
||||
if (PrevProcId == ProcessId)
|
||||
{
|
||||
PW32THREAD PrevThread;
|
||||
|
||||
if((Entry->Type & ~GDI_ENTRY_REUSE_MASK) != 0 && Entry->KernelData != NULL)
|
||||
if ((Entry->Type & ~GDI_ENTRY_REUSE_MASK) != 0 && Entry->KernelData != NULL)
|
||||
{
|
||||
POBJ Object = Entry->KernelData;
|
||||
|
||||
PrevThread = Object->Tid;
|
||||
if(Object->cExclusiveLock == 0 || PrevThread == Thread)
|
||||
if (Object->cExclusiveLock == 0 || PrevThread == Thread)
|
||||
{
|
||||
PEPROCESS OldProcess;
|
||||
PW32PROCESS W32Process;
|
||||
|
@ -1324,13 +1330,13 @@ LockHandle:
|
|||
|
||||
/* dereference the process' object counter */
|
||||
/* FIXME */
|
||||
if((ULONG_PTR)PrevProcId & ~0x1)
|
||||
if ((ULONG_PTR)PrevProcId & ~0x1)
|
||||
{
|
||||
Status = PsLookupProcessByProcessId((HANDLE)((ULONG_PTR)PrevProcId & ~0x1), &OldProcess);
|
||||
if(NT_SUCCESS(Status))
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
W32Process = (PW32PROCESS)OldProcess->Win32Process;
|
||||
if(W32Process != NULL)
|
||||
if (W32Process != NULL)
|
||||
{
|
||||
_InterlockedDecrement(&W32Process->GDIObjects);
|
||||
}
|
||||
|
@ -1338,13 +1344,13 @@ LockHandle:
|
|||
}
|
||||
}
|
||||
|
||||
if(NewOwner != NULL)
|
||||
if (NewOwner != NULL)
|
||||
{
|
||||
ProcessId = PsGetProcessId(NewOwner);
|
||||
|
||||
/* Increase the new process' object counter */
|
||||
W32Process = (PW32PROCESS)NewOwner->Win32Process;
|
||||
if(W32Process != NULL)
|
||||
if (W32Process != NULL)
|
||||
{
|
||||
_InterlockedIncrement(&W32Process->GDIObjects);
|
||||
}
|
||||
|
@ -1361,7 +1367,7 @@ LockHandle:
|
|||
else
|
||||
{
|
||||
#ifdef GDI_DEBUG
|
||||
if(++Attempts > 20)
|
||||
if (++Attempts > 20)
|
||||
{
|
||||
DPRINT1("[%d]Locked by 0x%x (we're 0x%x)\n", Attempts, PrevThread, Thread);
|
||||
}
|
||||
|
@ -1384,10 +1390,10 @@ LockHandle:
|
|||
DPRINT1("Entry->Type = 0x%lx, Entry->KernelData = 0x%p\n", Entry->Type, Entry->KernelData);
|
||||
}
|
||||
}
|
||||
else if(PrevProcId == LockedProcessId)
|
||||
else if (PrevProcId == LockedProcessId)
|
||||
{
|
||||
#ifdef GDI_DEBUG
|
||||
if(++Attempts > 20)
|
||||
if (++Attempts > 20)
|
||||
{
|
||||
DPRINT1("[%d]Waiting on 0x%x\n", Attempts, ObjectHandle);
|
||||
}
|
||||
|
@ -1398,14 +1404,14 @@ LockHandle:
|
|||
/* try again */
|
||||
goto LockHandle;
|
||||
}
|
||||
else if(((ULONG_PTR)PrevProcId & ~0x1) == 0)
|
||||
else if (((ULONG_PTR)PrevProcId & ~0x1) == 0)
|
||||
{
|
||||
/* allow changing ownership of global objects */
|
||||
ProcessId = NULL;
|
||||
LockedProcessId = (HANDLE)((ULONG_PTR)ProcessId | 0x1);
|
||||
goto LockHandle;
|
||||
}
|
||||
else if((HANDLE)((ULONG_PTR)PrevProcId & ~0x1) != PsGetCurrentProcessId())
|
||||
else if ((HANDLE)((ULONG_PTR)PrevProcId & ~0x1) != PsGetCurrentProcessId())
|
||||
{
|
||||
DPRINT1("Attempted to change ownership of object 0x%x (pid: 0x%x) from pid 0x%x!!!\n", ObjectHandle, (ULONG_PTR)PrevProcId & ~0x1, PsGetCurrentProcessId());
|
||||
}
|
||||
|
@ -1430,7 +1436,7 @@ GDIOBJ_CopyOwnership(HGDIOBJ CopyFrom, HGDIOBJ CopyTo)
|
|||
|
||||
Thread = PsGetCurrentThreadWin32Thread();
|
||||
|
||||
if(!GDI_HANDLE_IS_STOCKOBJ(CopyFrom) && !GDI_HANDLE_IS_STOCKOBJ(CopyTo))
|
||||
if (!GDI_HANDLE_IS_STOCKOBJ(CopyFrom) && !GDI_HANDLE_IS_STOCKOBJ(CopyTo))
|
||||
{
|
||||
FromEntry = GDI_HANDLE_GET_ENTRY(GdiHandleTable, CopyFrom);
|
||||
|
||||
|
@ -1440,27 +1446,27 @@ GDIOBJ_CopyOwnership(HGDIOBJ CopyFrom, HGDIOBJ CopyTo)
|
|||
LockHandleFrom:
|
||||
/* lock the object, we must not convert stock objects, so don't check!!! */
|
||||
FromPrevProcId = _InterlockedCompareExchangePointer((PVOID*)&FromEntry->ProcessId, FromProcessId, FromLockedProcessId);
|
||||
if(FromPrevProcId == FromProcessId)
|
||||
if (FromPrevProcId == FromProcessId)
|
||||
{
|
||||
PW32THREAD PrevThread;
|
||||
POBJ Object;
|
||||
|
||||
if((FromEntry->Type & ~GDI_ENTRY_REUSE_MASK) != 0 && FromEntry->KernelData != NULL)
|
||||
if ((FromEntry->Type & ~GDI_ENTRY_REUSE_MASK) != 0 && FromEntry->KernelData != NULL)
|
||||
{
|
||||
Object = FromEntry->KernelData;
|
||||
|
||||
/* save the pointer to the calling thread so we know it was this thread
|
||||
that locked the object */
|
||||
PrevThread = Object->Tid;
|
||||
if(Object->cExclusiveLock == 0 || PrevThread == Thread)
|
||||
if (Object->cExclusiveLock == 0 || PrevThread == Thread)
|
||||
{
|
||||
/* now let's change the ownership of the target object */
|
||||
|
||||
if(((ULONG_PTR)FromPrevProcId & ~0x1) != 0)
|
||||
if (((ULONG_PTR)FromPrevProcId & ~0x1) != 0)
|
||||
{
|
||||
PEPROCESS ProcessTo;
|
||||
/* FIXME */
|
||||
if(NT_SUCCESS(PsLookupProcessByProcessId((HANDLE)((ULONG_PTR)FromPrevProcId & ~0x1), &ProcessTo)))
|
||||
if (NT_SUCCESS(PsLookupProcessByProcessId((HANDLE)((ULONG_PTR)FromPrevProcId & ~0x1), &ProcessTo)))
|
||||
{
|
||||
GDIOBJ_SetOwnership(CopyTo, ProcessTo);
|
||||
ObDereferenceObject(ProcessTo);
|
||||
|
@ -1477,7 +1483,7 @@ LockHandleFrom:
|
|||
else
|
||||
{
|
||||
#ifdef GDI_DEBUG
|
||||
if(++Attempts > 20)
|
||||
if (++Attempts > 20)
|
||||
{
|
||||
DPRINT1("[%d]Locked by 0x%x (we're 0x%x)\n", Attempts, PrevThread, Thread);
|
||||
}
|
||||
|
@ -1499,10 +1505,10 @@ LockHandleFrom:
|
|||
DPRINT1("Attempted to copy ownership from an object 0x%x currently being destroyed!!!\n", CopyFrom);
|
||||
}
|
||||
}
|
||||
else if(FromPrevProcId == FromLockedProcessId)
|
||||
else if (FromPrevProcId == FromLockedProcessId)
|
||||
{
|
||||
#ifdef GDI_DEBUG
|
||||
if(++Attempts > 20)
|
||||
if (++Attempts > 20)
|
||||
{
|
||||
DPRINT1("[%d]Waiting on 0x%x\n", Attempts, CopyFrom);
|
||||
}
|
||||
|
@ -1513,7 +1519,7 @@ LockHandleFrom:
|
|||
/* try again */
|
||||
goto LockHandleFrom;
|
||||
}
|
||||
else if((HANDLE)((ULONG_PTR)FromPrevProcId & ~0x1) != PsGetCurrentProcessId())
|
||||
else if ((HANDLE)((ULONG_PTR)FromPrevProcId & ~0x1) != PsGetCurrentProcessId())
|
||||
{
|
||||
/* FIXME - should we really allow copying ownership from objects that we don't even own? */
|
||||
DPRINT1("WARNING! Changing copying ownership of object 0x%x (pid: 0x%x) to pid 0x%x!!!\n", CopyFrom, (ULONG_PTR)FromPrevProcId & ~0x1, PsGetCurrentProcessId());
|
||||
|
@ -1563,7 +1569,7 @@ HANDLE
|
|||
APIENTRY
|
||||
NtGdiCreateClientObj(
|
||||
IN ULONG ulType
|
||||
)
|
||||
)
|
||||
{
|
||||
// ATM we use DC object for KernelData. I think it should be at a minimum GDIOBJEMPTYHDR.
|
||||
// The UserData is set in user mode, so it is always NULL.
|
||||
|
@ -1588,7 +1594,7 @@ BOOL
|
|||
APIENTRY
|
||||
NtGdiDeleteClientObj(
|
||||
IN HANDLE h
|
||||
)
|
||||
)
|
||||
{
|
||||
return GDIOBJ_FreeObj(h, GDI_OBJECT_TYPE_CLIOBJ);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue