Skip to content

Commit e3f935c

Browse files
committed
[Fuzzer] SetThreadName implementation for Windows
Api available since Windows Server 2016/Windows 10 1607. Reviewers: vitalybuka Reviewed-By: vitalybuka Differential Revision: https://reviews.llvm.org/D156317
1 parent 20e87e2 commit e3f935c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

compiler-rt/lib/fuzzer/FuzzerUtilWindows.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include <windows.h>
2525

2626
// This must be included after windows.h.
27+
#include <processthreadsapi.h>
2728
#include <psapi.h>
29+
#include <stringapiset.h>
2830

2931
namespace fuzzer {
3032

@@ -234,8 +236,9 @@ size_t PageSize() {
234236
}
235237

236238
void SetThreadName(std::thread &thread, const std::string &name) {
237-
// TODO ?
238-
// to UTF-8 then SetThreadDescription ?
239+
wchar_t wname[16];
240+
if (MultiByteToWideChar(CP_UTF8, 0, name.c_str(), -1, wname, 16) > 0)
241+
(void)SetThreadDescription(thread.native_handle(), wname);
239242
}
240243

241244
} // namespace fuzzer

0 commit comments

Comments
 (0)