Merge bitcoin/bitcoin#35884: util: set os-level thread names on Windows
What changed, and why it matters
This change lets Bitcoin Core give meaningful names to its internal threads when running on Windows, so they appear labeled in debuggers and crash dumps. It is purely a debugging convenience improvement and does not change how the software behaves or process any attacker-controlled data.
No security action required; treat as a normal debugging/quality improvement.
Security signals we found
No security-relevant code path modified
No input parsing, memory allocation change, or privilege boundary crossed
Change is explicitly described by the project as debugging-ergonomics only
Evidence from the diff
The commit extends SetThreadName() in src/util/threadnames.cpp to call Windows’ SetThreadDescription() on WIN32 builds. It converts the existing ASCII thread name to a UTF-16 std::wstring and applies it to the current thread. The function is only used for diagnostic labeling; thread names are hardcoded/internal and not derived from user or network input.
Changed components
src/util/threadnames.cppInspect captured patch +9 / −0
### src/util/threadnames.cpp
@@ -18,6 +18,10 @@
#include <sys/prctl.h>
#endif
+#ifdef WIN32
+#include <windows.h>
+#endif
+
//! Set the thread's name at the process level. Does not affect the
//! internal name.
static void SetThreadName(const char* name)
@@ -29,6 +33,11 @@ static void SetThreadName(const char* name)
pthread_set_name_np(pthread_self(), name);
#elif defined(__APPLE__)
pthread_setname_np(name);
+#elif defined(WIN32)
+ // Thread names are ASCII-only, so widening each character is sufficient as
+ // a conversion to UTF-16.
+ const std::wstring wname{name, name + std::strlen(name)};
+ ::SetThreadDescription(::GetCurrentThread(), wname.c_str());
#else
// Prevent warnings for unused parameters...
(void)name;Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.