[llvm] Windows: use EcoQoS for ThreadPriority::Background (PR #148797)
Alexandre Ganea via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 27 11:00:40 PDT 2025
================
@@ -106,7 +106,66 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) {
Name.clear();
}
+static 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(TEXT('\\'));
+ Buf.append(lpModuleName, lpModuleName + std::wcslen(lpModuleName));
+ Buf.push_back(0);
+
+ return ::GetModuleHandleW(Buf.data());
+}
+
SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) {
+ HMODULE kernelMod = LoadSystemModuleSecure(TEXT("kernel32.dll"));
----------------
aganea wrote:
As suggested.
https://github.com/llvm/llvm-project/pull/148797
More information about the llvm-commits
mailing list