* [PATCH] mingw: replace deprecated GetVersion with RtlGetVersion @ 2023-01-19 17:07 Rose via GitGitGadget 2023-01-19 17:36 ` [PATCH v2] " Rose via GitGitGadget 0 siblings, 1 reply; 5+ messages in thread From: Rose via GitGitGadget @ 2023-01-19 17:07 UTC (permalink / raw) To: git; +Cc: Rose, Seija Kijin From: Seija Kijin <doremylover123@gmail.com> The previous way is deprecated and returns the wrong value in Windows 8 and up, returning the manifest Windows data as opposed to the actual Windows data. RtlGetVersion is the correct way to get the Windows version now. Signed-off-by: Seija Kijin <doremylover123@gmail.com> --- mingw: replace deprecated GetVersion with RtlGetVersion GetVersion has its behavior changed in Windows 8 and above anyway, so this is the right way to do it now. The previous way returns the wrong value in Windows 8 and up, returning the manifest Windows data as opposed to the actual Windows data. Signed-off-by: Seija Kijin doremylover123@gmail.com Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1438%2FAtariDreams%2Fmingw-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1438/AtariDreams/mingw-v1 Pull-Request: https://github.com/git/git/pull/1438 compat/mingw.c | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index af397e68a1d..ebd5850002a 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3081,15 +3081,36 @@ int wmain(int argc, const wchar_t **wargv) return exit_status; } +/* + * For RtlGetVersion in uname + */ + +typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); +union winprocaddr { + FARPROC procaddr; + RtlGetVersionPtr procGetVersion; +}; + int uname(struct utsname *buf) { - unsigned v = (unsigned)GetVersion(); + union winprocaddr RtlGetVersionInternal; + OSVERSIONINFOA version; + + RtlGetVersionInternal.procaddr = + GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"); + if (!RtlGetVersionInternal.procaddr) { + die_message_errno( + "Could not get handle to RtlGetVersion in ntdll.dll"); + } + + version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + RtlGetVersionInternal.procGetVersion((PRTL_OSVERSIONINFOW)&version); + memset(buf, 0, sizeof(*buf)); xsnprintf(buf->sysname, sizeof(buf->sysname), "Windows"); - xsnprintf(buf->release, sizeof(buf->release), - "%u.%u", v & 0xff, (v >> 8) & 0xff); - /* assuming NT variants only.. */ - xsnprintf(buf->version, sizeof(buf->version), - "%u", (v >> 16) & 0x7fff); + xsnprintf(buf->release, sizeof(buf->release), "%lu.%lu", + version.dwMajorVersion, version.dwMinorVersion); + xsnprintf(buf->version, sizeof(buf->version), "%lu", + version.dwBuildNumber); return 0; } base-commit: a7caae2729742fc80147bca1c02ae848cb55921a -- gitgitgadget ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2] mingw: replace deprecated GetVersion with RtlGetVersion 2023-01-19 17:07 [PATCH] mingw: replace deprecated GetVersion with RtlGetVersion Rose via GitGitGadget @ 2023-01-19 17:36 ` Rose via GitGitGadget 2023-01-21 19:50 ` [PATCH v3] " Rose via GitGitGadget 0 siblings, 1 reply; 5+ messages in thread From: Rose via GitGitGadget @ 2023-01-19 17:36 UTC (permalink / raw) To: git; +Cc: Rose, Seija Kijin From: Seija Kijin <doremylover123@gmail.com> The previous way is deprecated and returns the wrong value in Windows 8 and up, returning the manifest Windows data as opposed to the actual Windows data. RtlGetVersion is the correct way to get the Windows version now. Signed-off-by: Seija Kijin <doremylover123@gmail.com> --- mingw: replace deprecated GetVersion with RtlGetVersion GetVersion has its behavior changed in Windows 8 and above anyway, so this is the right way to do it now. The previous way returns the wrong value in Windows 8 and up, returning the manifest Windows data as opposed to the actual Windows data. Signed-off-by: Seija Kijin doremylover123@gmail.com Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1438%2FAtariDreams%2Fmingw-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1438/AtariDreams/mingw-v2 Pull-Request: https://github.com/git/git/pull/1438 Range-diff vs v1: 1: 8fe920c653e ! 1: e5457905028 mingw: replace deprecated GetVersion with RtlGetVersion @@ compat/mingw.c: int wmain(int argc, const wchar_t **wargv) } +/* -+ * For RtlGetVersion in uname ++ * for RtlGetVersion in uname + */ + +typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); @@ compat/mingw.c: int wmain(int argc, const wchar_t **wargv) + RtlGetVersionInternal.procaddr = + GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"); + if (!RtlGetVersionInternal.procaddr) { -+ die_message_errno( -+ "Could not get handle to RtlGetVersion in ntdll.dll"); ++ /* if this is reached, something is seriously, seriously wrong ++ */ ++ perror("Could not call RtlGetVersion in ntdll.dll"); ++ abort(); + } + + version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); compat/mingw.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index af397e68a1d..07d81fb8d69 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3081,15 +3081,38 @@ int wmain(int argc, const wchar_t **wargv) return exit_status; } +/* + * for RtlGetVersion in uname + */ + +typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); +union winprocaddr { + FARPROC procaddr; + RtlGetVersionPtr procGetVersion; +}; + int uname(struct utsname *buf) { - unsigned v = (unsigned)GetVersion(); + union winprocaddr RtlGetVersionInternal; + OSVERSIONINFOA version; + + RtlGetVersionInternal.procaddr = + GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"); + if (!RtlGetVersionInternal.procaddr) { + /* if this is reached, something is seriously, seriously wrong + */ + perror("Could not call RtlGetVersion in ntdll.dll"); + abort(); + } + + version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + RtlGetVersionInternal.procGetVersion((PRTL_OSVERSIONINFOW)&version); + memset(buf, 0, sizeof(*buf)); xsnprintf(buf->sysname, sizeof(buf->sysname), "Windows"); - xsnprintf(buf->release, sizeof(buf->release), - "%u.%u", v & 0xff, (v >> 8) & 0xff); - /* assuming NT variants only.. */ - xsnprintf(buf->version, sizeof(buf->version), - "%u", (v >> 16) & 0x7fff); + xsnprintf(buf->release, sizeof(buf->release), "%lu.%lu", + version.dwMajorVersion, version.dwMinorVersion); + xsnprintf(buf->version, sizeof(buf->version), "%lu", + version.dwBuildNumber); return 0; } base-commit: a7caae2729742fc80147bca1c02ae848cb55921a -- gitgitgadget ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3] mingw: replace deprecated GetVersion with RtlGetVersion 2023-01-19 17:36 ` [PATCH v2] " Rose via GitGitGadget @ 2023-01-21 19:50 ` Rose via GitGitGadget 2023-01-21 20:04 ` [PATCH v4] mingw: prefer RtlGetVersion over GetVersion Rose via GitGitGadget 0 siblings, 1 reply; 5+ messages in thread From: Rose via GitGitGadget @ 2023-01-21 19:50 UTC (permalink / raw) To: git; +Cc: Rose, Seija Kijin From: Seija Kijin <doremylover123@gmail.com> The previous way is deprecated and returns the wrong value in Windows 8 and up, returning the manifest Windows data as opposed to the actual Windows data. RtlGetVersion is the correct way to get the Windows version now. Note: ntdll does not need to be manually loaded into the runtime, as this is the one special library that is automatically loaded upon launch. Signed-off-by: Seija Kijin <doremylover123@gmail.com> --- mingw: replace deprecated GetVersion with RtlGetVersion GetVersion has its behavior changed in Windows 8 and above anyway, so this is the right way to do it now. The previous way returns the wrong value in Windows 8 and up, returning the manifest Windows data as opposed to the actual Windows data. Signed-off-by: Seija Kijin doremylover123@gmail.com Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1438%2FAtariDreams%2Fmingw-v3 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1438/AtariDreams/mingw-v3 Pull-Request: https://github.com/git/git/pull/1438 Range-diff vs v2: 1: e5457905028 ! 1: 31f778a6b34 mingw: replace deprecated GetVersion with RtlGetVersion @@ Commit message returning the manifest Windows data as opposed to the actual Windows data. - RtlGetVersion is the correct way to get the Windows version now. + RtlGetVersion is the correct way + to get the Windows version now. + + Note: ntdll does not need to be + manually loaded into the runtime, + as this is the one special library + that is automatically loaded upon launch. Signed-off-by: Seija Kijin <doremylover123@gmail.com> @@ compat/mingw.c: int wmain(int argc, const wchar_t **wargv) { - unsigned v = (unsigned)GetVersion(); + union winprocaddr RtlGetVersionInternal; -+ OSVERSIONINFOA version; ++ OSVERSIONINFOW version; ++ ++ memset(&version, 0, sizeof(version)); ++ version.dwOSVersionInfoSize = sizeof(version); + ++ /* RtlGetVersion always gets the true Windows version, even when running ++ * under Windows's compatibility mode*/ + RtlGetVersionInternal.procaddr = + GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"); -+ if (!RtlGetVersionInternal.procaddr) { -+ /* if this is reached, something is seriously, seriously wrong -+ */ -+ perror("Could not call RtlGetVersion in ntdll.dll"); -+ abort(); -+ } + -+ version.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); -+ RtlGetVersionInternal.procGetVersion((PRTL_OSVERSIONINFOW)&version); ++ if (RtlGetVersionInternal.procaddr) { ++ RtlGetVersionInternal.procGetVersion((PRTL_OSVERSIONINFOW)&version); ++ } else { ++ /* Should not happen, but just in case, fallback to deprecated ++ * GetVersionExW */ ++ GetVersionExW(&version); ++ } + memset(buf, 0, sizeof(*buf)); xsnprintf(buf->sysname, sizeof(buf->sysname), "Windows"); compat/mingw.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index af397e68a1d..b1d75c93cfe 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3081,15 +3081,42 @@ int wmain(int argc, const wchar_t **wargv) return exit_status; } +/* + * for RtlGetVersion in uname + */ + +typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); +union winprocaddr { + FARPROC procaddr; + RtlGetVersionPtr procGetVersion; +}; + int uname(struct utsname *buf) { - unsigned v = (unsigned)GetVersion(); + union winprocaddr RtlGetVersionInternal; + OSVERSIONINFOW version; + + memset(&version, 0, sizeof(version)); + version.dwOSVersionInfoSize = sizeof(version); + + /* RtlGetVersion always gets the true Windows version, even when running + * under Windows's compatibility mode*/ + RtlGetVersionInternal.procaddr = + GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"); + + if (RtlGetVersionInternal.procaddr) { + RtlGetVersionInternal.procGetVersion((PRTL_OSVERSIONINFOW)&version); + } else { + /* Should not happen, but just in case, fallback to deprecated + * GetVersionExW */ + GetVersionExW(&version); + } + memset(buf, 0, sizeof(*buf)); xsnprintf(buf->sysname, sizeof(buf->sysname), "Windows"); - xsnprintf(buf->release, sizeof(buf->release), - "%u.%u", v & 0xff, (v >> 8) & 0xff); - /* assuming NT variants only.. */ - xsnprintf(buf->version, sizeof(buf->version), - "%u", (v >> 16) & 0x7fff); + xsnprintf(buf->release, sizeof(buf->release), "%lu.%lu", + version.dwMajorVersion, version.dwMinorVersion); + xsnprintf(buf->version, sizeof(buf->version), "%lu", + version.dwBuildNumber); return 0; } base-commit: 904d404274fef6695c78a6b055edd184b72e2f9b -- gitgitgadget ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4] mingw: prefer RtlGetVersion over GetVersion 2023-01-21 19:50 ` [PATCH v3] " Rose via GitGitGadget @ 2023-01-21 20:04 ` Rose via GitGitGadget 2023-03-27 9:25 ` Johannes Schindelin 0 siblings, 1 reply; 5+ messages in thread From: Rose via GitGitGadget @ 2023-01-21 20:04 UTC (permalink / raw) To: git; +Cc: Rose, Seija Kijin From: Seija Kijin <doremylover123@gmail.com> The previous way is deprecated and returns the wrong value in Windows 8 and up, returning the manifest Windows data as opposed to the actual Windows data. RtlGetVersion is the correct way to get the Windows version now. Note: ntdll does not need to be manually loaded into the runtime, as this is the one special library that is automatically loaded upon launch. Signed-off-by: Seija Kijin <doremylover123@gmail.com> --- mingw: prefer RtlGetVersion over GetVersion GetVersion has its behavior changed in Windows 8 and above anyway, so this is the right way to do it now. The previous way returns the wrong value in Windows 8 and up, returning the manifest Windows data as opposed to the actual Windows data. Signed-off-by: Seija Kijin doremylover123@gmail.com Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1438%2FAtariDreams%2Fmingw-v4 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1438/AtariDreams/mingw-v4 Pull-Request: https://github.com/git/git/pull/1438 Range-diff vs v3: 1: 31f778a6b34 ! 1: 8293e868970 mingw: replace deprecated GetVersion with RtlGetVersion @@ Metadata Author: Seija Kijin <doremylover123@gmail.com> ## Commit message ## - mingw: replace deprecated GetVersion with RtlGetVersion + mingw: prefer RtlGetVersion over GetVersion The previous way is deprecated and returns the wrong value in Windows 8 and up, compat/mingw.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index af397e68a1d..b1d75c93cfe 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3081,15 +3081,42 @@ int wmain(int argc, const wchar_t **wargv) return exit_status; } +/* + * for RtlGetVersion in uname + */ + +typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); +union winprocaddr { + FARPROC procaddr; + RtlGetVersionPtr procGetVersion; +}; + int uname(struct utsname *buf) { - unsigned v = (unsigned)GetVersion(); + union winprocaddr RtlGetVersionInternal; + OSVERSIONINFOW version; + + memset(&version, 0, sizeof(version)); + version.dwOSVersionInfoSize = sizeof(version); + + /* RtlGetVersion always gets the true Windows version, even when running + * under Windows's compatibility mode*/ + RtlGetVersionInternal.procaddr = + GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"); + + if (RtlGetVersionInternal.procaddr) { + RtlGetVersionInternal.procGetVersion((PRTL_OSVERSIONINFOW)&version); + } else { + /* Should not happen, but just in case, fallback to deprecated + * GetVersionExW */ + GetVersionExW(&version); + } + memset(buf, 0, sizeof(*buf)); xsnprintf(buf->sysname, sizeof(buf->sysname), "Windows"); - xsnprintf(buf->release, sizeof(buf->release), - "%u.%u", v & 0xff, (v >> 8) & 0xff); - /* assuming NT variants only.. */ - xsnprintf(buf->version, sizeof(buf->version), - "%u", (v >> 16) & 0x7fff); + xsnprintf(buf->release, sizeof(buf->release), "%lu.%lu", + version.dwMajorVersion, version.dwMinorVersion); + xsnprintf(buf->version, sizeof(buf->version), "%lu", + version.dwBuildNumber); return 0; } base-commit: 904d404274fef6695c78a6b055edd184b72e2f9b -- gitgitgadget ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v4] mingw: prefer RtlGetVersion over GetVersion 2023-01-21 20:04 ` [PATCH v4] mingw: prefer RtlGetVersion over GetVersion Rose via GitGitGadget @ 2023-03-27 9:25 ` Johannes Schindelin 0 siblings, 0 replies; 5+ messages in thread From: Johannes Schindelin @ 2023-03-27 9:25 UTC (permalink / raw) To: Rose via GitGitGadget; +Cc: git, Rose, Seija Kijin Hi, On Sat, 21 Jan 2023, Rose via GitGitGadget wrote: > From: Seija Kijin <doremylover123@gmail.com> > > The previous way is deprecated and returns Let's always provide references for such claims (which would otherwise risk suspicion for being taken out of thin air). https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversion has this to say: *GetVersion* may be altered or unavailable for releases after Windows 8.1. The suggestion is to switch to using version helpers, but those version helpers do not get you a version number, they instead help you determine which major version you're on, which is not what we need. Please note that the documentation in no way or form suggests to switch to using `RtlGetVersion()`. > the wrong value in Windows 8 and up, > returning the manifest Windows data > as opposed to the actual Windows data. This is correct only if you ignore the reality that `compat/win32/git.manifest` contains the values required to make it work. > RtlGetVersion is the correct way > to get the Windows version now. Here, we would need a reference to support that claim. Seeing as I failed to find any, I suspect that the claim can safely be considered to be refuted and therefore the patch must be taken into doubt. Ciao, Johannes > > Note: ntdll does not need to be > manually loaded into the runtime, > as this is the one special library > that is automatically loaded upon launch. > > Signed-off-by: Seija Kijin <doremylover123@gmail.com> > --- > mingw: prefer RtlGetVersion over GetVersion > > GetVersion has its behavior changed in Windows 8 and above anyway, so > this is the right way to do it now. > > The previous way returns the wrong value in Windows 8 and up, returning > the manifest Windows data as opposed to the actual Windows data. > > Signed-off-by: Seija Kijin doremylover123@gmail.com > > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1438%2FAtariDreams%2Fmingw-v4 > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1438/AtariDreams/mingw-v4 > Pull-Request: https://github.com/git/git/pull/1438 > > Range-diff vs v3: > > 1: 31f778a6b34 ! 1: 8293e868970 mingw: replace deprecated GetVersion with RtlGetVersion > @@ Metadata > Author: Seija Kijin <doremylover123@gmail.com> > > ## Commit message ## > - mingw: replace deprecated GetVersion with RtlGetVersion > + mingw: prefer RtlGetVersion over GetVersion > > The previous way is deprecated and returns > the wrong value in Windows 8 and up, > > > compat/mingw.c | 39 +++++++++++++++++++++++++++++++++------ > 1 file changed, 33 insertions(+), 6 deletions(-) > > diff --git a/compat/mingw.c b/compat/mingw.c > index af397e68a1d..b1d75c93cfe 100644 > --- a/compat/mingw.c > +++ b/compat/mingw.c > @@ -3081,15 +3081,42 @@ int wmain(int argc, const wchar_t **wargv) > return exit_status; > } > > +/* > + * for RtlGetVersion in uname > + */ > + > +typedef NTSTATUS(WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); > +union winprocaddr { > + FARPROC procaddr; > + RtlGetVersionPtr procGetVersion; > +}; > + > int uname(struct utsname *buf) > { > - unsigned v = (unsigned)GetVersion(); > + union winprocaddr RtlGetVersionInternal; > + OSVERSIONINFOW version; > + > + memset(&version, 0, sizeof(version)); > + version.dwOSVersionInfoSize = sizeof(version); > + > + /* RtlGetVersion always gets the true Windows version, even when running > + * under Windows's compatibility mode*/ > + RtlGetVersionInternal.procaddr = > + GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion"); > + > + if (RtlGetVersionInternal.procaddr) { > + RtlGetVersionInternal.procGetVersion((PRTL_OSVERSIONINFOW)&version); > + } else { > + /* Should not happen, but just in case, fallback to deprecated > + * GetVersionExW */ > + GetVersionExW(&version); > + } > + > memset(buf, 0, sizeof(*buf)); > xsnprintf(buf->sysname, sizeof(buf->sysname), "Windows"); > - xsnprintf(buf->release, sizeof(buf->release), > - "%u.%u", v & 0xff, (v >> 8) & 0xff); > - /* assuming NT variants only.. */ > - xsnprintf(buf->version, sizeof(buf->version), > - "%u", (v >> 16) & 0x7fff); > + xsnprintf(buf->release, sizeof(buf->release), "%lu.%lu", > + version.dwMajorVersion, version.dwMinorVersion); > + xsnprintf(buf->version, sizeof(buf->version), "%lu", > + version.dwBuildNumber); > return 0; > } > > base-commit: 904d404274fef6695c78a6b055edd184b72e2f9b > -- > gitgitgadget > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-03-27 9:25 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-01-19 17:07 [PATCH] mingw: replace deprecated GetVersion with RtlGetVersion Rose via GitGitGadget 2023-01-19 17:36 ` [PATCH v2] " Rose via GitGitGadget 2023-01-21 19:50 ` [PATCH v3] " Rose via GitGitGadget 2023-01-21 20:04 ` [PATCH v4] mingw: prefer RtlGetVersion over GetVersion Rose via GitGitGadget 2023-03-27 9:25 ` Johannes Schindelin
Code repositories for project(s) associated with this public inbox https://80x24.org/mirrors/git.git 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 read-only IMAP folder(s) and NNTP newsgroup(s).