Skip to content

Commit cf76ddc

Browse files
committed
[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
1 parent 435d412 commit cf76ddc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,13 @@ size_t PageSize() {
234234
}
235235

236236
void SetThreadName(std::thread &thread, const std::string &name) {
237-
// TODO ?
238-
// to UTF-8 then SetThreadDescription ?
237+
std::wstring wname;
238+
auto sz = MultiByteToWideChar(CP_UTF8, 0, name.data(), name.size(), nullptr, 0);
239+
wname.resize(sz);
240+
if (sz == MultiByteToWideChar(CP_UTF8, 0, name.data, name.size, &wname[0], sz) > 0) {
241+
wname.resize(sz - 1);
242+
(void)SetThreadDescription(thread.native_handle(), wname.c_str());
243+
}
239244
}
240245

241246
} // namespace fuzzer

0 commit comments

Comments
 (0)