[compiler-rt] cf76ddc - [Fuzzer] SetThreadName implementation for Windows
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 28 05:15:49 PDT 2023
Author: David CARLIER
Date: 2023-08-28T13:14:47+01:00
New Revision: cf76ddcbeb10be1f3eee5fa86dc41f9ca2435d50
URL: https://github.com/llvm/llvm-project/commit/cf76ddcbeb10be1f3eee5fa86dc41f9ca2435d50
DIFF: https://github.com/llvm/llvm-project/commit/cf76ddcbeb10be1f3eee5fa86dc41f9ca2435d50.diff
LOG: [Fuzzer] SetThreadName implementation for Windows
Api available since Windows Server 2016/Windows 10 1607
Reviewers: vitalybuka
Reviewed-By: vitalybuka
Differential Revison: https://reviews.llvm.org/D156317
Added:
Modified:
compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
index 71770166805f78..6bcba6151f2681 100644
--- a/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
+++ b/compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
@@ -234,8 +234,13 @@ size_t PageSize() {
}
void SetThreadName(std::thread &thread, const std::string &name) {
- // TODO ?
- // to UTF-8 then SetThreadDescription ?
+ std::wstring wname;
+ auto sz = MultiByteToWideChar(CP_UTF8, 0, name.data(), name.size(), nullptr, 0);
+ wname.resize(sz);
+ if (sz == MultiByteToWideChar(CP_UTF8, 0, name.data, name.size, &wname[0], sz) > 0) {
+ wname.resize(sz - 1);
+ (void)SetThreadDescription(thread.native_handle(), wname.c_str());
+ }
}
} // namespace fuzzer
More information about the llvm-commits
mailing list