fix: skip cleanup in L0 DllMain when terminating process

Per https://learn.microsoft.com/en-us/windows/win32/dlls/dllmain,
it's not safe to cleanup resources in DllMain when
fdwReason == DLL_PROCESS_DETACH and lpvReserved != NULL (the process is
terminating), e.g. can result in a hang in some cases.

Related-To: NEO-14121

Signed-off-by: Oskar Hubert Weber <oskar.hubert.weber@intel.com>
This commit is contained in:
Oskar Hubert Weber
2025-07-01 16:53:11 +00:00
committed by Compute-Runtime-Automation
parent e4681ddafa
commit b70c7fd078

View File

@@ -17,10 +17,14 @@ BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
L0::globalDriverSetup();
}
if (fdwReason == DLL_PROCESS_DETACH) {
L0::globalDriverTeardown();
if (L0::globalOsSysmanDriver != nullptr) {
delete L0::globalOsSysmanDriver;
L0::globalOsSysmanDriver = nullptr;
/* If lpvReserved is non-NULL with DLL_PROCESS_DETACH, the process is terminating,
* cleanup should be skipped according to the DllMain spec. */
if (!lpvReserved) {
L0::globalDriverTeardown();
if (L0::globalOsSysmanDriver != nullptr) {
delete L0::globalOsSysmanDriver;
L0::globalOsSysmanDriver = nullptr;
}
}
}
return TRUE;