From: "Rose via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Rose <83477269+AtariDreams@users.noreply.github.com>,
Seija Kijin <doremylover123@gmail.com>
Subject: [PATCH v2] mingw: replace deprecated GetVersion with RtlGetVersion
Date: Thu, 19 Jan 2023 17:36:13 +0000 [thread overview]
Message-ID: <pull.1438.v2.git.git.1674149773693.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1438.git.git.1674148045970.gitgitgadget@gmail.com>
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
next prev parent reply other threads:[~2023-01-19 17:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-19 17:07 [PATCH] mingw: replace deprecated GetVersion with RtlGetVersion Rose via GitGitGadget
2023-01-19 17:36 ` Rose via GitGitGadget [this message]
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
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1438.v2.git.git.1674149773693.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=83477269+AtariDreams@users.noreply.github.com \
--cc=doremylover123@gmail.com \
--cc=git@vger.kernel.org \
/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.
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).