[PATCH] util/oslib-win32: Implement qemu_get_pid_name()

Evgeny Kolmakov posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260621130626.19073-1-randomjack94dev@gmail.com
Maintainers: Stefan Weil <sw@weilnetz.de>
util/oslib-win32.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
[PATCH] util/oslib-win32: Implement qemu_get_pid_name()
Posted by Evgeny Kolmakov 1 month ago
Replace the abort() stub with a proper implementation using
QueryFullProcessImageNameW() and g_utf16_to_utf8() to retrieve
the process executable name on Windows. Returns NULL on error
to match POSIX behavior.

Signed-off-by: Evgeny Kolmakov <randomjack94dev@gmail.com>
---
 util/oslib-win32.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 5f3e8f4d98..2b083b5d7a 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -287,8 +287,23 @@ bool qemu_finish_async_prealloc_mem(Error **errp)
 
 char *qemu_get_pid_name(pid_t pid)
 {
-    /* XXX Implement me */
-    abort();
+    HANDLE hProcess;
+    WCHAR path[4096];
+    DWORD size = G_N_ELEMENTS(path);
+    char *name = NULL;
+
+    hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, (DWORD)pid);
+    if (!hProcess) {
+        return NULL;
+    }
+
+    if (QueryFullProcessImageNameW(hProcess, 0, path, &size)) {
+        const WCHAR *base = wcsrchr(path, L'\\');
+        name = g_utf16_to_utf8(base ? base + 1 : path, -1, NULL, NULL, NULL);
+    }
+
+    CloseHandle(hProcess);
+    return name;
 }
 
 
-- 
2.43.0
Re: [PATCH] util/oslib-win32: Implement qemu_get_pid_name()
Posted by Evgeny an hour ago
ping

https://patchew.org/QEMU/20260621130626.19073-1-randomjack94dev@gmail.com/
https://lists.gnu.org/archive/html/qemu-devel/2026-06/msg05258.html

On Sun, Jun 21, 2026 at 4:08 PM Evgeny Kolmakov <randomjack94dev@gmail.com>
wrote:

> Replace the abort() stub with a proper implementation using
> QueryFullProcessImageNameW() and g_utf16_to_utf8() to retrieve
> the process executable name on Windows. Returns NULL on error
> to match POSIX behavior.
>
> Signed-off-by: Evgeny Kolmakov <randomjack94dev@gmail.com>
> ---
>  util/oslib-win32.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 5f3e8f4d98..2b083b5d7a 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -287,8 +287,23 @@ bool qemu_finish_async_prealloc_mem(Error **errp)
>
>  char *qemu_get_pid_name(pid_t pid)
>  {
> -    /* XXX Implement me */
> -    abort();
> +    HANDLE hProcess;
> +    WCHAR path[4096];
> +    DWORD size = G_N_ELEMENTS(path);
> +    char *name = NULL;
> +
> +    hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE,
> (DWORD)pid);
> +    if (!hProcess) {
> +        return NULL;
> +    }
> +
> +    if (QueryFullProcessImageNameW(hProcess, 0, path, &size)) {
> +        const WCHAR *base = wcsrchr(path, L'\\');
> +        name = g_utf16_to_utf8(base ? base + 1 : path, -1, NULL, NULL,
> NULL);
> +    }
> +
> +    CloseHandle(hProcess);
> +    return name;
>  }
>
>
> --
> 2.43.0
>
>