| 239 | } |
| 240 | |
| 241 | void SetThreadName(std::thread &thread, const std::string &name) { |
| 242 | typedef HRESULT(WINAPI * proc)(HANDLE, PCWSTR); |
| 243 | HMODULE kbase = GetModuleHandleA("KernelBase.dll"); |
| 244 | proc ThreadNameProc = |
| 245 | reinterpret_cast<proc>(GetProcAddress(kbase, "SetThreadDescription")); |
| 246 | if (ThreadNameProc) { |
| 247 | std::wstring buf; |
| 248 | auto sz = MultiByteToWideChar(CP_UTF8, 0, name.data(), -1, nullptr, 0); |
| 249 | if (sz > 0) { |
| 250 | buf.resize(sz); |
| 251 | if (MultiByteToWideChar(CP_UTF8, 0, name.data(), -1, &buf[0], sz) > 0) { |
| 252 | (void)ThreadNameProc(thread.native_handle(), buf.c_str()); |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | } // namespace fuzzer |
| 259 | |