From d7ac3ddbe95dc941da3553bd448c9d5f2e5ac075 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Thu, 5 Sep 2024 17:35:54 +0100 Subject: [PATCH] [Loader] Supress system errors when loading adapters on Windows. --- source/loader/ur_loader.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/loader/ur_loader.cpp b/source/loader/ur_loader.cpp index f2b43f2725..97fd0019a1 100644 --- a/source/loader/ur_loader.cpp +++ b/source/loader/ur_loader.cpp @@ -17,6 +17,19 @@ namespace ur_loader { context_t *getContext() { return context_t::get_direct(); } ur_result_t context_t::init() { +#ifdef _WIN32 + // Suppress system errors. + // Tells the system to not display the critical-error-handler message box. + // Instead, the system sends the error to the calling process. + // This is crucial for graceful handling of plugins that couldn't be + // loaded, e.g. due to missing native run-times. + // Sometimes affects L0 or the unified runtime. + // TODO: add reporting in case of an error. + // NOTE: we restore the old mode to not affect user app behavior. + // See https://github.com/intel/llvm/blob/sycl/sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp (preloadLibraries()) + UINT SavedMode = SetErrorMode(SEM_FAILCRITICALERRORS); +#endif + #ifdef UR_STATIC_ADAPTER_LEVEL_ZERO // If the adapters were force loaded, it means the user wants to use // a specific adapter library. Don't load any static adapters. @@ -35,6 +48,10 @@ ur_result_t context_t::init() { } } } +#ifdef _WIN32 + // Restore system error handling. + (void)SetErrorMode(SavedMode); +#endif forceIntercept = getenv_tobool("UR_ENABLE_LOADER_INTERCEPT");