qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Bin Meng <bmeng.cn@gmail.com>
Cc: Yan Vugenfirer <yvugenfi@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Bin Meng <bin.meng@windriver.com>,
	Xuzhou Cheng <xuzhou.cheng@windriver.com>,
	Stefan Weil <sw@weilnetz.de>
Subject: Re: [PATCH 2/5] util/oslib-win32: Add a helper to get the Windows version
Date: Wed, 27 Jul 2022 13:53:27 +0100	[thread overview]
Message-ID: <YuE1Rx1tOOwuS4SV@redhat.com> (raw)
In-Reply-To: <CAEUhbmVT6bwMObhW59Oxf6nfPazDziXYbuqxC=pLBEbd26r_NQ@mail.gmail.com>

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 :|



  reply	other threads:[~2022-07-27 12:55 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-27  7:35 [PATCH 0/5] Enable unix socket support on Windows Bin Meng
2022-07-27  7:35 ` [PATCH 1/5] util/qemu-sockets: Replace the call to close a socket with closesocket() Bin Meng
2022-07-27  7:35 ` [PATCH 2/5] util/oslib-win32: Add a helper to get the Windows version Bin Meng
2022-07-27  8:50   ` Yan Vugenfirer
2022-07-27  9:38     ` Bin Meng
2022-07-27  9:59       ` Daniel P. Berrangé
2022-07-27 10:57         ` Yan Vugenfirer
2022-07-27 11:55         ` Bin Meng
2022-07-27 12:53           ` Daniel P. Berrangé [this message]
2022-07-27 13:15             ` Bin Meng
2022-07-27 13:18           ` Konstantin Kostiuk
2022-07-27 13:21             ` Bin Meng
2022-07-27  7:35 ` [PATCH 3/5] qga/commands-win32: Use os_get_win_version() Bin Meng
2022-07-27  8:59   ` Konstantin Kostiuk
2022-07-27  7:35 ` [PATCH 4/5] util/qemu-sockets: Enable unix socket support on Windows Bin Meng
2022-07-27  8:50   ` Yan Vugenfirer
2022-07-27  9:58     ` Bin Meng
2022-07-27  8:53   ` Konstantin Kostiuk
2022-07-27 10:01     ` Bin Meng
2022-07-28 13:11       ` Marc-André Lureau
2022-07-28 13:41         ` Bin Meng
2022-07-27  7:35 ` [PATCH 5/5] chardev/char-socket: Update AF_UNIX for Windows Bin Meng
2022-07-27  9:06 ` [PATCH 0/5] Enable unix socket support on Windows Daniel P. Berrangé
2022-07-27 10:15   ` Bin Meng
2022-07-27 10:24     ` Daniel P. Berrangé
2022-07-27 11:37       ` Bin Meng
2022-07-27 11:45         ` Stefan Weil via
2022-07-27 12:17           ` Bin Meng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YuE1Rx1tOOwuS4SV@redhat.com \
    --to=berrange@redhat.com \
    --cc=bin.meng@windriver.com \
    --cc=bmeng.cn@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    --cc=xuzhou.cheng@windriver.com \
    --cc=yvugenfi@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).