[SHSVCS] Don't call UnregisterWait from within the wait callback.

Doing this causes deadlocks, the process runs out of worker threads and
the system runs out of memory by allocating too many I/O completion ports
when using ntdll.dll from Windows.
This commit is contained in:
Thomas Faber 2020-04-15 12:09:49 +02:00
parent c58d7a6df6
commit 5a5ba1ad10
No known key found for this signature in database
GPG key ID: 076E7C3D44720826

View file

@ -76,7 +76,6 @@ CALLBACK
ThemeStopCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
{
CloseHandle(hServiceProcess);
UnregisterWait(hThemeStopWaitObject);
UnregisterWait(hThemeServiceWaitObject);
ThemeWatchForStart();
@ -92,7 +91,10 @@ ThemeServiceDiedCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
ResetEvent(hStartEvent);
ResetEvent(hStopEvent);
ThemeStopCallback(lpParameter, TimerOrWaitFired);
CloseHandle(hServiceProcess);
UnregisterWait(hThemeStopWaitObject);
ThemeWatchForStart();
ThemeHooksRemove();
}
static
@ -100,12 +102,10 @@ VOID
CALLBACK
ThemeStartCallback(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
{
UnregisterWait(hThemeStartWaitObject);
hServiceProcess = GetThemeServiceProcessHandle();
RegisterWaitForSingleObject(&hThemeStopWaitObject, hStopEvent, ThemeStopCallback, NULL, INFINITE, WT_EXECUTEDEFAULT);
RegisterWaitForSingleObject(&hThemeServiceWaitObject, hServiceProcess, ThemeServiceDiedCallback, NULL, INFINITE, WT_EXECUTEDEFAULT);
RegisterWaitForSingleObject(&hThemeStopWaitObject, hStopEvent, ThemeStopCallback, NULL, INFINITE, WT_EXECUTEONLYONCE);
RegisterWaitForSingleObject(&hThemeServiceWaitObject, hServiceProcess, ThemeServiceDiedCallback, NULL, INFINITE, WT_EXECUTEONLYONCE);
ThemeHooksInstall();
}
@ -117,7 +117,7 @@ ThemeWatchForStart(VOID)
hStartEvent = CreateEventW(NULL, TRUE, FALSE, L"Global\\ThemeStartEvent");
hStopEvent = CreateEventW(NULL, TRUE, FALSE, L"Global\\ThemeStopEvent");
RegisterWaitForSingleObject(&hThemeStartWaitObject, hStartEvent, ThemeStartCallback, NULL, INFINITE, WT_EXECUTEDEFAULT);
RegisterWaitForSingleObject(&hThemeStartWaitObject, hStartEvent, ThemeStartCallback, NULL, INFINITE, WT_EXECUTEONLYONCE);
return TRUE;
}