Skip to content

Commit

Permalink
[Fuzzer] SetThreadName implementation for Windows
Browse files Browse the repository at this point in the history
Api available since Windows Server 2016/Windows 10 1607

Reviewed By: vitalybuka

Differential Revision: https://reviews.llvm.org/D156317
  • Loading branch information
devnexen authored and vitalybuka committed Jul 28, 2023
1 parent 404bc5c commit 885275b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,14 @@ size_t PageSize() {
}

void SetThreadName(std::thread &thread, const std::string &name) {
// TODO ?
// to UTF-8 then SetThreadDescription ?
auto sz =
MultiByteToWideChar(CP_UTF8, 0, name.data(), name.size(), nullptr, 0);
std::wstring wname(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
Expand Down

0 comments on commit 885275b

Please sign in to comment.