forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Don't use legacy ANSI-only Windows API for loading plugins (in…
…tel#10943) Currently to load PI plugins we use legacy ANSI-only versions of Windows API like GetModuleFileNameA, PathRemoveFileSpecA etc. Problem is that if path containing PI plugins has any non-ANSI symbols then PI plugins are not found and not loaded. In this patch get rid of legacy API calls, for example, use GetModuleFileName instead of GetModuleFileNameA. GetModuleFileName is an alias which automatically selects the ANSI or Unicode version of this function. Another difference is that GetModuleFileName and other similar aliases work with wchar_t to be able to handle unicode on Windows (in contrast to legacy GetModuleFileNameA which works with char_t). So, use std::filesystem:path to work with library paths for convenience (instead of storing path in std::string or std::wstring) because it allows to handle paths without caring about format, can be constructed from string/wstring/.. and can be converted to string/wstring ... DPCPP is supported on some linux systems where default compiler is gcc 7.5 which doesn't provide `<filesystem>` support. On Windows, minimal supported version of Visual Studio is 2019 where `<filesystem`> is available (supported since Visual Studio 2017 version 15.7). That's why use filesystem::path only on Windows for now, added TODO to do the same on Linux when matrix support changes.
- Loading branch information
Showing
7 changed files
with
144 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//==-- windows_os_utils.hpp - Header file with common utils for Windows --==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===--------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <shlwapi.h> | ||
|
||
using OSModuleHandle = intptr_t; | ||
constexpr OSModuleHandle ExeModuleHandle = -1; | ||
inline OSModuleHandle getOSModuleHandle(const void *VirtAddr) { | ||
HMODULE PhModule; | ||
DWORD Flag = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | | ||
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT; | ||
auto LpModuleAddr = reinterpret_cast<LPCSTR>(VirtAddr); | ||
if (!GetModuleHandleExA(Flag, LpModuleAddr, &PhModule)) { | ||
// Expect the caller to check for zero and take | ||
// necessary action | ||
return 0; | ||
} | ||
if (PhModule == GetModuleHandleA(nullptr)) | ||
return ExeModuleHandle; | ||
return reinterpret_cast<OSModuleHandle>(PhModule); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters