fix: skip cleanup in 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-06-13 15:21:22 +00:00
committed by Compute-Runtime-Automation
parent bf8de245d9
commit 0b5c9125ac
2 changed files with 15 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -13,7 +13,11 @@ using namespace NEO;
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { // NOLINT(readability-identifier-naming)
if (fdwReason == DLL_PROCESS_DETACH) {
globalPlatformTeardown();
/* If lpvReserved is non-NULL with DLL_PROCESS_DETACH, the process is terminating,
* cleanup should be skipped according to the DllMain spec. */
if (!lpvReserved) {
globalPlatformTeardown();
}
}
if (fdwReason == DLL_PROCESS_ATTACH) {
globalPlatformSetup();