- Hack around the system start up Dll Initialization Bug for GdiHandleTable.

svn path=/trunk/; revision=41191
This commit is contained in:
James Tabor 2009-05-29 07:13:43 +00:00
parent add725ffb4
commit 9fdb3933ab

View file

@ -124,47 +124,43 @@ BOOL GdiIsHandleValid(HGDIOBJ hGdiObj)
BOOL GdiGetHandleUserData(HGDIOBJ hGdiObj, DWORD ObjectType, PVOID *UserData) BOOL GdiGetHandleUserData(HGDIOBJ hGdiObj, DWORD ObjectType, PVOID *UserData)
{ {
if ( GdiHandleTable ) if ( !GdiHandleTable )
{ {
PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj); // FIXME HAX!! Due to the "Dll Initialization Bug" set the local handle table pointer.
if((Entry->Type & GDI_ENTRY_BASETYPE_MASK) == ObjectType && GdiHandleTable = NtCurrentTeb()->ProcessEnvironmentBlock->GdiSharedHandleTable;
( (Entry->Type << GDI_ENTRY_UPPER_SHIFT) & GDI_HANDLE_TYPE_MASK ) == }
GDI_HANDLE_GET_TYPE(hGdiObj)) PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX(hGdiObj);
{ if((Entry->Type & GDI_ENTRY_BASETYPE_MASK) == ObjectType &&
HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1); ( (Entry->Type << GDI_ENTRY_UPPER_SHIFT) & GDI_HANDLE_TYPE_MASK ) ==
if(pid == NULL || pid == CurrentProcessId) GDI_HANDLE_GET_TYPE(hGdiObj))
{ {
// HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
// Need to test if we have Read & Write access to the VM address space. if(pid == NULL || pid == CurrentProcessId)
// {
BOOL Result = TRUE; //
if(Entry->UserData) // Need to test if we have Read & Write access to the VM address space.
//
BOOL Result = TRUE;
if(Entry->UserData)
{
volatile CHAR *Current = (volatile CHAR*)Entry->UserData;
_SEH2_TRY
{ {
volatile CHAR *Current = (volatile CHAR*)Entry->UserData; *Current = *Current;
_SEH2_TRY
{
*Current = *Current;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Result = FALSE;
}
_SEH2_END
} }
else _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
Result = FALSE; // Can not be zero. {
if (Result) *UserData = Entry->UserData; Result = FALSE;
return Result; }
} _SEH2_END
} }
SetLastError(ERROR_INVALID_PARAMETER); else
return FALSE; Result = FALSE; // Can not be zero.
} if (Result) *UserData = Entry->UserData;
else return Result;
{ }
DPRINT1("!GGHUD: Warning System Initialization Error!!!! GdiHandleTable == 0x%x !!!\n",GdiHandleTable);
*UserData = NULL;
} }
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
} }
@ -172,43 +168,40 @@ PLDC
FASTCALL FASTCALL
GdiGetLDC(HDC hDC) GdiGetLDC(HDC hDC)
{ {
if ( GdiHandleTable ) if ( !GdiHandleTable )
{ {
PDC_ATTR Dc_Attr; // FIXME HAX!! Due to the "Dll Initialization Bug" set the local handle table pointer.
PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX((HGDIOBJ) hDC); GdiHandleTable = NtCurrentTeb()->ProcessEnvironmentBlock->GdiSharedHandleTable;
HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
// Don't check the mask, just the object type.
if ( Entry->ObjectType == GDIObjType_DC_TYPE &&
(pid == NULL || pid == CurrentProcessId) )
{
BOOL Result = TRUE;
if (Entry->UserData)
{
volatile CHAR *Current = (volatile CHAR*)Entry->UserData;
_SEH2_TRY
{
*Current = *Current;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Result = FALSE;
}
_SEH2_END
}
else
Result = FALSE;
if (Result)
{
Dc_Attr = (PDC_ATTR)Entry->UserData;
return Dc_Attr->pvLDC;
}
}
return NULL;
} }
else PDC_ATTR Dc_Attr;
PGDI_TABLE_ENTRY Entry = GdiHandleTable + GDI_HANDLE_GET_INDEX((HGDIOBJ) hDC);
HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
// Don't check the mask, just the object type.
if ( Entry->ObjectType == GDIObjType_DC_TYPE &&
(pid == NULL || pid == CurrentProcessId) )
{ {
DPRINT1("!LDC: Warning System Initialization Error!!!! GdiHandleTable == 0x%x !!!\n",GdiHandleTable); BOOL Result = TRUE;
if (Entry->UserData)
{
volatile CHAR *Current = (volatile CHAR*)Entry->UserData;
_SEH2_TRY
{
*Current = *Current;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
Result = FALSE;
}
_SEH2_END
}
else
Result = FALSE;
if (Result)
{
Dc_Attr = (PDC_ATTR)Entry->UserData;
return Dc_Attr->pvLDC;
}
} }
return NULL; return NULL;
} }