Skip to content

Commit d7ac3dd

Browse files
committed
[Loader] Supress system errors when loading adapters on Windows.
1 parent 92638b2 commit d7ac3dd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

source/loader/ur_loader.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ namespace ur_loader {
1717
context_t *getContext() { return context_t::get_direct(); }
1818

1919
ur_result_t context_t::init() {
20+
#ifdef _WIN32
21+
// Suppress system errors.
22+
// Tells the system to not display the critical-error-handler message box.
23+
// Instead, the system sends the error to the calling process.
24+
// This is crucial for graceful handling of plugins that couldn't be
25+
// loaded, e.g. due to missing native run-times.
26+
// Sometimes affects L0 or the unified runtime.
27+
// TODO: add reporting in case of an error.
28+
// NOTE: we restore the old mode to not affect user app behavior.
29+
// See https://github.com/intel/llvm/blob/sycl/sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp (preloadLibraries())
30+
UINT SavedMode = SetErrorMode(SEM_FAILCRITICALERRORS);
31+
#endif
32+
2033
#ifdef UR_STATIC_ADAPTER_LEVEL_ZERO
2134
// If the adapters were force loaded, it means the user wants to use
2235
// a specific adapter library. Don't load any static adapters.
@@ -35,6 +48,10 @@ ur_result_t context_t::init() {
3548
}
3649
}
3750
}
51+
#ifdef _WIN32
52+
// Restore system error handling.
53+
(void)SetErrorMode(SavedMode);
54+
#endif
3855

3956
forceIntercept = getenv_tobool("UR_ENABLE_LOADER_INTERCEPT");
4057

0 commit comments

Comments
 (0)