Repository navigation
[Support] Move loadSystemModuleSecure into Process.inc. NFC. - #177598
Conversation
This is to fix link problems on Windows, see llvm#169224 (comment)
|
@llvm/pr-subscribers-platform-windows Author: Alexandre Ganea (aganea) ChangesMove Windows-specific function This is to fix link problems on Windows, see #169224 (comment) 2 Files Affected:
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index c4d18ca7375f2..01c05bb21628f 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -521,3 +521,32 @@ bool llvm::RunningWindows11OrGreater() {
TerminateProcess(GetCurrentProcess(), RetCode);
llvm_unreachable("TerminateProcess doesn't return");
}
+
+namespace llvm::sys::windows {
+HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName) {
+ // Ensure we load indeed a module from system32 path.
+ // As per GetModuleHandle documentation:
+ // "If lpModuleName does not include a path and there is more than one loaded
+ // module with the same base name and extension, you cannot predict which
+ // module handle will be returned.". This mitigates
+ // https://learn.microsoft.com/en-us/security-updates/securityadvisories/2010/2269637
+ SmallVector<wchar_t, MAX_PATH> Buf;
+ size_t Size = MAX_PATH;
+ do {
+ Buf.resize_for_overwrite(Size);
+ SetLastError(NO_ERROR);
+ Size = ::GetSystemDirectoryW(Buf.data(), Buf.size());
+ if (Size == 0)
+ return NULL;
+
+ // Try again with larger buffer.
+ } while (Size > Buf.size());
+
+ Buf.truncate(Size);
+ Buf.push_back(L'\\');
+ Buf.append(lpModuleName, lpModuleName + std::wcslen(lpModuleName));
+ Buf.push_back(0);
+
+ return ::GetModuleHandleW(Buf.data());
+}
+} // namespace llvm::sys::windows
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 968423b98486c..86e46b99cb38b 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -105,35 +105,6 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
Name.clear();
}
-namespace llvm::sys::windows {
-HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName) {
- // Ensure we load indeed a module from system32 path.
- // As per GetModuleHandle documentation:
- // "If lpModuleName does not include a path and there is more than one loaded
- // module with the same base name and extension, you cannot predict which
- // module handle will be returned.". This mitigates
- // https://learn.microsoft.com/en-us/security-updates/securityadvisories/2010/2269637
- SmallVector<wchar_t, MAX_PATH> Buf;
- size_t Size = MAX_PATH;
- do {
- Buf.resize_for_overwrite(Size);
- SetLastError(NO_ERROR);
- Size = ::GetSystemDirectoryW(Buf.data(), Buf.size());
- if (Size == 0)
- return NULL;
-
- // Try again with larger buffer.
- } while (Size > Buf.size());
-
- Buf.truncate(Size);
- Buf.push_back(L'\\');
- Buf.append(lpModuleName, lpModuleName + std::wcslen(lpModuleName));
- Buf.push_back(0);
-
- return ::GetModuleHandleW(Buf.data());
-}
-} // namespace llvm::sys::windows
-
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
#ifdef THREAD_POWER_THROTTLING_CURRENT_VERSION
HMODULE kernelM = llvm::sys::windows::loadSystemModuleSecure(L"kernel32.dll");
|
|
@llvm/pr-subscribers-llvm-support Author: Alexandre Ganea (aganea) ChangesMove Windows-specific function This is to fix link problems on Windows, see #169224 (comment) 2 Files Affected:
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index c4d18ca7375f2..01c05bb21628f 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -521,3 +521,32 @@ bool llvm::RunningWindows11OrGreater() {
TerminateProcess(GetCurrentProcess(), RetCode);
llvm_unreachable("TerminateProcess doesn't return");
}
+
+namespace llvm::sys::windows {
+HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName) {
+ // Ensure we load indeed a module from system32 path.
+ // As per GetModuleHandle documentation:
+ // "If lpModuleName does not include a path and there is more than one loaded
+ // module with the same base name and extension, you cannot predict which
+ // module handle will be returned.". This mitigates
+ // https://learn.microsoft.com/en-us/security-updates/securityadvisories/2010/2269637
+ SmallVector<wchar_t, MAX_PATH> Buf;
+ size_t Size = MAX_PATH;
+ do {
+ Buf.resize_for_overwrite(Size);
+ SetLastError(NO_ERROR);
+ Size = ::GetSystemDirectoryW(Buf.data(), Buf.size());
+ if (Size == 0)
+ return NULL;
+
+ // Try again with larger buffer.
+ } while (Size > Buf.size());
+
+ Buf.truncate(Size);
+ Buf.push_back(L'\\');
+ Buf.append(lpModuleName, lpModuleName + std::wcslen(lpModuleName));
+ Buf.push_back(0);
+
+ return ::GetModuleHandleW(Buf.data());
+}
+} // namespace llvm::sys::windows
diff --git a/llvm/lib/Support/Windows/Threading.inc b/llvm/lib/Support/Windows/Threading.inc
index 968423b98486c..86e46b99cb38b 100644
--- a/llvm/lib/Support/Windows/Threading.inc
+++ b/llvm/lib/Support/Windows/Threading.inc
@@ -105,35 +105,6 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
Name.clear();
}
-namespace llvm::sys::windows {
-HMODULE loadSystemModuleSecure(LPCWSTR lpModuleName) {
- // Ensure we load indeed a module from system32 path.
- // As per GetModuleHandle documentation:
- // "If lpModuleName does not include a path and there is more than one loaded
- // module with the same base name and extension, you cannot predict which
- // module handle will be returned.". This mitigates
- // https://learn.microsoft.com/en-us/security-updates/securityadvisories/2010/2269637
- SmallVector<wchar_t, MAX_PATH> Buf;
- size_t Size = MAX_PATH;
- do {
- Buf.resize_for_overwrite(Size);
- SetLastError(NO_ERROR);
- Size = ::GetSystemDirectoryW(Buf.data(), Buf.size());
- if (Size == 0)
- return NULL;
-
- // Try again with larger buffer.
- } while (Size > Buf.size());
-
- Buf.truncate(Size);
- Buf.push_back(L'\\');
- Buf.append(lpModuleName, lpModuleName + std::wcslen(lpModuleName));
- Buf.push_back(0);
-
- return ::GetModuleHandleW(Buf.data());
-}
-} // namespace llvm::sys::windows
-
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
#ifdef THREAD_POWER_THROTTLING_CURRENT_VERSION
HMODULE kernelM = llvm::sys::windows::loadSystemModuleSecure(L"kernel32.dll");
|
|
@aganea Can you port this to release/22.x ? llvmorg-22-init was good and this issue started reproing with llvmorg-22.1.0-rc1. |
|
/cherry-pick 70ee6e4 |
|
Failed to create pull request for issue177598 https://github.com/llvm/llvm-project/actions/runs/21441400683 |
|
/pull-request #178431 |
…7598) Move Windows-specific function `llvm::sys::windows::loadSystemModuleSecure` from `lib/Support/Windows/Threading.inc` into `lib/Support/Windows/Process.inc`. This is to fix link problems on Windows, see llvm#169224 (comment) (cherry picked from commit 70ee6e4)
Move Windows-specific function
llvm::sys::windows::loadSystemModuleSecurefromlib/Support/Windows/Threading.incintolib/Support/Windows/Process.inc.This is to fix link problems on Windows, see #169224 (comment)