@samitouri / QOSamiQemu / commits / d74938d14c

util: set the name for the 'main' thread on Windows

The default main thread name is undefined, so use a constructor to explicitly set it to 'main'. This constructor is marked to run early as the thread name is intended to be used in error reporting / logs which may be triggered very early in QEMU execution. This is only done on Windows platforms, because on Linux (and possibly other POSIX platforms) changing the main thread name has a side effect of changing the process name reported by tools like 'ps' which fetch from the file /proc/self/task/tid/comm, expecting it to be the binary name. The subsequent patch will address POSIX platforms in a different way. Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Daniel P. Berrangé committed Aug 6, 2025 at 15:56 UTC d74938d14cfd431c53b511f9d7899c06e8bba776
1 file changed +6
util/qemu-thread-win32.c
+6
@@ -22,6 +22,12 @@ typedef HRESULT (WINAPI *pSetThreadDescription) (HANDLE hThread,
22 static pSetThreadDescription SetThreadDescriptionFunc;
23 static HMODULE kernel32_module;
24
25 +static void __attribute__((__constructor__(QEMU_CONSTRUCTOR_EARLY)))
26 +qemu_thread_init(void)
27 +{
28 + qemu_thread_set_name("main");
29 +}
30 +
31 static bool load_set_thread_description(void)
32 {
33 static gsize _init_once = 0;