Skip to content

Commit f6ff9e7

Browse files
hsbtclaude
andcommitted
Etc.uname: Report the actual Windows version
GetVersionEx reports 6.2.9200 on Windows 8.1 and later unless the manifest of the executable declares them as supported, and ruby.manifest does not. RtlGetVersion is not affected by the manifest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 41349bb commit f6ff9e7

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎ext/etc/etc.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,8 @@ static VALUE
800800
etc_uname(VALUE obj)
801801
{
802802
#ifdef _WIN32
803+
typedef long (WINAPI version_func)(OSVERSIONINFOW *);
804+
version_func *pRtlGetVersion;
803805
OSVERSIONINFOW v;
804806
SYSTEM_INFO s;
805807
const char *sysname, *mach;
@@ -808,9 +810,11 @@ etc_uname(VALUE obj)
808810
DWORD len = 0;
809811
WCHAR *buf;
810812

813+
/* GetVersionEx reports 6.2 unless the manifest declares Windows 8.1 or later */
814+
pRtlGetVersion = (version_func *)GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion");
811815
v.dwOSVersionInfoSize = sizeof(v);
812-
if (!GetVersionExW(&v))
813-
rb_sys_fail("GetVersionEx");
816+
if (!pRtlGetVersion || pRtlGetVersion(&v))
817+
rb_notimplement();
814818

815819
result = rb_hash_new();
816820
sysname = "Windows_NT";

‎test/etc/test_etc.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ def test_uname
131131
}
132132
end
133133

134+
def test_uname_release_on_windows
135+
release = IO.popen(%w[cmd.exe /c ver], "rb", &:read)[/\d+\.\d+\.\d+/]
136+
assert_equal(release, Etc.uname[:release])
137+
end if /mswin|mingw/ =~ RUBY_PLATFORM
138+
134139
def test_sysconf
135140
begin
136141
Etc.sysconf

0 commit comments

Comments
 (0)