Skip to content

Commit ad43e28

Browse files
Merge pull request #2060 from martygrant/martin/supressSystemErrorsOnWindows
[Loader] Suppress system errors when loading adapters on Windows
2 parents fa9ebe7 + 53abe07 commit ad43e28

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

source/loader/ur_loader.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ 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 adapters that couldn't be
25+
// loaded, e.g. due to missing native run-times.
26+
// TODO: add reporting in case of an error.
27+
// NOTE: we restore the old mode to not affect user app behavior.
28+
// See https://github.com/intel/llvm/blob/sycl/sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp (preloadLibraries())
29+
UINT SavedMode = SetErrorMode(SEM_FAILCRITICALERRORS);
30+
#endif
31+
2032
#ifdef UR_STATIC_ADAPTER_LEVEL_ZERO
2133
// If the adapters were force loaded, it means the user wants to use
2234
// a specific adapter library. Don't load any static adapters.
@@ -35,6 +47,10 @@ ur_result_t context_t::init() {
3547
}
3648
}
3749
}
50+
#ifdef _WIN32
51+
// Restore system error handling.
52+
(void)SetErrorMode(SavedMode);
53+
#endif
3854

3955
forceIntercept = getenv_tobool("UR_ENABLE_LOADER_INTERCEPT");
4056

0 commit comments

Comments
 (0)