Bug 1193033 - Teach mozinfo to get the real os version number for Windows >= 8.1, r=ted

For contemporary versions of Windows the sys.getwindowsversion call is unreliable
because it depends on a API which had its return value frozen. If we detect this
case use an alternate API instead
This commit is contained in:
James Graham 2015-08-11 16:43:20 +01:00
parent f2b93bae43
commit 43f789c16c

View File

@ -28,6 +28,29 @@ class unknown(object):
return 'UNKNOWN'
unknown = unknown() # singleton
def get_windows_version():
import ctypes
class OSVERSIONINFOEXW(ctypes.Structure):
_fields_ = [('dwOSVersionInfoSize', ctypes.c_ulong),
('dwMajorVersion', ctypes.c_ulong),
('dwMinorVersion', ctypes.c_ulong),
('dwBuildNumber', ctypes.c_ulong),
('dwPlatformId', ctypes.c_ulong),
('szCSDVersion', ctypes.c_wchar*128),
('wServicePackMajor', ctypes.c_ushort),
('wServicePackMinor', ctypes.c_ushort),
('wSuiteMask', ctypes.c_ushort),
('wProductType', ctypes.c_byte),
('wReserved', ctypes.c_byte)]
os_version = OSVERSIONINFOEXW()
os_version.dwOSVersionInfoSize = ctypes.sizeof(os_version)
retcode = ctypes.windll.Ntdll.RtlGetVersion(ctypes.byref(os_version))
if retcode != 0:
raise OSError
return os_version.dwMajorVersion, os_version.dwMinorVersion, os_version.dwBuildNumber
# get system information
info = {'os': unknown,
'processor': unknown,
@ -50,6 +73,14 @@ if system in ["Microsoft", "Windows"]:
system = os.environ.get("OS", system).replace('_', ' ')
(major, minor, _, _, service_pack) = os.sys.getwindowsversion()
info['service_pack'] = service_pack
if major >= 6 and minor >= 2:
# On windows >= 8.1 the system call that getwindowsversion uses has
# been frozen to always return the same values. In this case we call
# the RtlGetVersion API directly, which still provides meaningful
# values, at least for now.
major, minor, build_number = get_windows_version()
version = "%d.%d.%d" % (major, minor, build_number)
os_version = "%d.%d" % (major, minor)
elif system == "Linux":
if hasattr(platform, "linux_distribution"):