From: Bin Meng <bin.meng@windriver.com>
This adds a helper to get the Windows version via the RtlGetVersion
call, for QEMU codes to determine the Windows version at run-time.
Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
include/sysemu/os-win32.h | 2 ++
util/oslib-win32.c | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index edc3b38a57..1e324026a4 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
struct sockaddr *addr, socklen_t *addrlen);
+void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
+
#ifdef __cplusplus
}
#endif
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index 5723d3eb4c..6d2387b9ff 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
*/
return qemu_fdatasync(fd);
}
+
+void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
+{
+ typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
+
+ /* RtlGetVersion is available starting with Windows 2000 */
+ HMODULE module = GetModuleHandle("ntdll");
+ PVOID fun = GetProcAddress(module, "RtlGetVersion");
+ rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
+
+ info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
+ rtl_get_version(info);
+
+ return;
+}
--
2.34.1
On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> From: Bin Meng <bin.meng@windriver.com>
>
> This adds a helper to get the Windows version via the RtlGetVersion
> call, for QEMU codes to determine the Windows version at run-time.
>
> Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
> include/sysemu/os-win32.h | 2 ++
> util/oslib-win32.c | 15 +++++++++++++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> index edc3b38a57..1e324026a4 100644
> --- a/include/sysemu/os-win32.h
> +++ b/include/sysemu/os-win32.h
> @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
> ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
> struct sockaddr *addr, socklen_t *addrlen);
>
> +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
> +
> #ifdef __cplusplus
> }
> #endif
> diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> index 5723d3eb4c..6d2387b9ff 100644
> --- a/util/oslib-win32.c
> +++ b/util/oslib-win32.c
> @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
> */
> return qemu_fdatasync(fd);
> }
> +
> +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
> +{
> + typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
> +
> + /* RtlGetVersion is available starting with Windows 2000 */
> + HMODULE module = GetModuleHandle("ntdll");
> + PVOID fun = GetProcAddress(module, "RtlGetVersion");
> + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> +
> + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> + rtl_get_version(info);
The original function, when it was present in qemu-ga, tested that
getting the function address succeeded.
I think this test should be kept.
See below:
- PVOID fun = GetProcAddress(module, "RtlGetVersion");
- if (fun == NULL) {
- error_setg(errp, QERR_QGA_COMMAND_FAILED,
- "Failed to get address of RtlGetVersion");
- return;
- }
Best regards,
Yan.
> +
> + return;
> +}
> --
> 2.34.1
>
>
On Wed, Jul 27, 2022 at 4:50 PM Yan Vugenfirer <yvugenfi@redhat.com> wrote:
>
> On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> >
> > From: Bin Meng <bin.meng@windriver.com>
> >
> > This adds a helper to get the Windows version via the RtlGetVersion
> > call, for QEMU codes to determine the Windows version at run-time.
> >
> > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > ---
> >
> > include/sysemu/os-win32.h | 2 ++
> > util/oslib-win32.c | 15 +++++++++++++++
> > 2 files changed, 17 insertions(+)
> >
> > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> > index edc3b38a57..1e324026a4 100644
> > --- a/include/sysemu/os-win32.h
> > +++ b/include/sysemu/os-win32.h
> > @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
> > ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
> > struct sockaddr *addr, socklen_t *addrlen);
> >
> > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
> > +
> > #ifdef __cplusplus
> > }
> > #endif
> > diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> > index 5723d3eb4c..6d2387b9ff 100644
> > --- a/util/oslib-win32.c
> > +++ b/util/oslib-win32.c
> > @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
> > */
> > return qemu_fdatasync(fd);
> > }
> > +
> > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
> > +{
> > + typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
> > +
> > + /* RtlGetVersion is available starting with Windows 2000 */
> > + HMODULE module = GetModuleHandle("ntdll");
> > + PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> > +
> > + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> > + rtl_get_version(info);
> The original function, when it was present in qemu-ga, tested that
> getting the function address succeeded.
> I think this test should be kept.
> See below:
> - PVOID fun = GetProcAddress(module, "RtlGetVersion");
> - if (fun == NULL) {
> - error_setg(errp, QERR_QGA_COMMAND_FAILED,
> - "Failed to get address of RtlGetVersion");
> - return;
> - }
>
Please see the comment:
/* RtlGetVersion is available starting with Windows 2000 */
I don't think we need that check.
Regards,
Bin
On Wed, Jul 27, 2022 at 05:38:27PM +0800, Bin Meng wrote:
> On Wed, Jul 27, 2022 at 4:50 PM Yan Vugenfirer <yvugenfi@redhat.com> wrote:
> >
> > On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > >
> > > From: Bin Meng <bin.meng@windriver.com>
> > >
> > > This adds a helper to get the Windows version via the RtlGetVersion
> > > call, for QEMU codes to determine the Windows version at run-time.
> > >
> > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > ---
> > >
> > > include/sysemu/os-win32.h | 2 ++
> > > util/oslib-win32.c | 15 +++++++++++++++
> > > 2 files changed, 17 insertions(+)
> > >
> > > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> > > index edc3b38a57..1e324026a4 100644
> > > --- a/include/sysemu/os-win32.h
> > > +++ b/include/sysemu/os-win32.h
> > > @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
> > > ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
> > > struct sockaddr *addr, socklen_t *addrlen);
> > >
> > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
> > > +
> > > #ifdef __cplusplus
> > > }
> > > #endif
> > > diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> > > index 5723d3eb4c..6d2387b9ff 100644
> > > --- a/util/oslib-win32.c
> > > +++ b/util/oslib-win32.c
> > > @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
> > > */
> > > return qemu_fdatasync(fd);
> > > }
> > > +
> > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
> > > +{
> > > + typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
> > > +
> > > + /* RtlGetVersion is available starting with Windows 2000 */
> > > + HMODULE module = GetModuleHandle("ntdll");
> > > + PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> > > +
> > > + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> > > + rtl_get_version(info);
> > The original function, when it was present in qemu-ga, tested that
> > getting the function address succeeded.
> > I think this test should be kept.
> > See below:
> > - PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > - if (fun == NULL) {
> > - error_setg(errp, QERR_QGA_COMMAND_FAILED,
> > - "Failed to get address of RtlGetVersion");
> > - return;
> > - }
> >
>
> Please see the comment:
>
> /* RtlGetVersion is available starting with Windows 2000 */
>
> I don't think we need that check.
In include/qemu/osdep.h we have
/* as defined in sdkddkver.h */
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0601 /* Windows 7 API (should be in sync with glib) */
#endif
so do we even need to have the GetProcAddress calls at all ?
Surely we can just '#include <ddk/ntddk.h>' and call
RtlGetVersion directly at compile time ?
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
On Wed, Jul 27, 2022 at 6:00 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Wed, Jul 27, 2022 at 05:38:27PM +0800, Bin Meng wrote:
> > On Wed, Jul 27, 2022 at 4:50 PM Yan Vugenfirer <yvugenfi@redhat.com> wrote:
> > >
> > > On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > From: Bin Meng <bin.meng@windriver.com>
> > > >
> > > > This adds a helper to get the Windows version via the RtlGetVersion
> > > > call, for QEMU codes to determine the Windows version at run-time.
> > > >
> > > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > ---
> > > >
> > > > include/sysemu/os-win32.h | 2 ++
> > > > util/oslib-win32.c | 15 +++++++++++++++
> > > > 2 files changed, 17 insertions(+)
> > > >
> > > > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> > > > index edc3b38a57..1e324026a4 100644
> > > > --- a/include/sysemu/os-win32.h
> > > > +++ b/include/sysemu/os-win32.h
> > > > @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
> > > > ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
> > > > struct sockaddr *addr, socklen_t *addrlen);
> > > >
> > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
> > > > +
> > > > #ifdef __cplusplus
> > > > }
> > > > #endif
> > > > diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> > > > index 5723d3eb4c..6d2387b9ff 100644
> > > > --- a/util/oslib-win32.c
> > > > +++ b/util/oslib-win32.c
> > > > @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
> > > > */
> > > > return qemu_fdatasync(fd);
> > > > }
> > > > +
> > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
> > > > +{
> > > > + typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
> > > > +
> > > > + /* RtlGetVersion is available starting with Windows 2000 */
> > > > + HMODULE module = GetModuleHandle("ntdll");
> > > > + PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > > + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> > > > +
> > > > + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> > > > + rtl_get_version(info);
> > > The original function, when it was present in qemu-ga, tested that
> > > getting the function address succeeded.
> > > I think this test should be kept.
> > > See below:
> > > - PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > - if (fun == NULL) {
> > > - error_setg(errp, QERR_QGA_COMMAND_FAILED,
> > > - "Failed to get address of RtlGetVersion");
> > > - return;
> > > - }
> > >
> >
> > Please see the comment:
> >
> > /* RtlGetVersion is available starting with Windows 2000 */
> >
> > I don't think we need that check.
>
> In include/qemu/osdep.h we have
>
> /* as defined in sdkddkver.h */
> #ifndef _WIN32_WINNT
> #define _WIN32_WINNT 0x0601 /* Windows 7 API (should be in sync with glib) */
> #endif
>
> so do we even need to have the GetProcAddress calls at all ?
>
> Surely we can just '#include <ddk/ntddk.h>' and call
> RtlGetVersion directly at compile time ?
>
I believe #include <ddk/ntddk.h> is used in the kernel mode driver
programming environment.
In the user space we will have to use the ntdll exported symbol.
I cannot locate a Microsoft doc that tells us to call RtlGetVersion
directly in the user space.
Regards,
Bin
On Wed, Jul 27, 2022 at 2:58 PM Bin Meng <bmeng.cn@gmail.com> wrote:
> On Wed, Jul 27, 2022 at 6:00 PM Daniel P. Berrangé <berrange@redhat.com>
> wrote:
> >
> > On Wed, Jul 27, 2022 at 05:38:27PM +0800, Bin Meng wrote:
> > > On Wed, Jul 27, 2022 at 4:50 PM Yan Vugenfirer <yvugenfi@redhat.com>
> wrote:
> > > >
> > > > On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com>
> wrote:
> > > > >
> > > > > From: Bin Meng <bin.meng@windriver.com>
> > > > >
> > > > > This adds a helper to get the Windows version via the RtlGetVersion
> > > > > call, for QEMU codes to determine the Windows version at run-time.
> > > > >
> > > > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > > ---
> > > > >
> > > > > include/sysemu/os-win32.h | 2 ++
> > > > > util/oslib-win32.c | 15 +++++++++++++++
> > > > > 2 files changed, 17 insertions(+)
> > > > >
> > > > > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> > > > > index edc3b38a57..1e324026a4 100644
> > > > > --- a/include/sysemu/os-win32.h
> > > > > +++ b/include/sysemu/os-win32.h
> > > > > @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf,
> size_t len, int flags);
> > > > > ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int
> flags,
> > > > > struct sockaddr *addr, socklen_t
> *addrlen);
> > > > >
> > > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
> > > > > +
> > > > > #ifdef __cplusplus
> > > > > }
> > > > > #endif
> > > > > diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> > > > > index 5723d3eb4c..6d2387b9ff 100644
> > > > > --- a/util/oslib-win32.c
> > > > > +++ b/util/oslib-win32.c
> > > > > @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int
> fd)
> > > > > */
> > > > > return qemu_fdatasync(fd);
> > > > > }
> > > > > +
> > > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
> > > > > +{
> > > > > + typedef LONG (WINAPI
> *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
> > > > > +
> > > > > + /* RtlGetVersion is available starting with Windows 2000 */
> > > > > + HMODULE module = GetModuleHandle("ntdll");
> > > > > + PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > > > + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> > > > > +
> > > > > + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> > > > > + rtl_get_version(info);
> > > > The original function, when it was present in qemu-ga, tested that
> > > > getting the function address succeeded.
> > > > I think this test should be kept.
> > > > See below:
> > > > - PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > > - if (fun == NULL) {
> > > > - error_setg(errp, QERR_QGA_COMMAND_FAILED,
> > > > - "Failed to get address of RtlGetVersion");
> > > > - return;
> > > > - }
> > > >
> > >
> > > Please see the comment:
> > >
> > > /* RtlGetVersion is available starting with Windows 2000 */
> > >
> > > I don't think we need that check.
> >
> > In include/qemu/osdep.h we have
> >
> > /* as defined in sdkddkver.h */
> > #ifndef _WIN32_WINNT
> > #define _WIN32_WINNT 0x0601 /* Windows 7 API (should be in sync with
> glib) */
> > #endif
> >
> > so do we even need to have the GetProcAddress calls at all ?
> >
> > Surely we can just '#include <ddk/ntddk.h>' and call
> > RtlGetVersion directly at compile time ?
> >
>
> I believe #include <ddk/ntddk.h> is used in the kernel mode driver
> programming environment.
> In the user space we will have to use the ntdll exported symbol.
>
> I cannot locate a Microsoft doc that tells us to call RtlGetVersion
> directly in the user space.
>
From MS docs: RtlGetVersion is the kernel-mode equivalent of the user-mode
GetVersionEx function in the Windows SDK.
So you can use GetVersionEx instread.
>
> Regards,
> Bin
>
>
On Wed, Jul 27, 2022 at 9:18 PM Konstantin Kostiuk <kkostiuk@redhat.com> wrote:
>
>
>
> On Wed, Jul 27, 2022 at 2:58 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>>
>> On Wed, Jul 27, 2022 at 6:00 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>> >
>> > On Wed, Jul 27, 2022 at 05:38:27PM +0800, Bin Meng wrote:
>> > > On Wed, Jul 27, 2022 at 4:50 PM Yan Vugenfirer <yvugenfi@redhat.com> wrote:
>> > > >
>> > > > On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>> > > > >
>> > > > > From: Bin Meng <bin.meng@windriver.com>
>> > > > >
>> > > > > This adds a helper to get the Windows version via the RtlGetVersion
>> > > > > call, for QEMU codes to determine the Windows version at run-time.
>> > > > >
>> > > > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
>> > > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
>> > > > > ---
>> > > > >
>> > > > > include/sysemu/os-win32.h | 2 ++
>> > > > > util/oslib-win32.c | 15 +++++++++++++++
>> > > > > 2 files changed, 17 insertions(+)
>> > > > >
>> > > > > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
>> > > > > index edc3b38a57..1e324026a4 100644
>> > > > > --- a/include/sysemu/os-win32.h
>> > > > > +++ b/include/sysemu/os-win32.h
>> > > > > @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
>> > > > > ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
>> > > > > struct sockaddr *addr, socklen_t *addrlen);
>> > > > >
>> > > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
>> > > > > +
>> > > > > #ifdef __cplusplus
>> > > > > }
>> > > > > #endif
>> > > > > diff --git a/util/oslib-win32.c b/util/oslib-win32.c
>> > > > > index 5723d3eb4c..6d2387b9ff 100644
>> > > > > --- a/util/oslib-win32.c
>> > > > > +++ b/util/oslib-win32.c
>> > > > > @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
>> > > > > */
>> > > > > return qemu_fdatasync(fd);
>> > > > > }
>> > > > > +
>> > > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
>> > > > > +{
>> > > > > + typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
>> > > > > +
>> > > > > + /* RtlGetVersion is available starting with Windows 2000 */
>> > > > > + HMODULE module = GetModuleHandle("ntdll");
>> > > > > + PVOID fun = GetProcAddress(module, "RtlGetVersion");
>> > > > > + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
>> > > > > +
>> > > > > + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
>> > > > > + rtl_get_version(info);
>> > > > The original function, when it was present in qemu-ga, tested that
>> > > > getting the function address succeeded.
>> > > > I think this test should be kept.
>> > > > See below:
>> > > > - PVOID fun = GetProcAddress(module, "RtlGetVersion");
>> > > > - if (fun == NULL) {
>> > > > - error_setg(errp, QERR_QGA_COMMAND_FAILED,
>> > > > - "Failed to get address of RtlGetVersion");
>> > > > - return;
>> > > > - }
>> > > >
>> > >
>> > > Please see the comment:
>> > >
>> > > /* RtlGetVersion is available starting with Windows 2000 */
>> > >
>> > > I don't think we need that check.
>> >
>> > In include/qemu/osdep.h we have
>> >
>> > /* as defined in sdkddkver.h */
>> > #ifndef _WIN32_WINNT
>> > #define _WIN32_WINNT 0x0601 /* Windows 7 API (should be in sync with glib) */
>> > #endif
>> >
>> > so do we even need to have the GetProcAddress calls at all ?
>> >
>> > Surely we can just '#include <ddk/ntddk.h>' and call
>> > RtlGetVersion directly at compile time ?
>> >
>>
>> I believe #include <ddk/ntddk.h> is used in the kernel mode driver
>> programming environment.
>> In the user space we will have to use the ntdll exported symbol.
>>
>> I cannot locate a Microsoft doc that tells us to call RtlGetVersion
>> directly in the user space.
>
>
> From MS docs: RtlGetVersion is the kernel-mode equivalent of the user-mode GetVersionEx function in the Windows SDK.
> So you can use GetVersionEx instread.
>
Unfortunately this does not work. GetVersionEx is deprecated since Windows 8.1
Regards,
Bin
On Wed, Jul 27, 2022 at 07:55:40PM +0800, Bin Meng wrote:
> On Wed, Jul 27, 2022 at 6:00 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> >
> > On Wed, Jul 27, 2022 at 05:38:27PM +0800, Bin Meng wrote:
> > > On Wed, Jul 27, 2022 at 4:50 PM Yan Vugenfirer <yvugenfi@redhat.com> wrote:
> > > >
> > > > On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > >
> > > > > From: Bin Meng <bin.meng@windriver.com>
> > > > >
> > > > > This adds a helper to get the Windows version via the RtlGetVersion
> > > > > call, for QEMU codes to determine the Windows version at run-time.
> > > > >
> > > > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > > ---
> > > > >
> > > > > include/sysemu/os-win32.h | 2 ++
> > > > > util/oslib-win32.c | 15 +++++++++++++++
> > > > > 2 files changed, 17 insertions(+)
> > > > >
> > > > > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> > > > > index edc3b38a57..1e324026a4 100644
> > > > > --- a/include/sysemu/os-win32.h
> > > > > +++ b/include/sysemu/os-win32.h
> > > > > @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
> > > > > ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
> > > > > struct sockaddr *addr, socklen_t *addrlen);
> > > > >
> > > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
> > > > > +
> > > > > #ifdef __cplusplus
> > > > > }
> > > > > #endif
> > > > > diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> > > > > index 5723d3eb4c..6d2387b9ff 100644
> > > > > --- a/util/oslib-win32.c
> > > > > +++ b/util/oslib-win32.c
> > > > > @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
> > > > > */
> > > > > return qemu_fdatasync(fd);
> > > > > }
> > > > > +
> > > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
> > > > > +{
> > > > > + typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
> > > > > +
> > > > > + /* RtlGetVersion is available starting with Windows 2000 */
> > > > > + HMODULE module = GetModuleHandle("ntdll");
> > > > > + PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > > > + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> > > > > +
> > > > > + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> > > > > + rtl_get_version(info);
> > > > The original function, when it was present in qemu-ga, tested that
> > > > getting the function address succeeded.
> > > > I think this test should be kept.
> > > > See below:
> > > > - PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > > - if (fun == NULL) {
> > > > - error_setg(errp, QERR_QGA_COMMAND_FAILED,
> > > > - "Failed to get address of RtlGetVersion");
> > > > - return;
> > > > - }
> > > >
> > >
> > > Please see the comment:
> > >
> > > /* RtlGetVersion is available starting with Windows 2000 */
> > >
> > > I don't think we need that check.
> >
> > In include/qemu/osdep.h we have
> >
> > /* as defined in sdkddkver.h */
> > #ifndef _WIN32_WINNT
> > #define _WIN32_WINNT 0x0601 /* Windows 7 API (should be in sync with glib) */
> > #endif
> >
> > so do we even need to have the GetProcAddress calls at all ?
> >
> > Surely we can just '#include <ddk/ntddk.h>' and call
> > RtlGetVersion directly at compile time ?
> >
>
> I believe #include <ddk/ntddk.h> is used in the kernel mode driver
> programming environment.
> In the user space we will have to use the ntdll exported symbol.
>
> I cannot locate a Microsoft doc that tells us to call RtlGetVersion
> directly in the user space.
I wonder if we actually need to add this helper API to QEMU at all.
Would it be possible to use GLib 's g_win32_check_windows_version API
instead ?
https://developer-old.gnome.org/glib/unstable/glib-Windows-Compatibility-Functions.html#g-win32-check-windows-version
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
On Wed, Jul 27, 2022 at 8:53 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Wed, Jul 27, 2022 at 07:55:40PM +0800, Bin Meng wrote:
> > On Wed, Jul 27, 2022 at 6:00 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
> > >
> > > On Wed, Jul 27, 2022 at 05:38:27PM +0800, Bin Meng wrote:
> > > > On Wed, Jul 27, 2022 at 4:50 PM Yan Vugenfirer <yvugenfi@redhat.com> wrote:
> > > > >
> > > > > On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > > > >
> > > > > > From: Bin Meng <bin.meng@windriver.com>
> > > > > >
> > > > > > This adds a helper to get the Windows version via the RtlGetVersion
> > > > > > call, for QEMU codes to determine the Windows version at run-time.
> > > > > >
> > > > > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > > > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > > > ---
> > > > > >
> > > > > > include/sysemu/os-win32.h | 2 ++
> > > > > > util/oslib-win32.c | 15 +++++++++++++++
> > > > > > 2 files changed, 17 insertions(+)
> > > > > >
> > > > > > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> > > > > > index edc3b38a57..1e324026a4 100644
> > > > > > --- a/include/sysemu/os-win32.h
> > > > > > +++ b/include/sysemu/os-win32.h
> > > > > > @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
> > > > > > ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
> > > > > > struct sockaddr *addr, socklen_t *addrlen);
> > > > > >
> > > > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
> > > > > > +
> > > > > > #ifdef __cplusplus
> > > > > > }
> > > > > > #endif
> > > > > > diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> > > > > > index 5723d3eb4c..6d2387b9ff 100644
> > > > > > --- a/util/oslib-win32.c
> > > > > > +++ b/util/oslib-win32.c
> > > > > > @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
> > > > > > */
> > > > > > return qemu_fdatasync(fd);
> > > > > > }
> > > > > > +
> > > > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
> > > > > > +{
> > > > > > + typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
> > > > > > +
> > > > > > + /* RtlGetVersion is available starting with Windows 2000 */
> > > > > > + HMODULE module = GetModuleHandle("ntdll");
> > > > > > + PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > > > > + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> > > > > > +
> > > > > > + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> > > > > > + rtl_get_version(info);
> > > > > The original function, when it was present in qemu-ga, tested that
> > > > > getting the function address succeeded.
> > > > > I think this test should be kept.
> > > > > See below:
> > > > > - PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > > > - if (fun == NULL) {
> > > > > - error_setg(errp, QERR_QGA_COMMAND_FAILED,
> > > > > - "Failed to get address of RtlGetVersion");
> > > > > - return;
> > > > > - }
> > > > >
> > > >
> > > > Please see the comment:
> > > >
> > > > /* RtlGetVersion is available starting with Windows 2000 */
> > > >
> > > > I don't think we need that check.
> > >
> > > In include/qemu/osdep.h we have
> > >
> > > /* as defined in sdkddkver.h */
> > > #ifndef _WIN32_WINNT
> > > #define _WIN32_WINNT 0x0601 /* Windows 7 API (should be in sync with glib) */
> > > #endif
> > >
> > > so do we even need to have the GetProcAddress calls at all ?
> > >
> > > Surely we can just '#include <ddk/ntddk.h>' and call
> > > RtlGetVersion directly at compile time ?
> > >
> >
> > I believe #include <ddk/ntddk.h> is used in the kernel mode driver
> > programming environment.
> > In the user space we will have to use the ntdll exported symbol.
> >
> > I cannot locate a Microsoft doc that tells us to call RtlGetVersion
> > directly in the user space.
>
> I wonder if we actually need to add this helper API to QEMU at all.
>
> Would it be possible to use GLib 's g_win32_check_windows_version API
> instead ?
>
> https://developer-old.gnome.org/glib/unstable/glib-Windows-Compatibility-Functions.html#g-win32-check-windows-version
>
I am afraid not. g_win32_check_windows_version API does not provide
detailed build number like RtlGetVersion does.
Regards,
Bin
On Wed, Jul 27, 2022 at 1:00 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Wed, Jul 27, 2022 at 05:38:27PM +0800, Bin Meng wrote:
> > On Wed, Jul 27, 2022 at 4:50 PM Yan Vugenfirer <yvugenfi@redhat.com> wrote:
> > >
> > > On Wed, Jul 27, 2022 at 10:43 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> > > >
> > > > From: Bin Meng <bin.meng@windriver.com>
> > > >
> > > > This adds a helper to get the Windows version via the RtlGetVersion
> > > > call, for QEMU codes to determine the Windows version at run-time.
> > > >
> > > > Signed-off-by: Xuzhou Cheng <xuzhou.cheng@windriver.com>
> > > > Signed-off-by: Bin Meng <bin.meng@windriver.com>
> > > > ---
> > > >
> > > > include/sysemu/os-win32.h | 2 ++
> > > > util/oslib-win32.c | 15 +++++++++++++++
> > > > 2 files changed, 17 insertions(+)
> > > >
> > > > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> > > > index edc3b38a57..1e324026a4 100644
> > > > --- a/include/sysemu/os-win32.h
> > > > +++ b/include/sysemu/os-win32.h
> > > > @@ -204,6 +204,8 @@ ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
> > > > ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
> > > > struct sockaddr *addr, socklen_t *addrlen);
> > > >
> > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info);
> > > > +
> > > > #ifdef __cplusplus
> > > > }
> > > > #endif
> > > > diff --git a/util/oslib-win32.c b/util/oslib-win32.c
> > > > index 5723d3eb4c..6d2387b9ff 100644
> > > > --- a/util/oslib-win32.c
> > > > +++ b/util/oslib-win32.c
> > > > @@ -547,3 +547,18 @@ int qemu_msync(void *addr, size_t length, int fd)
> > > > */
> > > > return qemu_fdatasync(fd);
> > > > }
> > > > +
> > > > +void os_get_win_version(RTL_OSVERSIONINFOEXW *info)
> > > > +{
> > > > + typedef LONG (WINAPI *rtl_get_version_t)(PRTL_OSVERSIONINFOEXW);
> > > > +
> > > > + /* RtlGetVersion is available starting with Windows 2000 */
> > > > + HMODULE module = GetModuleHandle("ntdll");
> > > > + PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > > + rtl_get_version_t rtl_get_version = (rtl_get_version_t)fun;
> > > > +
> > > > + info->dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW);
> > > > + rtl_get_version(info);
> > > The original function, when it was present in qemu-ga, tested that
> > > getting the function address succeeded.
> > > I think this test should be kept.
> > > See below:
> > > - PVOID fun = GetProcAddress(module, "RtlGetVersion");
> > > - if (fun == NULL) {
> > > - error_setg(errp, QERR_QGA_COMMAND_FAILED,
> > > - "Failed to get address of RtlGetVersion");
> > > - return;
> > > - }
> > >
> >
> > Please see the comment:
> >
> > /* RtlGetVersion is available starting with Windows 2000 */
> >
> > I don't think we need that check.
>
> In include/qemu/osdep.h we have
>
> /* as defined in sdkddkver.h */
> #ifndef _WIN32_WINNT
> #define _WIN32_WINNT 0x0601 /* Windows 7 API (should be in sync with glib) */
> #endif
>
> so do we even need to have the GetProcAddress calls at all ?
>
> Surely we can just '#include <ddk/ntddk.h>' and call
> RtlGetVersion directly at compile time ?
Yes.
https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlgetversion
- RtlGetVersion is available from Windows 2000.
Best regards,
Yan.
>
>
> With regards,
> Daniel
> --
> |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o- https://fstop138.berrange.com :|
> |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
>
© 2016 - 2026 Red Hat, Inc.