[NTGDI][FREETYPE] Unload font engine on system shut-down (#6955)

Check system integrity by explicitly
releasing the font engine.
JIRA issue: CORE-9616
- Use RTL_STATIC_LIST_HEAD against
  g_FontListHead and
  g_FontCacheListHead variables and
  omit initialization of them.
- Implement FreeFontSupport function.
- Call FreeFontSupport in win32k!
  DriverUnload function.
- Fix some usages of
  CONTAINING_RECORD macro.
This commit is contained in:
Katayama Hirofumi MZ 2024-05-29 09:41:39 +09:00 committed by GitHub
parent 817f89466d
commit a541a468ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 9 deletions

View file

@ -78,7 +78,7 @@ static UNICODE_STRING g_FontRegPath =
to serialize access to it */
static PFAST_MUTEX g_FreeTypeLock;
static LIST_ENTRY g_FontListHead;
static RTL_STATIC_LIST_HEAD(g_FontListHead);
static PFAST_MUTEX g_FontListLock;
static BOOL g_RenderingEnabled = TRUE;
@ -105,7 +105,7 @@ static BOOL g_RenderingEnabled = TRUE;
#define MAX_FONT_CACHE 256
static LIST_ENTRY g_FontCacheListHead;
static RTL_STATIC_LIST_HEAD(g_FontCacheListHead);
static UINT g_FontCacheNumEntries;
static PWCHAR g_ElfScripts[32] = /* These are in the order of the fsCsb[0] bits */
@ -476,9 +476,7 @@ VOID DumpFontSubstList(VOID)
pListEntry != pHead;
pListEntry = pListEntry->Flink)
{
pSubstEntry =
(PFONTSUBST_ENTRY)CONTAINING_RECORD(pListEntry, FONT_ENTRY, ListEntry);
pSubstEntry = CONTAINING_RECORD(pListEntry, FONTSUBST_ENTRY, ListEntry);
DumpFontSubstEntry(pSubstEntry);
}
}
@ -673,8 +671,6 @@ InitFontSupport(VOID)
{
ULONG ulError;
InitializeListHead(&g_FontListHead);
InitializeListHead(&g_FontCacheListHead);
g_FontCacheNumEntries = 0;
/* Fast Mutexes must be allocated from non paged pool */
g_FontListLock = ExAllocatePoolWithTag(NonPagedPool, sizeof(FAST_MUTEX), TAG_INTERNAL_SYNC);
@ -715,6 +711,58 @@ InitFontSupport(VOID)
return TRUE;
}
VOID FASTCALL
FreeFontSupport(VOID)
{
PLIST_ENTRY pHead, pEntry;
PFONT_CACHE_ENTRY pFontCache;
PFONTSUBST_ENTRY pSubstEntry;
PFONT_ENTRY pFontEntry;
IntLockGlobalFonts();
// Free font cache list
pHead = &g_FontCacheListHead;
while (!IsListEmpty(pHead))
{
pEntry = RemoveHeadList(pHead);
pFontCache = CONTAINING_RECORD(pEntry, FONT_CACHE_ENTRY, ListEntry);
RemoveCachedEntry(pFontCache);
}
// Free font subst list
pHead = &g_FontSubstListHead;
while (!IsListEmpty(pHead))
{
pEntry = RemoveHeadList(pHead);
pSubstEntry = CONTAINING_RECORD(pEntry, FONTSUBST_ENTRY, ListEntry);
ExFreePoolWithTag(pSubstEntry, TAG_FONT);
}
// Free font list
pHead = &g_FontListHead;
while (!IsListEmpty(pHead))
{
pEntry = RemoveHeadList(pHead);
pFontEntry = CONTAINING_RECORD(pEntry, FONT_ENTRY, ListEntry);
CleanupFontEntry(pFontEntry);
}
if (g_FreeTypeLibrary)
{
FT_Done_Library(g_FreeTypeLibrary);
g_FreeTypeLibrary = NULL;
}
IntUnLockGlobalFonts();
ExFreePoolWithTag(g_FontListLock, TAG_INTERNAL_SYNC);
g_FontListLock = NULL;
ExFreePoolWithTag(g_FreeTypeLock, TAG_INTERNAL_SYNC);
g_FreeTypeLock = NULL;
}
static LONG IntNormalizeAngle(LONG nTenthsOfDegrees)
{
nTenthsOfDegrees %= 360 * 10;
@ -783,8 +831,7 @@ SubstituteFontByList(PLIST_ENTRY pHead,
pListEntry != pHead;
pListEntry = pListEntry->Flink)
{
pSubstEntry =
(PFONTSUBST_ENTRY)CONTAINING_RECORD(pListEntry, FONT_ENTRY, ListEntry);
pSubstEntry = CONTAINING_RECORD(pListEntry, FONTSUBST_ENTRY, ListEntry);
CharSets[FONTSUBST_FROM] = pSubstEntry->CharSets[FONTSUBST_FROM];

View file

@ -110,6 +110,7 @@ NTSTATUS FASTCALL TextIntRealizeFont(HFONT,PTEXTOBJ);
NTSTATUS FASTCALL TextIntCreateFontIndirect(CONST LPLOGFONTW lf, HFONT *NewFont);
BYTE FASTCALL IntCharSetFromCodePage(UINT uCodePage);
BOOL FASTCALL InitFontSupport(VOID);
VOID FASTCALL FreeFontSupport(VOID);
BOOL FASTCALL IntIsFontRenderingEnabled(VOID);
BOOL FASTCALL IntIsFontRenderingEnabled(VOID);
VOID FASTCALL IntEnableFontRendering(BOOL Enable);

View file

@ -908,6 +908,7 @@ DriverUnload(IN PDRIVER_OBJECT DriverObject)
{
// TODO: Do more cleanup!
FreeFontSupport();
ResetCsrApiPort();
ResetCsrProcess();
}