Skip to content

Commit eaeb6f6

Browse files
kswiecickiAlexeySachkov
authored andcommitted
[UR][OpenCL] Remove redundant library loading on Windows (#19816)
Loading library on Windows using default search order is insecure. Since OpenCL is already linked with the adapter, we just need to retrieve the library handle.
1 parent 9b91d42 commit eaeb6f6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

unified-runtime/source/adapters/opencl/adapter.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@ static ur_adapter_handle_t liveAdapter = nullptr;
2626
ur_adapter_handle_t_::ur_adapter_handle_t_() : handle_base() {
2727
#ifdef _MSC_VER
2828

29-
// Loading OpenCL.dll increments the libraries internal reference count.
30-
auto handle = LoadLibraryA("OpenCL.dll");
29+
// Retrieving handle of an already linked OpenCL.dll library doesn't increase
30+
// the reference count.
31+
auto handle = GetModuleHandleA("OpenCL.dll");
32+
assert(handle);
3133

3234
#define CL_CORE_FUNCTION(FUNC) \
3335
FUNC = reinterpret_cast<decltype(::FUNC) *>(GetProcAddress(handle, #FUNC));
3436
#include "core_functions.def"
3537
#undef CL_CORE_FUNCTION
36-
37-
// So we can safely decrement it here wihtout actually unloading OpenCL.dll.
38-
FreeLibrary(handle);
39-
4038
#else // _MSC_VER
4139

4240
// Use the default shared object search order (RTLD_DEFAULT) since the

0 commit comments

Comments
 (0)