llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: None (llvmbot)

<details>
<summary>Changes</summary>

Backport 70ee6e4

Requested by: @<!-- -->aganea

---
Full diff: https://github.com/llvm/llvm-project/pull/178431.diff


2 Files Affected:

- (modified) llvm/lib/Support/Windows/Process.inc (+29) 
- (modified) llvm/lib/Support/Windows/Threading.inc (-29) 


``````````diff
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");

``````````

</details>


https://github.com/llvm/llvm-project/pull/178431
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to